Avoid loosing precision with the Binomial Distribution /Bayes?

63 Views Asked by At

So when dealing with the Bayes' Rule and Binomial distributions, the value $p^k(1-p)^{n-k}$ loses precision and becomes 0 when $n$ and $k$ are large(noting that the binomial coefficient can be safely ignored since it cancels out). For example if $n = 500\,,\,k=250\,\,$for $p= 0.05$ , then my TI-83 calculator returns 0.

I found out about a "fix" for this using the following expression that replaces $p^k(1-p)^{n-k}$.

$e^{k\,ln \,p + (n-k)ln(1-p)-max_i(kln(p_i) + (n-k)ln(1-p_i)}$

I think the $p_i$ in the expression is suppose to represent any one of prior probabilities. Can anyone explain why this works ?

1

There are 1 best solutions below

3
On

If you want to do your calculation with natural logarithms, the expression is $p^k(1-p)^{n-k} = \exp( k \log_e(p)+(n-k)\log_e(1-p) )$ which is the first part of your expression.

This should lead you to $0.05^{250}0.95^{250} \approx 1.49 \times 10^{-331}$.