rmcelreath / stat_rethinking_2022

Statistical Rethinking course winter 2022
4.12k stars 445 forks source link

Question about multiplication in Bayesian Inference #19

Closed JerryCBH closed 2 years ago

JerryCBH commented 2 years ago

Hi Richard @rmcelreath ,

Thanks for this great course! I have been reading chapter two of the book and I can't see why for the marble example, successive multiplications will produce the same results as a single number of ways calculation. In the example we are calculating the number of ways to draw with replacement a blue marble followed by a white and then another blue marble (BWB), given there are four marbles in the bag, I can't seem to get the same result if I do calculation in three stages like:

Posterior = (Number of ways / Total number of ways) * Prior

Assuming Prior is 1 at the beginning.

p Blue White Blue Product
0.25 0.17 (1) 0.50 (3) 0.17 (1) 0.0145
0.50 0.33 (2) 0.33 (2) 0.33 (2) 0.0360
0.75 0.50 (3) 0.17 (1) 0.50 (3) 0.0425

Calculate in one go:

p BWB
0.25 0.15 (3)
0.50 0.40 (8)
0.75 0.45 (9)

We can see the for example, P = 0.75, doing successive draw / multiply gives a posterior probability of 0.0425, but if we do this in one go in the second table, we get 9 out of 20 ways = 0.45 which doesn't match with 0.0425. Assuming the normalization (denominator) is always 1 for every stage?

For the proportion of water in globe example, I also tried to see if the probabilities are calculated individually, the product will be the same as a single calculation. If we had the sequence WWWLL:

E Likelihood Posterior How Posterior is calculated
W p 2p (p 1)/ integral from 0 to 1 {p1}
WW p 3p^2 (p 2p)/ integral from 0 to 1 {p 2p}
WWW p 4p^3 (p 3p^2)/ integral from 0 to 1 {p 3p^2}
WWWL 1-p 20p^3 - 20p^4 ((1-p) 4p^3)/ integral from 0 to 1 {(1-p) 4p^3}
WWWLL 1-p 60p^3 - 120p^4 + 60p^5 ((1-p) (20p^3−20p^4))/ integral from 0 to 1 {(1-p) (20p^3−20p^4)}

And this is different if I use the binomial distribution formula directly, the result is:

$5!/(2!3!) p^3 (1-p)^2 = 10p^3 - 20p^4 + 10p^5

Same question in stack exchange: https://math.stackexchange.com/questions/4503794/bayesian-inference-multiplication