Timeline for Trying to calculate confidence intervals for a Monte-Carlo estimate of Pi. What am I doing wrong?
Current License: CC BY-SA 4.0
12 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
May 21, 2021 at 19:56 | history | edited | kjetil b halvorsen♦ | CC BY-SA 4.0 |
added 9 characters in body
|
May 21, 2021 at 7:01 | comment | added | saeranv |
Thanks @ThomasLumley, I think I understand it now, I didn't recognize that the mean of in_circle is equal to sum(in_circle)/N because it's a binary vector. Thus the in_circle values are a sample from the uniform distribution, with a true pop. mean of $\pi/4 = 0.785$. Since the estimate_se represents the standard deviation of the mean of the sample, we don't need to divide by N (it's already normalized because it's a binary variable). The sample sd here approximates the population sd (estimate_sd ), which is constant, so the only array of values is the sqrt(1:n) .
|
|
May 20, 2021 at 20:05 | comment | added | Thomas Lumley |
estimate_sd is the population sd of the individual throw estimates of $\pi$, which are either 4 or 0. estimate_se , which divides by sqrt(1:n) is the standard error of $\hat\pi$ after $n$ throws.
|
|
May 20, 2021 at 20:02 | comment | added | saeranv |
I am still puzzled by how the variance of in_circle is used to derive the population SD of $\pi$. If in_circle sample variance is $\sigma_{sample}^2 = (\pi/4)×(1−\pi/4)$; population variance is $\sigma_{pop}^2 = \sqrt{\sigma_{sample}^2/n}$. Your formula then scales this by 4 to represent population SD of $\pi$ 4*sqrt((pi/4)*(1-pi/4)/n) , but we calculate $\pi$ by calculating proportion of in_circle points to $n$, shouldn't we be scaling $\sigma_{pop}^2$ by $4/n$ not $4$? Or to put it another way: how does the variance of in_circle map to the variance of $\pi$?
|
|
May 20, 2021 at 20:01 | comment | added | saeranv |
@ThomasLumley, okay I see my mistake, the sample SD estimate: estimate_sd <-4*sd(in_circle) is a scalar value, I was thinking it was producing a vector of cumulative SDs for every ith-step of in_circle 's N length (like cumsum). I see it's not correlated.
|
|
May 20, 2021 at 10:54 | comment | added | EngrStudent | Beautiful work. For a moment I was wondering if it was whuber or gung writing the answer. You might want to show what log10 scaling the x-axis does to the shape of the convergence in the 2nd to the last plot. | |
May 20, 2021 at 7:42 | comment | added | Thomas Lumley |
in_circle isn't correlated, it's just independent results of each throw. The reason not to scale stddevs by $1/\sqrt{n}$ is that it's already the standard deviation of the independent $\hat\pi$ estimates from different experiments, so it already gets smaller as they get closer together.
|
|
May 20, 2021 at 7:31 | comment | added | saeranv |
Second question: You say that "Averages (and variances) of the binary in_circle variable along one run estimate the same thing as averages and variances across experiments." but wouldn't the correlation of in_circle at throw 800 and 900 also share the same first 800 points and thus have a correlation of 0.9? Why isn't this more correlated like the cumsum?
|
|
May 20, 2021 at 7:27 | comment | added | saeranv |
I have some follow-up questions: In examples 2 and 3 where you're plotting the CIs for multiple experiments with 1000 and then 100,000 throws, why aren't you dividing the stddevs with the square root of the number of experiments at that point? I see pi-1.96*stddevs , but shouldn't it be pi-1.96*stddevs/range(1,experiment_number) ?
|
|
May 20, 2021 at 7:18 | comment | added | saeranv | Great answer! This has clarified a lot of theoretical and implementation confusion that I haven't been able to answer after days of looking online. I'm going to have to read it a couple more times to absorb the details, but this line alone "the estimates at 800 and 900 throws share the first 800 throws and so have a correlation of 800/900, or nearly 0.9" clarifies a lot. | |
May 20, 2021 at 7:11 | vote | accept | saeranv | ||
May 20, 2021 at 6:46 | history | answered | Thomas Lumley | CC BY-SA 4.0 |