Precision of a simulated estimate

36 Views Asked by At

I've estimate the probability of the event

"the circle with center in $(X,Y)$ where $X$ and $Y$ have a distribution $U[0,1]$, and a radius $R$ which has a distribution $U[0,1]$ intersects the perimeter of the unit square in which it is drawn"

simulating it thorugh this R program :

simulation <- function() {

  n = 10^6
  x = runif(n, 0, 1)
  y = runif(n, 0, 1)
  r = runif(n, 0, 1)

  cond1 = (x - r) > 0 
  cond2 = (x + r) < 1
  cond3 = (y + r) < 1
  cond4 = (y - r) > 0

  result <- sum(cond1 & cond2 & cond3 & cond4)

  return(result)
}

In which for a million times I generate x, y, r and I verify how many times there is no the intersection between the circle and the square. The result is 166436, so I've estimated the probability of the event as 1 - 0.166436 = 0.833564.

How can I calculate the precision of the simulated estimate based on the number of simulations?

1

There are 1 best solutions below

0
On BEST ANSWER

You've estimated a proportion of $\hat{p}=0.833564$ from $n=1000000$ trials. You can for example construct a $95\%$ confidence interval: $$[\hat{p}-1.96\sqrt{\frac{\hat{p}(1-\hat{p})}{n}},\hat{p}+1.96\sqrt{\frac{\hat{p}(1-\hat{p})}{n}}]=[0.8329,0.8343]$$ So with $95\%$ confidence you can say that you are off by less than $0.00073$ i.e. inside the above interval.

BTW the true answer is $\frac{5}{6}=0.8333...$ as you can see by computing a simple integral and therefore in reality you are off by just $0.00023$.