Hypothesis Testing with the Student t-Distribution

Hypothesis Testing with the Student $t$-distribution

We test hypotheses with the Student $t$-distribution when we have a sample of the population and the population standard deviation is not known.

We estimate the population standard deviation using \[s = \sqrt{\frac{1}{n-1}\sum\limits_{i=1}^n(x_i-\bar{x})^2}\] so the test statistic becomes \[t= \frac{\bar{x}-\mu}{\sqrt{\frac{s^2}{n}}}\] where $n$ is the number of samples, $\bar{x}$ is the sample mean, $\mu$ is the population mean and $x_1, x_2, \ldots, x_n$ are the $n$ observations obtained in the sample.

Because we are dividing by an estimate, the test statistic does not have a standard normal distribution under the null hypothesis, instead it has a Student $t$-distribution with $n-1$ degrees of freedom.

Worked Example 1

Worked Example

The population mean of the heights of five-year old boys is 100cm. A teacher measures the height of her twenty five students, obtaining a mean height of $105$cm and standard deviation $18$. This means $\bar{x}=105, \mu=100, s=18, n=25$. Perform a Student $t$-test with a $5$% significance level to calculate whether the true mean is actually greater than $100$cm.

Solution

We need to set up a hypothesis test. \begin{align} &H_0 : \mu = 100\\ &H_1 : \mu > 100 \end{align}

First calculate the $t$-statistic, \begin{align} t&=\frac{\bar{x} - \mu}{\frac{s}{\sqrt{n} } } \\ &=\frac{105 - 100}{\frac{18}{5} } \\ &= 1.3889 \text{.} \end{align} Now looking at the $t$-distribution table gives $t_{\alpha, v} = t_{0.05, 24} = 1.7109$.

We have $t = 1.3889 < 1.7109 = t_{\alpha, v}$ so we accept the null hypothesis. The mean height of the population of five-year old boys is $100$ at a $5$% significance level.

Video Example

In this video, Dr Lee Fawcett conducts a hypothesis test for the mean of a distribution whose population variance is unknown, using a one-sample t-test.

Paired Samples

Definition

Paired data is when each value in one sample corresponds to a specific value in the other sample.

If we have paired data, both samples must be of the same size. Call this sample size $n$. Let $x$ be the first sample and $y$ be the second sample. Then $x_1$ is paired with $y_1$, $x_2$ is paired with $y_2$ etc. so for $i = 1, 2, \ldots, n$, every $ x_i$ is paired with $y_i$.

Now calculate the difference $d_i$ between the pairs, where $d_i=y_i-x_i$. From this the mean difference $\bar{d}$ can be calculated where \[\bar{d} = \frac{1}{n} \sum\limits_{i=1}^{n} d_i \text{.}\] Now the test statistic is given by \[t = \frac{\bar{d}}{\frac{s}{\sqrt{n}}}\text{.}\]

An alternative formula for the test statistic is \[t= \frac{\sum\limits_{i=1}^n d}{\sqrt{\frac{n\left(\sum\limits_{i=1}^n d^2\right) - \left(\sum\limits_{i=1}^n d\right)^2}{n-1}}} \text{.}\] This is the same, but sometimes makes calculation easier.

Worked Example 2

Worked Example

A sports governing body wants to test whether a supplement used by professional athletes ought to be banned for increasing levels of testosterone in the body.

The levels of testosterone in picograms/millilitre of ten athletes were tested before and after taking the supplement, with the results summarised in the following table.

$i$

$1$

$2$

$3$

$4$

$5$

$6$

$7$

$8$

$9$

$10$

Before (pg/ml)

$65.83$

$111.15$

$106.18$

$91.12$

$97.43$

$135.89$

$69.45$

$83.33$

$157.88$

$74.69$

After (pg/ml)

$77.92$

$129.27$

$109.72$

$97.68$

$124.37$

$147.12$

$71.16$

$81.27$

$164.16$

$79.51$

Perform a hypothesis test using a $1$% significance level to decide whether or not the supplement should be banned.

Worked Example 3

Worked Example

A disgruntled member of public sits at a train station for over two hours recording the time at which trains arrive. He records the following data.

Claimed Arrival Time

$10$:$29$

$10$:$39$

$10$:$49$

$10$:$59$

$11$:$09$

$11$:$19$

$11$:$29$

$11$:$39$

$11$:$49$

$11$:$59$

$12$:$09$

$12$:$19$

Actual Arrival Time

$10$:$28$

$10$:$44$

$10$:$52$

$10$:$59$

$11$:$11$

$11$:$32$

$11$:$35$

$11$:$43$

$11$:$51$

$12$:$00$

$12$:$14$

$12$:$27$

Difference (minutes)

$-1$

$5$

$3$

$0$

$2$

$13$

$6$

$4$

$2$

$1$

$5$

$8$

The company responsible claim that on average, trains arrive $3$ minutes late which they believe is acceptable. Perform a Student $t$-test at a $1$% significance level to see if the actual mean is greater than the company claim.

Solution

First, write down the null and alternative hypotheses.

$H_0: \mu = 3$
$H_1: \mu >3$

From the alternative hypothesis, we see that we need to perform a one-tailed test.

As the test has been performed for us, we can move onto calculating the test statistic. As we are using the Student $t$-distribution, we first need to calculate the sample mean difference $\bar{d}$ and the sample standard deviation $s$:

\[\bar{x} = \dfrac{-1+5+3+0+2+13+6+4+2+1+5+8}{12} = 4\text{,}\] \[s = \sqrt{\sum_{i=1}^{12}\frac{(d_i - \bar{d})^2}{n-1} }.\]

Now calculate the differences: \begin{align} &(d_1-\bar{d})^2 = (-1 - 4)^2 = 25, \\ &(d_2-\bar{d})^2 = (5-4)^2 =1, \\ &(d_3-\bar{d})^2 = (3-4)^2=1,\\ &(d_4-\bar{d})^2 = (0-4)^2=16,\\ &(d_5-\bar{d})^2 = (2-4)^2 =4,\\ &(d_6-\bar{d})^2 = (13-4)^2=81,\\ &(d_7-\bar{d})^2 = (6-4)^2 =4,\\ &(d_8-\bar{d})^2 = (4-4)^2 =0,\\ &(d_9-\bar{d})^2 = (2-4)^2 =4, \\ &(d_{10} - \bar{d})^2 =(1-4)^2=9, \\ &(d_{11} - \bar{d})^2 = (5-4)^2 =1, \\ &(d_{12} - \bar{d})^2 = (8-4)^2 =16. \end{align} Substitute these into the formula for $s$,

\[s=\sqrt{\dfrac{25+1+1+16+4+81+4+0+4+9+1+16}{11} } = \sqrt{\dfrac{162}{11} } = \sqrt{14.7273} = 3.8376.\]

Now calculate the test statistic \[t= \dfrac{\bar{x} - \mu}{\frac{s}{\sqrt{n} } } = \dfrac{4-3}{\frac{3.8376}{\sqrt{12} } } = \dfrac{\sqrt{12} }{3.8376} = 0.9027.\]

Check the one-tailed tables with $11 = (12-1)$ degrees of freedom at the $1$% significance level. We see that the critical value is $2.7181$ so the critical region is $t>2.7181$. As $0.9027<2.7181$, the null hypothesis is accepted.

Video Example

In this video, Daniel Organisciak performs a hypothesis test on a paired set of data with variance unknown.

Unpaired Samples

If the data is unpaired, we have to compare the variances, even though we don't actually know the true value of the variance. If the sample variances are approximately equal we combine them when computing the test statistic, whereas if they are completely different, the test statistic is computed by considering each variance separately.

Unknown but Approximately Equal Variances

When the variances are equal we need to use pooled data. When we test hypotheses with two means, we will look at the difference $\mu_1 - \mu_2$. The null hypothesis will be of the form

$H_0 : \mu_1 - \mu_2 = a$

where $a$ is a constant. Often $a=0$ is used to compare if the two means are the same. Given two continuous random variables $X_1$ and $X_2$ with means $\mu_1$ and $\mu_2$ and variances $\frac{\sigma_1^2}{n_1}$ and $\frac{\sigma_2^2}{n_2}$ respectively, \[\mathrm{E} [\bar{X_1} - \bar{X_2} ] = \mathrm{E} [\bar{X_1}] - \mathrm{E} [\bar{X_2}] = \mu_1 - \mu_2\] and \[\mathrm{Var}[\bar{X_1} - \bar{X_2}] = \mathrm{Var}[\bar{X_1}] - \mathrm{Var}[\bar{X_2}]=\frac{\sigma_1^2}{n_1}+\frac{\sigma_2^2}{n_2}.\]

As we don't know the value of $\sigma$ we need to estimate it. This is done by pooling (combining) the sample variances. We introduce $S_p$ to mean the pooled standard deviation where \[S_p^2 = \frac{(n_1-1)S_1^2 + (n_2-1)S_2^2}{n_1+n_2-2} .\] Note this is a weighted average of the two variances. We then obtain the $t$-statistic using the formula \[t = \frac{(\bar{X_1}-\bar{X_2})-(\mu_1 - \mu_2)}{S_p \sqrt{\frac{1}{n_1}+\frac{1}{n_2}}}\] with $n_1+n_2-2$ degrees of freedom.

Worked Example 4

Worked Example

Two energy drinks both claim that their average caffeine content is $30$mg/$100$ml. The following data was recorded from random cans of each drink.

$X_1$

$29.37$

$31.24$

$29.98$

$29.04$

$28.93$

$31.34$

$30.16$

$X_2$

$29.79$

$31.89$

$33.84$

$32.37$

$31.40$

Perform a hypothesis test at a $1$% significance level to check if they have the same mean caffeine content.

Solution

We are not given the population standard deviation so we cannot perform a test using the normal distribution. This means we have to perform a Student $t$-test.

Mean of $X_1$ is \[\bar{X_1}=\frac{29.37+31.24+29.98+29.04+28.93+31.34+30.16}{7} = 30.0086.\] Mean of $X_2$ is \[\bar{X_2}=\frac{29.79+31.89+33.84+32.37+31.40}{5}=31.6980.\] Firstly, we notice our data isn't paired. One observation of $X_1$ does not have a correspondence with any observation of $X_2$.

$X_1 - \bar{X_1}$

$-0.6386$

$1.2314$

$-0.0286$

$-0.9686$

$-1.0786$

$1.3314$

$0.1514$

$X_2-\bar{X_2}$

$-1.9080$

$0.1920$

$1.4420$

$0.5720$

$-0.2980$

$(X_1 - \bar{X_1})^2$

$0.4078$

$1.5164$

$0.0008$

$0.9381$

$1.1633$

$1.7727$

$0.0229$

$(X_2-\bar{X_2})^2$

$3.6406$

$0.0369$

$2.0794$

$0.3272$

$0.0888$

We next need to calculate the two standard deviations:

\begin{align} s_1 &= \sqrt{\frac{1}{n_1-1}\sum\limits_{i=1}^n (x_i-\bar{x})^2} \\\\ &=\sqrt{\frac{1}{6} \times (0.4078+1.5164+0.0008+0.9381+1.1633+1.7727+0.0229 } \\\\ &=0.9851 \text{,} \\\\ s_2 &= \sqrt{\frac{1}{n_1-1}\sum\limits_{i=1}^n (x_i-\bar{x})^2} \\\\ &=\sqrt{\frac{1}{4} \times (3.6406+0.0369+2.0794+0.3272+0.0888)} \\\\ &=1.2422 . \end{align} These standard deviations are of a similar size. The corresponding variances are $0.9703$ and $1.5431$ which are also similar so we assume that the population variances are the same. This means we need to calculate the pooled standard deviation. The pooled standard deviation $s_p$ is given by \begin{align} s_p&= \frac{(n_1-1)s_1^2+(n_2-1)s_2^2}{n_1+n_2-2} \\ &= \frac{6 \times 0.9851^2 + 4 \times 1.2422^2}{6+4-2} \\ &=1.1995 . \end{align}

The test statistic $t$ is given by \begin{align} t &= \frac{(\bar{X_1}-\bar{X_2})-(\mu_1 - \mu_2)}{S_p \sqrt{\frac{1}{n_1}+\frac{1}{n_2} } }\\ &=\frac{30.0086 - 31.6980}{1.1195 \times \sqrt{\frac{1}{5} + \frac{1}{7} } } \\ &=-2.4052. \end{align}

Video Example

In this video, Holly Ainsworth conducts a test of the hypothesis that two samples come from distributions with the same population mean, using a two-sample t-test.

Unknown and unequal variances

What if the variances aren't equal? This time the $t$-statistic is calculated using the formula \[t = \frac{(\bar{X_1}-\bar{X_2})-(\mu_1-\mu_2)}{ \sqrt{\frac{S_1^2}{n_1}+\frac{S_2^2}{n_2}}}\] where $\bar{X_1}$ and $\bar{X_2}$ are the sample means, $S_1^2$ and $S_2^2$ are the sample variances and $n_1$ and $n_2$ are the sample sizes. The number of degrees of freedom $v$ is given by \[v=\frac{\left(\frac{S_1^2}{n_1}+\frac{S_2^2}{n_2} \right)^2}{\frac{1}{n_1+1}\left(\frac{S_1^2}{n_1}\right)^2+\frac{1}{n_2+1}\left(\frac{S_2^2}{n_2}\right)^2}-2.\]

Workbooks

These workbooks produced by HELM are good revision aids, containing key points for revision and many worked examples.

Test Yourself

Test yourself: Numbas quiz on $t$-tests

Test yourself: Numbas test on two sample $t$-tests

External Resources

See Also

Selecting a Hypothesis Test