| ← Previous Lecture | Home | Next Lecture → |
This lecture introduces two important probability distributions for count data: the binomial distribution and the Poisson distribution.
We begin with a simple coin-toss example and then move to a biological application involving mutations in the HIV genome.
The same example is then used to introduce:
1. Binomial Distribution
2. Poisson Distribution
3. HIV Mutation Example
4. Central
95% Region for a Binomial Distribution
5. Left-Tailed Binomial
Test
6. Cumulative Distribution
Function
7. Hypothesis
Test for the HIV Mutation Rate
By the end of this lecture, you should be able to:
dbinom();dpois();pbinom();qbinom();binom.test();File: BinomialDistribution.R
Many biological measurements are counts.
Examples include:
Such quantities are discrete variables because they take countable values such as
\[ 0,1,2,3,\ldots \]
rather than any possible value on a continuous scale.
The binomial distribution is one of the simplest probability distributions for count data.
Suppose an experiment has only two possible outcomes:
success
failure
Examples might be:
head / tail
mutation / no mutation
infected / not infected
positive / negative
One such experiment is called a Bernoulli trial.
If the probability of success is
\[ p, \]
then the probability of failure is
\[ 1-p. \]
A Bernoulli trial describes a single trial.
Let
\[ X_i = \begin{cases} 1, & \text{if trial } i \text{ is a success},\\ 0, & \text{if trial } i \text{ is a failure}. \end{cases} \]
Each \(X_i\) is therefore a Bernoulli random variable.
If the experiment is repeated independently \(n\) times, with the same probability of success \(p\), then the total number of successes is
\[ X = X_1 + X_2 + \cdots + X_n. \]
This sum follows a binomial distribution:
\[ X \sim \mathrm{Binomial}(n,p). \]
For example:
one coin toss -> Bernoulli trial
3 coin tosses -> X = X1 + X2 + X3
= total number of heads
-> Binomial distribution
So the binomial distribution can be thought of as counting the number of successes in repeated Bernoulli trials.
A binomial distribution applies when:
If \(X\) is the number of successes in \(n\) trials, then
\[ X \sim \mathrm{Binomial}(n,p). \]
The probability of obtaining exactly \(x\) successes is
\[ P(X=x)= {n \choose x} p^x (1-p)^{n-x}. \]
The quantity
\[ {n \choose x} =\frac{n!}{x!(n-x)!} \]
counts the number of different ways in which \(x\) successes can occur among \(n\) trials.
Suppose a fair coin is tossed three times.
The number of trials is
n <- 3and the probability of a head on each toss is
p <- 0.5Let
\[ X = \text{number of heads}. \]
The possible values are
\[ X=0,1,2,3. \]
In R, dbinom() gives the probability of obtaining
exactly a specified number of successes.
dbinom(
3,
size = 3,
prob = 0.5
)The arguments are:
x number of successes
size total number of trials
prob probability of success in each trial
Thus,
dbinom(3, size = 3, prob = 0.5)calculates
\[ P(X=3). \]
For three fair coin tosses,
\[ P(X=3)= {3 \choose 3} (0.5)^3 (0.5)^0= \frac{1}{8}= 0.125. \]
Instead of calculating only one probability, we can calculate all possible probabilities at once.
x <- 0:n
prob <- dbinom(
x,
size = n,
prob = p
)Because x is a vector,
0 1 2 3R calculates
\[ P(X=0),\quad P(X=1),\quad P(X=2),\quad P(X=3). \]
The results can be placed in a data frame:
results <- data.frame(
Heads = x,
Probability = prob
)
resultsFor three fair coin tosses, the distribution is
| Heads | Probability |
|---|---|
| 0 | 0.125 |
| 1 | 0.375 |
| 2 | 0.375 |
| 3 | 0.125 |
Notice that
\[ \sum_x P(X=x)=1. \]
The probabilities of all possible outcomes of a probability distribution must add to 1.
The binomial distribution can be plotted using vertical lines:
plot(
x,
prob,
type = "h",
lwd = 5,
xlab = "Number of Heads",
ylab = "Probability",
main = "Binomial Distribution: 3 Coin Tosses"
)Here,
type = "h"draws a vertical line from the horizontal axis to each probability.
This representation is useful because the binomial distribution is discrete.
Points can be added at the top of the lines:
points(
x,
prob,
pch = 16,
cex = 1.3
)Here:
pch = 16 gives a filled circle;cex = 1.3 controls the size of the plotted points.For a binomial random variable,
\[ X \sim \mathrm{Binomial}(n,p), \]
the symbol
\[ \sim \]
means “is distributed as” or “follows the distribution”.
Thus,
\[ X \sim \mathrm{Binomial}(n,p) \]
is read as:
\(X\) follows a binomial distribution with parameters \(n\) and \(p\).
Here,
The expected number of successes is
\[ E[X]=np. \]
For example, if a fair coin is tossed 10 times,
\[ X \sim \mathrm{Binomial}(10,0.5), \]
and
\[ E[X]=10\times0.5=5. \]
This means that the average number of heads over many repetitions of the 10-toss experiment would approach 5. It does not mean that every set of 10 tosses will contain exactly 5 heads.
This is an example of the Law of Large Numbers: as the experiment is repeated many times, the mean of the observed values of \(X\) approaches the mean (expected value) of its probability distribution,
\[ E[X]=np. \]
This quantity will become particularly important when we connect the binomial distribution to the Poisson distribution.
File: PoissonDistribution.R
The Poisson distribution is another probability distribution for counts.
It is often used to describe the number of events occurring within a fixed interval of:
Examples could include:
The Poisson distribution has one parameter,
\[ \lambda, \]
which represents the expected number of events.
If
\[ X\sim\mathrm{Poisson}(\lambda), \]
then
\[ P(X=x)= \frac{e^{-\lambda}\lambda^x}{x!}. \]
The mean of the Poisson distribution is
\[ E[X]=\lambda. \]
A Poisson distribution can approximate a binomial distribution when:
\[ n \text{ is large}, \]
\[ p \text{ is small}, \]
and
\[ np=\lambda \]
remains approximately constant.
This is particularly useful for rare events.
For example, we can choose
lambda <- 2and then examine increasingly large values of n:
n <- 10or
n <- 100or
n <- 1000To keep
\[ np=\lambda, \]
we choose
p <- lambda / nThus:
n = 10 p = 0.2
n = 100 p = 0.02
n = 1000 p = 0.002
In each case,
\[ np=2. \]
As \(n\) becomes larger and \(p\) becomes smaller, the binomial distribution becomes increasingly similar to a Poisson distribution with
\[ \lambda=2. \]
The exact binomial probability of one success is
dbinom(
1,
size = n,
prob = p
)The corresponding Poisson probability is
dpois(
1,
lambda = lambda
)Thus:
dbinom() -> binomial probability
dpois() -> Poisson probability
The d at the beginning of both function names can be
thought of as asking for the probability associated with a particular
value of the distribution.
Consider values from 0 to 10:
x <- 0:10Calculate the exact binomial probabilities:
binom_prob <- dbinom(
x,
size = n,
prob = p
)and the Poisson probabilities:
poisson_prob <- dpois(
x,
lambda = lambda
)The exact binomial distribution can then be plotted:
plot(
x,
binom_prob,
type = "h",
lwd = 4,
ylim = c(0, 0.3),
xaxt = "n",
xlab = "Number of successes",
ylab = "Probability",
main = paste(
"Binomial vs Poisson",
"\nn =", n,
" p =", p
),
col = "blue"
)Add integer labels to the horizontal axis:
axis(
1,
at = x
)Then add the Poisson probabilities:
points(
x,
poisson_prob,
pch = 16,
cex = 1.2,
col = "red"
)Try the calculation with
n <- 10then
n <- 100and finally
n <- 1000while always defining
p <- lambda / nThe two distributions become progressively more similar.
This illustrates the limiting relationship
\[ \mathrm{Binomial}(n,p) \longrightarrow \mathrm{Poisson}(\lambda) \]
when
\[ n\rightarrow\infty, \qquad p\rightarrow 0, \qquad np=\lambda. \]
This relationship is particularly useful in biology because many biological events are individually rare but occur across a large number of opportunities.
File: HIVMutation.R
We now apply the binomial and Poisson distributions to a biological example.
Suppose the HIV genome contains approximately
\[ 10\,000 \]
nucleotides.
Assume that during one replication cycle each nucleotide independently has probability
\[ 5\times10^{-4} \]
of undergoing a mutation.
We ask:
What is the probability of observing exactly 3 mutations?
The number of nucleotides is
n <- 10000and the probability of mutation at each nucleotide is
p <- 5e-4Thus,
\[ X\sim\mathrm{Binomial}(10000,0.0005). \]
For a binomial distribution,
\[ E[X]=np. \]
Therefore,
\[ E[X]= 10000\times0.0005= 5. \]
In R:
lambda <- n * p
lambdagives
5
So although the mutation probability for an individual nucleotide is very small, there are many nucleotides at which a mutation could occur.
The expected number of mutations in the complete genome is therefore 5.
Set
x <- 3The exact binomial probability is
binom_prob <- dbinom(
x,
size = n,
prob = p
)
print(binom_prob)This calculates
\[ P(X=3) \]
using the binomial distribution.
Here,
\[ n=10000 \]
is large and
\[ p=0.0005 \]
is small.
The expected number of mutations is
\[ \lambda=np=5. \]
This is therefore a situation in which a Poisson approximation should work well.
Calculate
poisson_prob <- dpois(
x,
lambda = lambda
)
print(poisson_prob)This gives the approximation
\[ X\approx\mathrm{Poisson}(5). \]
The exact binomial and approximate Poisson probabilities should be very similar.
Consider mutation counts from 0 to 12:
x <- 0:12Calculate the exact binomial probabilities:
binom_prob <- dbinom(
x,
size = n,
prob = p
)and the Poisson approximation:
poisson_prob <- dpois(
x,
lambda = lambda
)Plot the binomial probabilities:
plot(
x,
binom_prob,
type = "h",
lwd = 4,
col = "blue",
xaxt = "n",
xlab = "Number of mutations",
ylab = "Probability",
main = "HIV Mutations: Binomial vs Poisson"
)Add an integer x-axis:
axis(
1,
at = x
)and the Poisson probabilities:
points(
x,
poisson_prob,
pch = 16,
cex = 1.2,
col = "red"
)Because \(n\) is large and \(p\) is small, the red Poisson points lie very close to the exact binomial distribution.
For this problem, R can easily calculate the exact binomial probabilities.
Therefore, there is no computational need to replace the binomial distribution with its Poisson approximation.
However, the comparison is useful because it demonstrates an important statistical relationship and explains why the Poisson distribution frequently appears in the study of rare events.
File: ConfidenceInterval_Binomial_2Tail.R
We now connect probability distributions with statistical hypothesis testing.
Suppose the mutation probability specified by a model is
\[ p=5\times10^{-4}. \]
If that model is correct, some numbers of mutations will be common and others will be unusually small or unusually large.
We can use the binomial distribution to identify these regions.
Choose a significance level
alpha <- 0.05Thus,
\[ \alpha=0.05. \]
The corresponding central probability is
\[ 1-\alpha=0.95. \]
In R:
confidence_level <- 1 - alpha
confidence_levelgives
0.95
For a two-tailed procedure, the significance level is divided between the two tails:
\[ \frac{\alpha}{2}= 0.025. \]
Conceptually:
left tail central region right tail
2.5% 95% 2.5%
For a continuous probability distribution this division can often be made exactly.
For a discrete distribution such as the binomial distribution, the available probabilities occur in discrete steps, so the tail probabilities will not necessarily be exactly 0.025.
Define
n <- 10000
p <- 5e-4and calculate the probability distribution:
x <- 0:15
prob <- dbinom(
x,
size = n,
prob = p
)R’s qbinom() function gives a quantile
of the binomial distribution.
For the lower boundary:
lower <- qbinom(
alpha / 2,
size = n,
prob = p
)For the upper boundary:
upper <- qbinom(
1 - alpha / 2,
size = n,
prob = p
)The function
qbinom(probability, size, prob)finds the number of successes corresponding to a specified cumulative probability.
The prefix
q
can therefore be associated with quantile.
We can assign different colors depending on whether a count lies inside or outside the central region:
bar_col <- ifelse(
x < lower | x > upper,
"tomato",
"skyblue"
)The expression
x < lower | x > uppermeans
x is below the lower boundary
OR
x is above the upper boundary
The symbol
|means logical OR in R.
The distribution can then be plotted:
barplot(
prob,
names.arg = x,
col = bar_col,
xlab = "Number of mutations",
ylab = "Probability",
main = "Binomial Distribution of HIV Mutations"
)The colors can be interpreted as:
blue central region
red tail regions
Suppose the null hypothesis specifies
\[ H_0:p=p_0. \]
If an observed result falls far into either tail of the distribution expected under \(H_0\), it provides evidence against that null hypothesis.
For a two-sided alternative,
\[ H_A:p\ne p_0, \]
both unusually small and unusually large mutation counts are relevant.
Conceptually:
very small X expected X very large X
| | |
evidence compatible evidence
against H0 with H0 against H0
The binomial distribution is discrete.
Therefore, we cannot always choose integer boundaries that place exactly
\[ 2.5\% \]
of the probability in each tail.
The probability in the rejection region may therefore be slightly smaller than the nominal significance level.
This is an important distinction between many exact tests for discrete data and tests based on continuous probability distributions.
File: ConfidenceInterval_Binomial_LeftTail.R
The previous example considered both tails of the distribution.
Sometimes the scientific question concerns only one direction.
Suppose we want to test whether the mutation probability is smaller than
\[ 5\times10^{-4}. \]
For the exact binomial calculation, we use the null model
\[ H_0:p=p_0=5\times10^{-4}, \]
and the alternative hypothesis
\[ H_A:p<5\times10^{-4}. \]
Because the alternative hypothesis contains
\[ p<p_0, \]
this is a left-tailed test.
If the true mutation probability is smaller than the value specified by \(H_0\), we expect to observe unusually small numbers of mutations.
Therefore, evidence against \(H_0\) occurs in the left tail of the distribution.
small number of mutations large number
|
v
rejection region do-not-reject region
<----------------|---------------------------->
A right-tailed test is also possible.
For example, if we want to test whether the mutation probability is larger than the value specified by \(H_0\), the hypotheses would be
\[ H_0:p=p_0 \]
and
\[ H_A:p>p_0. \]
In this case, unusually large numbers of mutations provide evidence against \(H_0\), so the rejection region lies in the right tail.
small number of mutations large number
|
v
do-not-reject region rejection region
----------------------------|-------------------->
Thus:
HA: p < p0 -> left-tailed test
HA: p > p0 -> right-tailed test
HA: p != p0 -> two-tailed test
Again choose
alpha <- 0.05For a left-tailed test, the complete significance level is placed in the left tail.
Thus we want a critical value satisfying approximately
\[ P(X\le x_{\mathrm{critical}}\mid H_0) \le 0.05. \]
First calculate
q <- qbinom(
alpha,
size = n,
prob = p0
)However, qbinom() returns the first integer at which the
cumulative probability reaches or exceeds the requested
probability.
Because the binomial distribution is discrete, that value can sometimes give a cumulative probability greater than \(\alpha\).
The script therefore checks it explicitly:
if (pbinom(q, size = n, prob = p0) <= alpha) {
critical <- q
} else {
critical <- q - 1
}This ensures that
\[ P(X\le \text{critical}\mid H_0) \le\alpha. \]
For the HIV example, the rejection region becomes
\[ X\le1. \]
The probability of this region is approximately
\[ P(X\le1)\approx0.0404. \]
It is smaller than 0.05 because there is no integer mutation count that gives a tail probability exactly equal to 0.05.
The bars can be colored according to whether they lie in the rejection region:
bar_col <- ifelse(
x <= critical,
"tomato",
"skyblue"
)Thus:
tomato rejection region
skyblue do-not-reject region
Plot the distribution:
barplot(
prob,
names.arg = x,
col = bar_col,
xlab = "Number of mutations",
ylab = "Probability",
main = "Left-Tailed Binomial Test for HIV Mutations"
)If the observed number of mutations falls in the red region,
\[ X\le1, \]
we reject
\[ H_0. \]
The data then provide evidence that
\[ p<p_0. \]
If the observed number of mutations falls outside this rejection region, we do not reject \(H_0\).
This wording is important.
Do not reject H0
does not mean
H0 has been proven true.
It means only that the observed data do not provide sufficiently strong evidence against \(H_0\) at the chosen significance level.
File: HIVMutation_CDF.R
So far we have often calculated probabilities for individual counts such as
\[ P(X=3). \]
Hypothesis testing often requires probabilities such as
\[ P(X\le3). \]
This is a cumulative probability.
Under the null hypothesis,
\[ p_0=5\times10^{-4} \]
and
\[ n=10000. \]
Suppose we observe
\[ x_{\mathrm{obs}}=3 \]
mutations.
In R:
n <- 10000
p0 <- 5e-4
x_obs <- 3Calculate probabilities for mutation counts from 0 to 15:
x <- 0:15
prob <- dbinom(
x,
size = n,
prob = p0
)The null hypothesis determines the probability distribution against which the observation will be compared.
For a left-tailed question, we are interested not only in exactly three mutations but also in outcomes even smaller than three.
Thus the relevant outcomes are
\[ 0,1,2,3. \]
They can be highlighted using
bar_col <- ifelse(
x <= x_obs,
"tomato",
"skyblue"
)Plot the distribution:
bp <- barplot(
prob,
names.arg = x,
col = bar_col,
xlab = "Number of mutations",
ylab = "Probability",
main = "Null distribution for HIV mutations"
)The observed value can be labelled:
text(
x = bp[x_obs + 1],
y = prob[x_obs + 1],
labels = "observed = 3",
pos = 3
)First calculate the individual probabilities:
pvals <- dbinom(
0:x_obs,
size = n,
prob = p0
)
print(pvals)These are
\[ P(X=0), \]
\[ P(X=1), \]
\[ P(X=2), \]
and
\[ P(X=3). \]
Adding them gives
\[ P(X\le3)= P(X=0) + P(X=1) + P(X=2) + P(X=3). \]
In R:
sum(pvals)For this example,
\[ P(X\le3) \approx0.265. \]
pbinom()Instead of calculating the individual probabilities and adding them, R can calculate the cumulative probability directly:
pbinom(
x_obs,
size = n,
prob = p0
)Thus
pbinom(3, size = 10000, prob = 5e-4)calculates
\[ P(X\le3). \]
It is useful to distinguish two R functions:
dbinom() probability at a particular value
pbinom() cumulative probability up to that value
For example,
dbinom(3, size = n, prob = p0)means
\[ P(X=3), \]
whereas
pbinom(3, size = n, prob = p0)means
\[ P(X\le3). \]
Graphically:
dbinom(3)
0 1 2 3 4 5 6 ...
^
|
only X = 3
while
pbinom(3)
0 1 2 3 4 5 6 ...
|-----------|
all values
up to 3
The cumulative distribution function, or CDF, is defined as
\[ F(x)=P(X\le x). \]
For the binomial distribution, pbinom() evaluates this
function.
This idea is central to hypothesis testing because a p-value often represents the probability of obtaining the observed result or something still more extreme under the null hypothesis.
File: HIVMutation_HypothesisTest.R
We can now combine the ideas from the previous sections into a formal hypothesis test.
Suppose the mutation probability per nucleotide is denoted by
\[ p. \]
This is the underlying mutation probability that we want to learn about from the data. Its value is generally unknown.
We need a reference value against which to compare the data. We denote this value by
\[ p_0. \]
The subscript \(0\) indicates that this is the probability specified by the null hypothesis, \(H_0\).
In this example,
\[ p_0 = 5\times10^{-4}. \]
The value \(p_0\) is not calculated from the current observation. It is a reference value specified before the hypothesis test. Depending on the scientific problem, it may come from previous experiments, published evidence, an established model, or another scientifically meaningful baseline.
Thus,
p = unknown underlying mutation probability
p0 = reference mutation probability specified by H0
= 5 x 10^-4
We observe 3 mutations among 10,000 nucleotides.
If the mutation probability were
\[ p_0=5\times10^{-4}, \]
then for
\[ n=10000 \]
nucleotides, the expected number of mutations would be
\[ E[X]=np_0 =10000\times5\times10^{-4} =5. \]
But we observed
\[ x_{\mathrm{obs}}=3. \]
The observed mutation proportion is therefore
\[ \hat p= \frac{3}{10000} =3\times10^{-4}, \]
which is smaller than
\[ p_0=5\times10^{-4}. \]
However, neither
\[ 3<5 \]
nor
\[ \hat p<p_0 \]
is sufficient by itself to reject the null hypothesis.
Even if the true mutation probability were exactly \(p_0\), random variation would produce different mutation counts in repeated experiments.
For example:
2 mutations
3 mutations
4 mutations
5 mutations
6 mutations
7 mutations
...
The value
\[ E[X]=np_0=5 \]
is an expected value, not a value that must occur in every experiment.
The relevant question is therefore not simply
Is the observed number smaller than 5?
Instead, we ask
If the mutation probability were really \(p_0\), how likely would it be to observe 3 mutations or fewer?
This is the purpose of the hypothesis test.
The null hypothesis is
\[ H_0:p=p_0, \]
where
\[ p_0=5\times10^{-4}. \]
Therefore,
\[ H_0:p=5\times10^{-4}. \]
The alternative hypothesis is
\[ H_A:p<p_0, \]
or equivalently,
\[ H_A:p<5\times10^{-4}. \]
Under \(H_0\),
\[ X\sim\mathrm{Binomial}(n,p_0). \]
The null hypothesis therefore specifies the probability distribution against which the observed mutation count is evaluated.
We have observed only one experiment:
\[ x_{\mathrm{obs}}=3 \]
mutations among
\[ n=10000 \]
nucleotides.
The hypothesis test asks us to imagine repeating the same experiment many times under \(H_0\).
If
\[ H_0:p=p_0, \]
then the mutation count would vary from experiment to experiment because of random variation, but those counts would follow
\[ X\sim\mathrm{Binomial}(n,p_0). \]
Thus, we judge whether the observed value \(x_{\mathrm{obs}}=3\) is unusual by comparing it with the distribution of values that could occur under \(H_0\).
# Number of nucleotides examined
n <- 10000
# Mutation probability under the null hypothesis
p0 <- 5e-4
# Observed number of mutations
x_obs <- 3
# Significance level
alpha <- 0.05Here:
n = total number of nucleotides
p0 = mutation probability specified by H0
x_obs = observed number of mutations
alpha = significance level used for the statistical decision
Notice that p0 belongs to the null
model, whereas x_obs comes from the
observed data.
The alternative hypothesis is
\[ H_A:p<p_0. \]
Therefore, unusually small mutation counts provide evidence in the direction of \(H_A\).
This is a left-tailed test.
For the observed value \(x_{\mathrm{obs}}=3\), the relevant tail probability is
\[ P(X\le3\mid H_0). \]
Because \(H_0\) specifies
\[ p=p_0, \]
this probability is calculated using
\[ X\sim\mathrm{Binomial}(10000,5\times10^{-4}). \]
R provides the function
binom.test()for performing an exact binomial test.
result <- binom.test(
x = x_obs,
n = n,
p = p0,
alternative = "less"
)
resultThe arguments mean:
x observed number of successes
n total number of trials
p probability specified by H0
alternative form of the alternative hypothesis
Using
alternative = "less"specifies
\[ H_A:p<p_0. \]
R may print
alternative hypothesis: true probability of success is less than 5e-04
Here, the word true refers to the true but unknown probability of success, \(p\).
It does not mean that the alternative hypothesis has been shown to be true.
The line simply states the alternative hypothesis:
\[ H_A:p<5\times10^{-4}. \]
Whether the data provide sufficient evidence against \(H_0\) is decided from the p-value and the chosen significance level \(\alpha\).
binom.test()
comparing?It is useful to distinguish three different quantities:
\[ p_0=5\times10^{-4} \]
is the mutation probability specified by the null hypothesis;
\[ \hat p=\frac{x_{\mathrm{obs}}}{n} =\frac{3}{10000} =3\times10^{-4} \]
is the mutation probability estimated from the observed sample; and
\[ P(X\le x_{\mathrm{obs}}\mid H_0) \]
is the left-tail probability used as the p-value.
binom.test() does not decide
significance merely because
\[ \hat p<p_0 \]
or because
\[ x_{\mathrm{obs}}<E[X]. \]
Instead, \(p_0\) defines the complete null distribution
\[ X\sim\mathrm{Binomial}(n,p_0), \]
and the observed count is used to determine the appropriate tail probability in that distribution.
The p-value returned by binom.test() can be extracted
using
p_value <- result$p.value
print(p_value)For this left-tailed test,
\[ p\text{-value} = P(X\le3\mid H_0). \]
For these data,
\[ p\text{-value}\approx0.265. \]
Thus:
If the mutation probability were really \(p_0=5\times10^{-4}\), the probability of observing 3 or fewer mutations among 10,000 nucleotides would be about 26.5%.
The same tail probability can be calculated directly using
pbinom(
x_obs,
size = n,
prob = p0
)so, for this one-sided test, binom.test() and
pbinom() give the same p-value.
The p-value is not the probability that \(H_0\) is true. It is calculated assuming that \(H_0\) is true.
The statistical decision is made by comparing the p-value with the chosen significance level.
p_value < alphaThe decision rule is
\[ p\text{-value}<\alpha \quad\Rightarrow\quad \text{reject }H_0, \]
whereas
\[ p\text{-value}\ge\alpha \quad\Rightarrow\quad \text{do not reject }H_0. \]
An important point is that binom.test() itself reports
the p-value but does not print the final decision. The
decision depends on the value of \(\alpha\) chosen for the analysis.
if (p_value < alpha) {
print("Reject H0")
} else {
print("Do not reject H0")
}For this example,
\[ 0.265>0.05. \]
Therefore,
\[ \boxed{\text{Do not reject }H_0} \]
at the 5% significance level.
The observed mutation count is
\[ x_{\mathrm{obs}}=3, \]
whereas the expected number under \(H_0\) is
\[ E[X]=np_0=5. \]
Thus, 3 mutations is indeed below the expected value of 5.
However,
\[ P(X\le3\mid H_0)\approx0.265. \]
A probability of about 26.5% is not particularly small.
Therefore, observing 3 mutations is not sufficiently unusual under \(H_0\) to provide evidence that the true mutation probability is smaller than
\[ 5\times10^{-4}. \]
This illustrates an important distinction:
observed value below the expected value
is not the same as
statistically unusual under the null distribution
The alternative argument determines the direction of the
test.
alternative = "less"corresponds to
\[ H_A:p<p_0. \]
alternative = "greater"corresponds to
\[ H_A:p>p_0. \]
and
alternative = "two.sided"corresponds to
\[ H_A:p\ne p_0. \]
The scientific question should determine the alternative hypothesis before examining the result.
Earlier we constructed a left-tailed rejection region for
\[ \alpha=0.05. \]
For the HIV example, the rejection region was
\[ X\le1. \]
Our observation was
\[ X=3. \]
Since 3 is not in the rejection region, we do not reject \(H_0\).
The p-value approach gives the same conclusion:
\[ p\text{-value} = P(X\le3\mid H_0) \approx0.265 > 0.05. \]
Therefore,
\[ \text{do not reject }H_0. \]
Thus, the two approaches are equivalent ways of viewing the same statistical decision:
critical-value approach
|
| Is the observation in the rejection region?
|
v
statistical decision
^
|
| Is the p-value smaller than alpha?
|
p-value approach
A hypothesis test does not normally prove that a hypothesis is true or false.
If
\[ p\text{-value}<\alpha, \]
we say
Reject H0
because the observation is sufficiently unusual under \(H_0\).
If
\[ p\text{-value}\ge\alpha, \]
we say
Do not reject H0
because the data do not provide sufficiently strong evidence against \(H_0\).
We should generally avoid saying
Accept H0
because failure to find evidence against a hypothesis is not the same as proving that the hypothesis is correct.
R uses a consistent naming system for probability distributions.
For the binomial distribution:
dbinom() probability of exactly x successes
pbinom() cumulative probability P(X <= x)
qbinom() quantile corresponding to a cumulative probability
For the Poisson distribution:
dpois() probability of exactly x events
The prefixes are useful to remember:
d density / probability mass
p cumulative probability
q quantile
For example:
dbinom(
3,
size = 10000,
prob = 5e-4
)calculates
\[ P(X=3), \]
while
pbinom(
3,
size = 10000,
prob = 5e-4
)calculates
\[ P(X\le3). \]
And
qbinom(
0.05,
size = 10000,
prob = 5e-4
)finds a mutation count associated with the lower 5% of the cumulative distribution.