Suppose we have a fair coin, so that we expect to get nearly the same number of heads and tails if we flip the coin many times. We expect to get heads half the time, and tails half the time. We say that the probability of getting heads p=1/2, and the probability of getting tails is q =1/2 also. This is our null hypothesis, H0..

Since these are the only two possibilities, i.e. we will get one or the other each coin toss. Notice that 1/2 + 1/2 =1; we should agree that it will be convenient if the sum of all probabilities adds to one. Then if p equals any value less than one, q must be (1-p).

We can do a lot of science by assuming that there is no difference between two things, and then check the frequencies we observe against our assumption, our Null Hypothesis, H0. If our observation should be very rare, maybe we should reject H0.

If we flip a coin only four times, and we get HHHH, we shrug and say we got that by chance; heads and tails are still equally likely. Expected values were not found because of “sampling error”.

But if we get HHHHHHHHHHHHHHHHHHHHHHHT in 24 coin tosses we begin to think that our null hypothesis is wrong, i.e. that maybe there is a difference in the probability of getting a head and tail.

We can actually calculate the chance of getting k=23 heads in n=24 coin tosses if our null hypothesis H0 is right. We feel intuitively that 23 heads and one tail will be a rare event. Call the event "heads" a success.

The probability of getting exactly k successes in n trials is given by the binomial density:

The pk(1-p)n-k calculates the probability of an outcome,

While

calculates the possible orderings.

I'll calculate it for you, just this once. The terms on the left side are:

n! = 24*23*22* … *1 ; k! = 23*22*21* … *1 ; and n - k = 24 - 23 = 1 so (n - k)! = 1! =1

so most of this cancels ___n! ___ = (24*23*22* … *1) = 24

k! (n - k)! (23*22*21* … *1)( 1 )

p = 1/2 and 1-p is also =1/2, so the right side is 1/2 raised to the 23rd power times 1/2. The whole thing is

= 24 * .000000192 * 1/2 = .00000143. In other words 23 heads and one tail will occur about once in 700,000 attempts at repeated 24 coin tosses. We can probably agree that that is too rare. Our coin probably came from a magic shop, and we should reject H0.