What apples do worms prefer? I'm confused with some practical statistical problem, for which I have limited data and don't understand how to start with the problem. If anybody can point how such problems are (traditionally) solved in statistics, this could help me to understand this better.
Imagine the following situation: we have some sample of objects, let call them "apples". Let the sample contain 100 green apples and 5 red apples. We cannot take more apples from anywhere, the sample is strictly limited. Some of them contain worms, some not. I need to check what of the following hypothesis is more credible:


*

*All = "Worms eat all apples"

*PreferGreen = "Worms prefer green apples"

*PreferRed = "Worms prefer red apples"

*None = "Worms don't eat apples"


Based on the law of total probability, we can write probabilities of these events:


*

*$P(All) = P(worm | green) \cdot P(green) + P(worm | red) \cdot P(red)$

*$P(PreferGreen) = P(worm | green) \cdot P(green) + P(no\; worm | red) \cdot P(red)$

*$P(PreferRed) = P(no\; worm | green) \cdot P(green) + P(worm | red) \cdot P(red)$

*$P(None) = P(no\; worm | green) \cdot P(green) + P(no\; worm | red) \cdot P(red)$
where $P(green)$ denotes the frequency of green apples among all apples, $P(red)$ denotes the frequency of red apples. In our setting they are $\frac{100}{105}$ and $\frac{5}{105}$, correspondingly.
Then let us imagine that there are no worms in green apples, and 4 of 5 red apples contain worms. It is obvious then to say that worm prefer red apples. But our estimate gives us the following numbers:


*

*$P(All) = 0 \cdot \frac{100}{105} + \frac{4}{5} \cdot \frac{5}{105} = \frac{4}{105}$

*$P(PreferGreen) = 0 \cdot \frac{100}{105} + \frac{1}{5} \cdot \frac{5}{105} = \frac{1}{105}$

*$P(PreferRed) = 1 \cdot \frac{100}{105} + \frac{4}{5} \cdot \frac{5}{105} = \frac{104}{105}$

*$P(None) = 1 \cdot \frac{100}{105} + \frac{1}{5} \cdot \frac{5}{105} = \frac{101}{105}$
We see that the most probable event is "PreferRed", but its probability is quite close to the probability of "None". To make the difference more evident, we can choose the following estimate instead:


*

*$P(All) = P(worm | green) \cdot P(worm | red)$

*$P(PreferGreen) = P(worm | green) \cdot P(no\; worm | red)$

*$P(PreferRed) = P(no\; worm | green) \cdot P(worm | red)$

*$P(None) = P(no\; worm | green) \cdot P(no\; worm | red)$
Because they give us more evident difference between probabilities:


*

*$P(All) = 0 \cdot \frac{4}{5} = 0$

*$P(PreferGreen) = 0 \cdot \frac{1}{5} = 0$

*$P(PreferRed) = 1 \cdot \frac{4}{5} = \frac{4}{5}$

*$P(None) = 1 \cdot \frac{1}{5} = \frac{1}{5}$
Because the difference between $\frac{4}{5}$ and $\frac{1}{5}$ is more evident than the difference between $\frac{104}{105}$ and $\frac{101}{105}$. In our application we need the difference to be evident.
But I don't understand how to explain this estimate from the theoretical point of view.
Can anybody help me?
 A: Various scenarios are possible and not all would use the
same statistical analysis.  
Here is one example:  Out of 100 green applies 6 have worm damage;
out of 5 red apples, 2 have worm damage. You could try a formal
test to see if proportions $\hat p_g = .06$ and $\hat p_r = .40$ are
significantly different. (Asking this makes sense only if red and green
applies were grown and stored together so worms had equal munching opportunity for each apple.)
You can look in a basic statistics text or online for 'test of two proportions'. (For example, NIST.) Various statistical computer programs implement such
a test. Minitab is one of them, giving results below:
Test and CI for Two Proportions 

Sample  X    N  Sample p
1       6  100  0.060000
2       2    5  0.400000

Difference = p (1) - p (2)
Estimate for difference:  -0.34
95% upper bound for difference:  0.0224804
Test for difference = 0 (vs < 0):  Z = -2.80  P-Value = 0.003

* NOTE * The normal approximation may be inaccurate for small samples.

Fisher’s exact test: P-Value = 0.046

The first test uses a normal approximation. The note complains that you have too little data (especially for red apples) for the P-value 0.003 to be
trusted exactly. But this P-value is sufficiently smaller that 0.05, that
it seems reasonable to say the two sample proportions are significantly 
different at the 5% level.
Fisher's exact test is sometimes more accurate for small samples. It uses
the hypergeometric distribution. The reasoning is as follows.  I have 105 apples in a bag (100 green, 5 red), worms randomly attack 8, what is the
probability six or fewer are green: $P(X \le 6).$ The probability for exactly $6$ is $P(X=6) = 0.0428:$
$$\frac{{100 \choose 6}{5 \choose 2}}{105 \choose 8} = 0.0428,$$
which can be evaluated by computing the  three binomial coefficients or by
using a hypergeometric PDF dhyper in R.
choose(100, 6)*choose(5,2)/choose(105,8)
[1] 0.04275365
dhyper(6, 100, 5, 8)
[1] 0.04275365

The remaining five probabilities are smaller. The sum for $P(X \le 6) = 0.0455$ can be found in R with the hypergeometric CDF phyper. The result agrees
with the Minitab output.
phyper(6, 100, 5, 8)
[1] 0.04552478

A simpler scenario is to ask whether the worm infestation is sufficiently bad that half of the apples are wormy. With the data above, it seems not. If 105 apples are equally likely to be wormy or not, then  'on average' we would expect to see about 52 or 53 wormy apples. The probability of seeing
8 or fewer wormy ones is very small. Specifically, the null distribution of the number $Y$ of wormy apples is $Y \sim \mathsf{Binom}(n = 105, p = .5)$ and $P(Y \le 8) \approx 0.$
pbinom(8, 105, .5)
[1] 7.476687e-21

A: Your first estimates are about: 1/ The probbility that an apple has a worm 4/ The propability that an apple has no worm 2/ The probability that an apple has a worm and is green 3/The probability that an apple has a worm and is red.
None of these estimates will help you to choose between your alternative hypotheses.
Let us first consider the hypothesis (All) = "Worms eat all apples". What does it mean ? I think it means that worms would choose red and green apple at random. That is: $P(worm|green)=P(worm|red)=P(worm)$
Alternatively, the hypothesis (Green) = "Worms prefer green apples" can translate into: $P(worm|green)>P(worm)$
Hence your problem translates into testing:
A- (Green) vs (All):  Is $P(worm|green)$ significantly higher than $P(worm)$ ?
B- (Red) vs (All):  Is $P(worm|red)$ significantly higher than $P(worm)$ ?
C- (Red) vs (Green):  Is $P(worm|red)$ significantly higher than $P(worm|Green)$ ?
Hoping it helps you start.
