So lets say we are trying to calculate value of $\pi$ using MonteCarlo method. By picking random points in a square and measuring their distance from the center and if $k$ points lie inside the circle using the ratio $\frac{k}N$ to calculate the value of $\pi$.
How do I derive the formula for variance of the calculated value of $\pi$?
This is what I have got so far.
Say the probability that the point lies inside the circle is $p$.
Say we have N random points in the square, of which k lie inside the circle.
The probability that k points lie inside the circle is $\binom{N}{k}p^k(1-p)^{N-k}$.
The error in estimate of $\pi$ is $e=||c\pi-\frac{N}k||$.
So the expected value of error $E(e) = \sum_{k=0}^{k=N}\left\|c\pi-\frac{N}k\right\|\binom{N}{k}p^k(1-p)^{N-k}$?
Is the expectation value of error that I have written correct, how do I evaluate it?
For very large $n$, as in a simulation, a reasonable 95% confidence interval for the estimate $\hat p = k/n$ of the proportion of the points inside the circle is of the form
$$\hat p \pm 1.96\sqrt{\frac{\hat p(1-\hat p)}{n}}.$$
So the approximate margin of simulation error is $1.96\sqrt{\frac{\hat p(1-\hat p)}{n}}.$
We have $Var(\hat p) = Var(k/n) = (1/n^2)Var(k) = p(1-p)/n,$ so $SD(\hat p) = \sqrt{\frac{p(1-p)}{n}},$ where $p$ is the unknown theoretical fraction. We use the observed value $\hat p$ to get $\widehat{SD}(\hat p),$ the estimated standard deviation of $\hat p.$
But be careful! You are not specific about 'a square' and 'the circle', but the usual simulation is to use a square of area $4$ with vertices at $(-1,-1)$ and $(1,1)$ and the inscribed circle of radius $1$ and area $\pi.$ Thus the ratio of 'accepted' points in the circle to the total points in the square estimates $\pi/4.$ If you multiply the estimate by $4$ to get an estimate of $\pi,$ then the margin of error is also multiplied by $4.$
Let's try the actual simulation experiment in R statistical software:
The observed simulation error (about 0.001) for estimating $\pi$ is within the 95% simulation margin of error (about 0.003) for the estimate of $\pi$, but not within the 95% margin of simulation error (about 0.0001) for estimating $\pi/4.$
Here is a plot of 10,000 of the million points.