Berkeley CSUA MOTD:Entry 53378
Berkeley CSUA MOTD
2022/06/25 [General] UID:1000 Activity:popular

2009/9/18-29 [Computer/Theory] UID:53378 Activity:nil
9/18    I forgot my math.  Say the probability of a bug happening is the
        unknown fixed value p in [0,1].  I attempt to reproduce the
        bug until it happens once.  Then it happens at my n-th trial, so I
        stop.  Now, what is the expected value of p?  Is it E(p) = 1/n?  Thx.
        \_ Did a quick program to test.  Looks like E(p) = 1/n
           (given assumption n(p) = sum x = 1 to inf of x*(1-p)^(x-1)*p
            where n(p) = expected n for a given p)
        \_ Consider the case n=1 to see why E(p) = 1/n can't possibly be
           right. You need to specify a prior distribution and then apply
           Bayes' theorem. If your prior distribution is the uniform
           distribution on [0,1] (i.e. before running the experiment you think
           all values for p between 0 and 1 are equally likely), then if you
           see your bug for the first time in the nth trial, you'll get a
           posterior distribution of (n)(n+1)(p)(1-p)^(n-1). The expected
           value of this is the root r of the equation (1+nr)(1-r)^n = 1/2.
           For n = 1, E(p)=1/sqrt(2). For n = 2, E(p) = 1/2. For n = 3, it's
           around .3857. This sequence probably has some name, but I don't
           know it. [In practice that might be a stupid prior to use for your
           problem. But you have to have some prior, otherwise the problem is
           not well-specified mathematically.]
           \_ Doy, wow I'm an idiot. I'm wrong, this person is right. -pp
           \_ That is a fine answer above. The part about Bayes Rule and
              having to make some assumptions about priors/distribution
              properties is hard to explain. All I have to add is OP may
              enjoy reading about the NEGATIVE BINOMIAL DISTRIBUTIION.
              (while you are at it, you might read up on POISSON DISTRIBUTION/
              PROCESS ... which can be quite useful in a lot of engineering