How was p-value calculated in this Wikipedia example of a Binomial test Consider the following example from This binomial test wikipedia article:

Suppose we have a board game that depends on the roll of one die and attaches special importance to rolling a 6. In a particular game, the die is rolled 235 times, and 6 comes up 51 times. If the die is fair, we would expect 6 to come up 235/6 = 39.17 times. Is the proportion of 6s significantly higher than would be expected by chance, on the null hypothesis of a fair die?

The article then goes on to compute the p-value for a one-tailed binomial test (i.e. it finds the probability of getting 51 or more sixes from 235 rolls).
Then the article says that we might be interested in using a two-tailed p-value (Excerpt is quoted below). I have two questions:


*

*What are the two tails we are looking at here (I think one is that $p(\#successes \geq 51)$. The other i guess would be of the form $p(\#successes \leq \bf{X})$, I am asking what is $\bf{X}$ in this example).

*How did they calculate the probability of  $.0437$. The explain it in the article -- I bolded this part --  but the explanation doesn't make sense to me.


*

*(i.e. what is the "probability that the total deviation in numbers of events in either direction from the expected value"? I don't even get what the expected value is here? It would just be 39.17, the expected number of 6's in 235 rolls right?)




There are two methods to define the two tailed p-value. One method is to sum the probability that the total deviation in numbers of events in either direction from the expected value is either more than or less than the expected value. The probability of that occurring in our example is 0.0437. The second method involves computing the probability that the deviation from the expected value is as unlikely or more unlikely than the observed value, i.e. from a comparison of the probability density functions. This can create a subtle difference, but in this example yields the same probability of 0.0437

 A: Method One: Observed 51 is more than expected 39.17 by 11.83. If the observed number is less than expected 39.17 by 11.83 then observed number would be 27.34. So p value is calculated by $\Pr(X\ge 51) + \Pr(X\le 27)$.
Method Two: Get $\Pr(X=51)$. Calculate $\Pr(X=i), i = 0,..., 235$. Add all $\Pr(X=i)$ with $\Pr(X=i)\le \Pr(X=51)$. Of course there is easy way to get it.
A: It's useful to consider a couple of things:

*

*the definition of a p value. It is the probability of obtaining a test statistic at least as extreme as the one we observed from the sample, if the null hypothesis were true.


*The particular test statistic we're using, which is a way of measuring how far the sample is from what we'd expect under the null; we choose it so that the particular alternative(s) we're interested in will tend to yield different test statistics than the null does.
In particular, we generally choose the statistic so that it tends to either give large values or small values when the null hypothesis is false.
With those ideas in place, let's not discuss the calculations for the problem at hand.
Let's use $O_6$ to denote be the observed count of 6's in our experiment. In the case of this binomial proportion, we could look at measuring the difference of the observed count of 6's from the expected count (when the null is true), $T = O_6-\frac{235}{6}$ (or we could equivalently look at $T_2 = \frac{O_6}{235} - \frac16$, the difference of the proportion).
When looking at the one tailed alternative ($p_6>\frac16$), the test statistic would just be $T$, and values considerably larger than the expected difference of zero will be more consistent with the alternative hypothesis than they would be with the null.

Note that what is plotted here is the count rather than the count minus its expected value; the appearance is the same, the only thing that is different is how the x-axis is labelled. The red parts represent the terms that make up the p value.
With a two tailed alternative, we could consider $T_3=|O_6-\frac{235}{6}|$ as our test statistic; this will make lower proportions than $\frac16$ and higher proportions than $\frac16$ both yield large values of the test statistic. Our measure of "more extreme" is now just the absolute difference of the observed count from that we'd expect if the null were true.

We could of course achieve the same end by considering our original $T$ but look at the distance from expected in both directions:

