Perform Monte Carlo integration using R statistical programming to estimate the value of .Generate N pairs of
Question:
Perform Monte Carlo integration using R statistical programming to estimate the value of π.Generate N pairs of uniform random numbers (x,y), where x ∼ U(0,1)and y ∼ U(0,1) and each (x,y) pair represents a point in the unit square. To obtain an estimate of π count the fraction of points that fall inside the unit quarter circle and multiply by 4. Note that the fraction of points that fall inside the quarter circle should tend to the ratio between the area of the unit quarter circle (i.e 1/4π.) as compared to area of the unit square (e.i.,1)
We proceed step-by-step:
a) Create a function inside circle that takes two inputs between 0 and 1 and returns 1 if these points fall within the unit circle.
b) Create a function estimate that takes a single input N, generates N pairs of uniform random numbers and uses inside circle to produce an estimate of π as described above. In addition to the estimate of π., estimate should also return the standard error of this estimate, and a 95% confidence interval for the estimate.
c) Use estimate to estimate π for N = 1000 to 10000 in increments of 500 and record the estimate, its standard error and the upper and lower bounds of the 95 % CI. How large must N be in order to ensure that your estimate of π is within 0.1 of the true value?
d) Using the value of N you determined in part c), run estimate 500 times and collect 500 different estimates of π. Produce a histogram of the estimates and note the shape of this distribution. Calculate the standard deviation of the estimates - does it match the standard error you obtained in part c)? What percentage of the estimates lies within the 95% CI you obtained in part c)?