0

I've written a monte carlo program to calculate ln(2). I generate random x in the range 1-2 and random y in the range 0-1. If y<1/x I add 1 to my count. My estimate of ln(2) is count/n (i.e. frac from above). I'm trying to find the error in my estimate so that I can end the program once my estimate is accurate to 2dp. I am not sure how to compute the standard deviation in a meaningful way. Help?

Chris A.
  • 6,817
  • 2
  • 25
  • 43
Goods
  • 225
  • 2
  • 10
  • How would you like to calculate the *error*? – dlask Nov 02 '15 at 21:05
  • 1
    Try to describe more clearly how this program should actually work, from beginning to end. As it is, it is a complete mystery how you are attempting to do any computation. – David K Nov 02 '15 at 21:52
  • FYI, in general, problems like this are better answered at [Cross Validated](http://stats.stackexchange.com/). This is not a programming question. – Chris A. Nov 02 '15 at 22:34
  • @ChrisA. Okay thanks I'll bare that in mind! I've only recently started programming so I'm still learning where's best to get help when I get stuck on different problems. – Goods Nov 02 '15 at 23:27

1 Answers1

1

I believe the answer you want is related to the binomial random variance.

For a binomial variable you would have a number of counts related to the times when it was under the curve, U, and a number of times it was above the curve, A. Let N = U + A be the total number of samples.

A reasonable estimate of your standard deviation of U would be sigma = sqrt(U/N * A/N * N). This is because U is a binomial random variable and your best estimate of p, the probability of it being under the curve on a single trial, is well estimated by U/N. Note also that 1-p is well estimated by A/N.

But the thing you're estimating is U/N so a reasonable estimate of your standard deviation of your estimate of ln(2) is going to be sigma / N.

This will provide you a reasonable stopping criterion (when sigma / N is sufficiently small for your needs.)

Chris A.
  • 6,817
  • 2
  • 25
  • 43