Before you begin: precede your R script with pdf(file=‘myfile.pdf’), and include as the last line dev.off(). This will funnel every plot you make into a single pdf to submit along with your code. While you are working in Rstudio, I recommend commenting out these two lines so that you can see the graphs as you go. When you are done, uncomment them and re-run your whole script to generate the file with the figures. Make sure all of your figures have informative titles (using the option main=‘mytitle’ within most plotting commands e.g. hist() and curve()).
Q1 : Recall the beta density function f (x|α, β) given by
f (x α, β) = Γ(α + β) xα−1(1 x)β−1, Γ(α)Γ(β)
for x ∈ (0, 1) and positive α and β. Let X ∼ beta(2, 5). Find P (X > 1 ) by:
a) Monte Carlo (MC) integration.
b) Simulating 25, 000 beta(2, 5) realizations. Use rejection sampling and uniform proposal density q(x).
c) Using the following command to find the theoretical solution: pbeta(0.5, shape1=2, shape2=5, lower.tail=FALSE). Note: without the lower.tail=FALSE argument, this would return P (X < 1 )
Q2 : Let X and Y be independent standard normal random variables. Use the polar method to simulate 25, 000 pairs (x, y) of independent, standard normal realizations.
a) Use these realizations to estimate P (X > Y )
b) Use these realizations to find the value of k that satisfies P (√X2 + Y 2 < k) = 1
c) Estimate P (−1.96 < X < 1.96) for X ∼ Normal(0, 1) using:
i. your X draws
ii. MC integration
iii. the command pnorm(1.96)-pnorm(-1.96) (this will give you the theoretical answer!)
Q3 : Let X and Y have jointly normal density f (x, y) given by:
f (x, y) = 1
2π√1 − ρ2
• exp −(x2 + y2 − 2ρxy)/(2(1 − ρ2))} .
Write a function that uses Gibbs sampling to produce realizations from this joint density, where ρ = 0.75. Your program should be flexible enough to accommodate a choice of
– Correlation ρ
– Initial values x0.
– Number of desired (xi, yi) realizations.
– Number of iterations to skip (lag) in order to avoid serial correlation (a lag of 1 should be the same as no lag)
– Number of burn-in iterations to skip
Note that the number of desired realizations, together with the burn-in and lag, should determine the number of required iterations. Use this program to complete the following:
a) Generate 500 realizations with x0 = 80, no burn-in and no lag. Plot these realizations and connect the points in order using the following commands:
plot(xvec[1:500],yvec[1:500]) arrows(xvec[1:499],yvec[1:499],xvec[2:500],yvec[2:500])
b) Use ts.plot() to draw time series plots for both x and y. Use these two plots to choose a reasonable burn-in.
c) Use acf() to look at autocorrelation plots for both your x and y draws. Use these two plots to choose a reasonable lag for generating independent realizations of (xi, yi).
d) Using the lag and burn-in from parts b) and c) draw 10,000 independent realizations of X. Plot a histogram of x, and overlay the theoretical standard normal curve to confirm that the marginal density is correct.
Q4 : Use your Gibbs sampling function from above to generate 15,000 independent realizations each for ρ = {−0.9, −0.8, ..., 0.8, 0.9} (note: the function seq may be useful here). For each value of ρ, approximate P (X > 0 and Y > 0), and plot these probabilities as a function of ρ, setting your vertical axis limits to (0,1) using ylim.
CS 340 Milestone One Guidelines and Rubric Overview: For this assignment, you will implement the fundamental operations of create, read, update,
Retail Transaction Programming Project Project Requirements: Develop a program to emulate a purchase transaction at a retail store. This
7COM1028 Secure Systems Programming Referral Coursework: Secure
Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip
CS 340 Final Project Guidelines and Rubric Overview The final project will encompass developing a web service using a software stack and impleme