# Bayes' theorem to know how many of my dates (fruit) are bad!

I bought a container of dates (fruit) (containing $57$ dates in total). I started opening them to see if they're good or bad (do have warms inside or not), and after opening $7$ of them I found that the first $5$ were bad whereas the $2$ last were good.

I usually buy these dates' containers and I would estimate that one third of it are bad dates$^{(*)}$.

How can I estimate (or rather improve my estimation, I guess using Bayes' theorem) the number of bad dates I have in the container considering the evidence I have (i.e. $5$ first opened dates are good and last $2$ bad).

$^{(*)}$: I still buy them though because they're cheap ;-)

Spoiler alert: I can check the real numbers after I open all dates :-)

It depends on how strongly you believe in your prior knowledge. Say $k$ represents the strength of your belief. The higher $k$ is, the more you believe in your prior. Using beta distribution as the conjugate prior, $B(\alpha=k/3, \beta=2k/3)$ and modeling with binomial, the posterior distribution is proportional to $p^{5+\alpha-1}(1-p)^{2+\beta-1}$.

Your new estimate for proportion of bad dates becomes $\frac{5+\alpha}{7+\alpha+\beta}=\frac{5+k/3}{7+k}$. In other words, it's like you're adding imaginary dates ($k/3$ good ones and $2k/3$ bad ones) to your samples and use the frequentist method.

• what's the range of variation of $k$? Commented Jul 23, 2017 at 4:45
• Any positive number Commented Jul 23, 2017 at 4:48
• Is there a reason for using the beta distribution? the binomial I guess is because we have two choices (either bad or good)! Commented Jul 23, 2017 at 4:52
• You're right about binomial for modeling the number of "successes" (bad dates). There's no real reason other than ease of computation. Beta distribution is a conjugate prior for binomial, meaning the posterior distribution will also be a beta distribution. In your case, the posterior is $B(5+\alpha-1, 2+\beta-1)$. Commented Jul 23, 2017 at 4:58
• The answer seems logical, even though I can't seem to attach a meaning to the beta parameters, like why would you choose $\alpha = k/3$? Commented Jul 23, 2017 at 5:38

This isn't really my territory, but I actually don't think you'd need to / can apply Bayes' Theorem here. Rather, it's more of a statistics problem, like a 1-sample proportion t-test, where the observed value is $5/7$, or $71.4\%$, the degrees of freedom is $(n-1) = 6$, and the null hypothesis of $33\%$. Working this out, we get a p-value of around $0.015$, which means that around $1.5\%$ of the time, you'd expect to get at more than or equal to $5/7$ bad dates! Doesn't totally answer your question of the expected value, but know that if you're testing to see if you had a normal container, statistically speaking you probably don't!

• why can't I apply Bayes' theorem? Commented Jul 23, 2017 at 4:43