# 41 T-test

## 41.1 One-Sample T-test

The t-test is commonly used to look for evidence that the mean of a normally distributed random variable may differ from a hypothesized (or previously observed) value.

### 41.1.1 T-Statistic

The $$t$$-statistic is a standardized measure of the magnitude of difference between a sample’s mean and some known, non-random constant. It is similar to a $$z$$-statistic, but differs in that a $$t$$-statistic may be calculated without knowledge of the population variance.

### 41.1.2 Definitions and Terminology

Let $$\bar{x}$$ be a sample mean from a sample with standard deviation $$s$$. Let $$\mu_0$$ be a constant, and $$s_{\bar{x}} = s/\sqrt{n}$$ be the standard error of the parameter $$\bar{x}$$. $$t$$ is defined: $t = \frac{\bar{x} - \mu_0}{s_{\bar{x}}} = \frac{\bar{x} - \mu_0}{\frac{s}{\sqrt{n}}}$

and has $$\nu = n-1$$ degrees of freedom.

### 41.1.3 Hypotheses

The hypotheses for these test take the forms:

For a two-sided test: \begin{aligned} H_0: \mu &= \mu_0\\ H_a: \mu &\neq \mu_0 \end{aligned}

For a one-sided test: \begin{aligned} H_0: \mu &< \mu_0\\ H_a: \mu &\geq \mu_0 \end{aligned}

or \begin{aligned} H_0: \mu &> \mu_0\\ H_a: \mu &\leq \mu_0 \end{aligned}

To compare a sample $$(X_1, \ldots, X_n)$$ against the hypothesized value, a T-statistic is calculated in the form:

$T = \frac{\bar{x} - \mu_0}{s / \sqrt{n}}$

Where $$\bar{x}$$ is the sample mean and $$s$$ is the sample standard deviation.

### 41.1.4 Decision Rule

The decision to reject a null hypothesis is made when an observed T-value lies in a critical region that suggests the probability of that observation is low. We define the critical region as the upper bound we are willing to accept for $$\alpha$$, the Type I Error.

In the two-sided test, $$\alpha$$ is shared equally in both tails. The rejection regions for the most common values of $$\alpha$$ are depicted in the figure below, with the sum of shaded areas on both sides equaling the corresponding $$\alpha$$. It follows, then, that the decision rule is:

Reject $$H_0$$ when $$T \leq t_{\alpha/2, \nu}$$ or when $$T \geq t_{1-\alpha/2, \nu}$$.

By taking advantage of the symmetry of the T-distribution, we can simplify the decision rule to:

Reject $$H_0$$ when $$|T| \geq t_{1-\alpha/2, \nu}$$

## Warning: Ignoring unknown aesthetics: ymax

## Warning: Ignoring unknown aesthetics: ymax Figure 41.1: The example displayed uses 25 degrees of freedom

In the one-sided test, $$\alpha$$ is placed in only one tail. The rejection regions for the most common values of $$\alpha$$ are depicted in the figure below. In each case, $$\alpha$$ is the area in the tail of the figure. It follows, then, that the decision rule for a lower tailed test is:

Reject $$H_0$$ when $$T \leq t_{\alpha, \nu}$$.

For an upper tailed test, the decision rule is:

Reject $$H_0$$ when $$T \geq t_{1-\alpha, \nu}$$.

Using the symmetry of the T-distribution, we can simplify the decision rule as:

Reject $$H_0$$ when $$|T| \geq t_{1-\alpha, \nu}$$.

## Warning: Ignoring unknown aesthetics: ymax

## Warning: Ignoring unknown aesthetics: ymax Figure 41.2: The example displayed uses 25 degrees of freedom

The decision rule can also be written in terms of $$\bar{x}$$:

Reject $$H_0$$ when $$\bar{x} \leq \mu_0 - t_\alpha \cdot s/\sqrt{n}$$ or $$\bar{x} \geq \mu_0 + t_\alpha \cdot s/\sqrt{n}$$.

This change can be justified by:

\begin{aligned} |T| &\geq t_{1-\alpha, \nu}\\ \Big|\frac{\bar{x} - \mu_0}{s/\sqrt{n}}\Big| &\geq t_{1-\alpha, \nu} \end{aligned}

\begin{aligned} -\Big(\frac{\bar{x} - \mu_0}{s/\sqrt{n}}\Big) &\geq t_{1-\alpha, \nu} & \frac{\bar{x} - \mu_0}{s/\sqrt{n}} &\geq t_{1-\alpha, \nu}\\ \bar{x} - \mu_0 &\leq - t_{1-\alpha, \nu} \cdot s/\sqrt{n} & \bar{x} - \mu_0 &\geq t_{1-\alpha, \nu} \cdot s/\sqrt{n}\\ \bar{x} &\leq \mu_0 - t_{1-\alpha, \nu} \cdot s/\sqrt{n} & \bar{x} &\geq \mu_0 + t_{1-\alpha, \nu} \cdot s/\sqrt{n} \end{aligned}

For a two-sided test, both the conditions apply. The left side condition is used for a left-tailed test, and the right side condition for a right-tailed test.

### 41.1.5 Power

The derivations below make use of the following symbols:

• $$\bar{x}$$: The sample mean
• $$s$$: The sample standard deviation
• $$n$$: The sample size
• $$\mu_0$$: The value of population mean under the null hypothesis
• $$\mu_a$$: The value of the population mean under the alternative hypothesis.
• $$\alpha$$: The significance level
• $$\gamma(\mu)$$: The power of the test for the parameter $$\mu$$.
• $$t_{\alpha, \nu}$$: A quantile of the central t-distribution for a probability, $$\alpha$$ and $$n-1$$ degrees of freedom.
• $$T$$: A calculated value to be compared against a t-distribution.
• $$C$$: The critical region (rejection region) of the test.

Two-Sided Test

\begin{aligned} \gamma(\mu_a) &= P_{\mu_a}(\bar{x} \in C)\\ &= P_\mu\big(\bar{x} \leq \mu_0 - t_{\alpha/2, \nu} \cdot s/\sqrt{n}\big) + P_{\mu_a}\big(\bar{x} \geq \mu_0 + t_{1-\alpha/2, \nu} \cdot s/\sqrt{n}\big)\\ &= P_{\mu_a}\big(\bar{x} - \mu_a \leq \mu_0 - \mu_a - t_{\alpha/2, \nu} \cdot s/\sqrt{n}\big) + P_{\mu_a}\big(\bar{x} - \mu_a \geq \mu_0 - \mu_a + t_{1-\alpha/2, \nu} \cdot s/\sqrt{n}\big)\\ &= P_{\mu_a}\Big(\frac{\bar{x} - \mu}{s/\sqrt{n}} \leq \frac{\mu_0 - \mu_a - t_{\alpha/2, \nu} \cdot s/\sqrt{n}}{s/\sqrt{n}}\Big) + P_{\mu_a}\Big(\frac{\bar{x} - \mu}{s/\sqrt{n}} \geq \frac{\mu_0 - \mu_a + t_{1-\alpha/2, \nu} \cdot s/\sqrt{n}}{s/\sqrt{n}}\Big)\\ &= P_{\mu_a}\Big(T \leq \frac{\mu_0 - \mu_a}{s/\sqrt{n}} - t_{\alpha/2, \nu}\Big) + P_{\mu_a}\Big(T \geq \frac{\mu_0 - \mu_a}{s/\sqrt{n}} + t_{1-\alpha/2, \nu}\Big)\\ &= P_{\mu_a}\Big(T \leq -t_{\alpha/2, \nu} + \frac{\mu_0 - \mu_a}{s/\sqrt{n}}\Big) + P_{\mu_a}\Big(T \geq t_{1-\alpha/2, \nu} + \frac{\mu_0 - \mu_a}{s/\sqrt{n}}\Big)\\ &= P_{\mu_a}\Big(T \leq -t_{\alpha/2, \nu} + \frac{\sqrt{n} \cdot (\mu_0 - \mu_a)}{s}\Big) + P_{\mu_a}\Big(T \geq t_{1-\alpha/2, \nu} + \frac{\sqrt{n} \cdot (\mu_0 - \mu_a)}{s}\Big) \end{aligned}

Both $$t_{\alpha/2, \nu}$$ and $$t_{1-\alpha/2, \nu}$$ have non-central T-distributions with non-centrality parameter $$\frac{\sqrt{n} (\mu_0 -\mu_a)}{s}$$.

One-Sided Test

For convenience, the power for only the upper tailed test is derived here.
Recall that the symmetry of the t-test allows us to use the decision rule: Reject $$H_0$$ when $$|T| \geq t_{1-\alpha}$$. Thus, where $$T$$ occurs in the derivation below, it may reasonably be replaced with $$|T|$$.

\begin{aligned} \gamma(\mu_a) &= P_{\mu_a}(\bar{x} \in C)\\ &= P_{\mu_a}\big(\bar{x} \geq \mu_0 + t_{1-\alpha, \nu} \cdot s / \sqrt{n}\big)\\ &= P_{\mu_a}\big(\bar{x} - \mu_a \geq \mu_0 - \mu_a + t_{1-\alpha, \nu} \cdot s / \sqrt{n}\big)\\ &= P_{\mu_a}\Big(\frac{\bar{x} - \mu_a}{s/\sqrt{n}} \geq \frac{\mu_0 - \mu_a + t_{1-\alpha, \nu} \cdot s / \sqrt{n}}{s / \sqrt{n}}\Big)\\ &= P_{\mu_a}\Big(T \geq \frac{\mu_0 - \mu_a}{s/\sqrt{n}} + t_{1-\alpha, \nu} \Big)\\ &= P_{\mu_a}\Big(T \geq t_{1-\alpha, \nu} + \frac{\mu_0 - \mu_a}{s/\sqrt{n}}\Big)\\ &= P_{\mu_a}\Big(T \geq t_{1-\alpha, \nu} + \frac{\sqrt{n} \cdot (\mu_0 -\mu_a)}{s}\Big) \end{aligned}

Where $$t_{1-\alpha, \nu} + \frac{\sqrt{n} (\mu_0 -\mu_a)}{s}$$ has a non-central t-distribution with non-centrality parameter $$\frac{\sqrt{n} (\mu_0 -\mu_a)}{s}$$

### 41.1.6 Confidence Interval

The confidence interval for $$\theta$$ is written: $\bar{x} \pm t_{1-\alpha/2} \cdot \frac{s}{\sqrt{n}}$

The value of the expression on the right is often referred to as the margin of error, and we will refer to this value as $E = t_{1-\alpha/2} \cdot \frac{s}{\sqrt{n}}$

## 41.2 Two-Sample T-test

The two sample t-test is commonly used to look for evidence that the mean of one normally distributed random variable may differ from that of another normally distributed random variable. The hypotheses for this test take the forms:

### 41.2.1 T-Statistic

The $$t$$-statistic is a standardize measure of the magnitude of difference between two sample means and some known, non-random difference of population means. It is similar to a two sample $$z$$-statistic, but differes in that a $$t$$-statistic may be calculated without knowledge of the population variances.

### 41.2.2 Definitions and Terminology

Let $$\bar{x_1}$$ and $$\bar{x_2}$$ be sample means from two independent samples with standard deviations $$s_1$$ and $$s_2$$. Let $$\mu_1$$ and $$\mu_2$$ be constants representing the means of the populations from which $$\bar{x_1}$$ and $$\bar{x_2}$$ obtained. $$t$$ is defined:

$t = \frac{(\bar{x_1} - \bar{x_2}) - (\mu_1 - \mu_2)}{SE^*}$

Where

$SE^* = \left\{ \begin{array}{rl} \sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}}, & \sigma_1^2 \neq \sigma_2^2 \\ \sqrt{\frac{(n_1-1) \cdot s_1^2 + (n_2-1) \cdot s_2^2} {n_1 + n_2 - 2}} \cdot \sqrt{\frac{1}{n_1} + \frac{1}{n_2}}, & \sigma_1^2 = \sigma_2^2 \end{array} \right.$

and the degrees of freedom $$\nu$$ are (by the Welch-Satterthwaite equation)

$\nu = \left\{ \begin{array}{rl} \frac{(\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2})^2} {\frac{s_1^2/n_1}{n_1 - 1} + \frac{s_2^2/n_2}{n_2 - 1}}, & \sigma_1^2 \neq \sigma_2^2 \\ n_1 + n_2 - 2, & \sigma_1^2 = \sigma_2^2 \end{array} \right.$

### 41.2.3 Hypotheses

For a two-sided test:

$H_0 : \mu_1 = \mu_2 \\ H_a : \mu_1 \neq \mu_2$

For a one-sided test:

$H_0 : \mu_1 \leq \mu_2 \\ H_a : \mu_1 > \mu_2$

or

$H_0 : \mu_1 \geq \mu_1 \\ H_a : \mu_1 < \mu_1$

### 41.2.4 Decision Rule

The decision to reject a null hypothesis is made when an observed T-value lies in a critical region that suggests the probability of that observation is low. We define the critical region as the upper bound we are willing to accept for $$\alpha$$, the Type I Error.

#### 41.2.4.1 Two Sided Test

In the two-sided test, $$\alpha$$ is shared equally in both tails. The rejection regions for the most common values of $$\alpha$$ are depicted in the figure below, with the sum of the shaded areas on both sides equally the corresponding $$\alpha$$. It follows then that the decision rule is:

Reject $$H_0$$ when $$T \leq t_{\alpha/2, \nu}$$ or when $$T \geq t_{1 - \alpha/2, \nu}$$.

By taking advantage of the symmetry of the T-distribution, we can simplify the decision rule to:

Reject $$H_0$$ when $$|T| \geq t_{1-\alpha/2, \nu}$$

## Warning: Ignoring unknown aesthetics: ymax

## Warning: Ignoring unknown aesthetics: ymax Figure 41.3: The example displayed uses 25 degrees of freedom

## 41.3 One Sided Test

In the one sided test, $$\alpha$$ is placed in only one tail. The rejection regions for the most common values of $$\alpha$$ are depicted in the figure below. In each case, $$\alpha$$ is the area in the tail of the figure. It follow, then, that the decision rule for a lower tailed test is:

Reject $$H_0$$ when $$T \leq t_{\alpha, \nu}$$.

For an upper tailed test, the decision rule is:

Reject $$H_0$$ when $$T \geq t_{1-\alpha, \nu}$$.

Using the symmetry of the $$T$$-distribution, we can simplify the decision rule as:

Reject $$H_0$$ when $$|T| \geq t_{1-\alpha, \nu}$$.

## Warning: Ignoring unknown aesthetics: ymax

## Warning: Ignoring unknown aesthetics: ymax Figure 41.4: The example displayed uses 25 degrees of freedom

The decision rule can also be written in terms of $$\bar{x_1}$$ and $$\bar{x_2}$$.

Reject $$H_0$$ when $$\bar{x_1} - \bar{x_2} \leq (\mu_1 - \mu_2) - t_{\alpha, \nu} \cdot SE^*$$ or $$\bar{x_1} - \bar{x_2} \geq (\mu_1 - \mu_2) + t_{\alpha, \nu} \cdot SE^*$$

This change can be justified by:

\begin{aligned} |T| & \geq t_{1 - \alpha, \nu} \\ \Big| \frac{(\bar{x_1} - \bar{x_2}) - (\mu_1 - \mu_2)}{SE^*} \Big | & \geq t_{1 - \alpha, \nu} \end{aligned}

\begin{aligned} -\Big(\frac{(\bar{x_1} - \bar{x_2}) - (\mu_1 - \mu_2)}{SE^*}\Big) & \geq t_{1-\alpha, \nu} & \Big(\frac{(\bar{x_1} - \bar{x_2}) - (\mu_1 - \mu_2)}{SE^*}\Big) & \geq t_{1-\alpha, \nu} \\ (\bar{x_1} - \bar{x_2}) - (\mu_1 - \mu_2) & \leq -t_{1 - \alpha, \nu} \cdot SE^* & (\bar{x_1} - \bar{x_2}) - (\mu_1 - \mu_2) &\geq t_{1 - \alpha, \nu} \cdot SE^* \\ \bar{x_1} - \bar{x_2} &\leq (\mu_1 - \mu_2) - t_{1-\alpha, \nu} \cdot SE^* & \bar{x_1} - \bar{x_2} &\leq (\mu_1 - \mu_2) + t_{1-\alpha, \nu} \cdot SE^* \end{aligned}

### 41.3.1 Power

Two Sided Test

\begin{aligned} \gamma(\mu_{1a} - \mu_{2a}) &= P_{\mu_{1a} - \mu_{2a}}(\bar{x} \in C)\\ &= P_{\mu_{1a} - \mu_{2a}}\big((\bar{x_1} - \bar{x_2}) \leq (\mu_1 - \mu_2) - t_{\alpha/2, \nu} \cdot SE^*\big) + \\ &\ \ \ \ P_{\mu_{1a} - \mu_{2a}}\big((\bar{x_1} - \bar{x_2} \geq (\mu_1 - \mu_2) + t_{1-\alpha/2, \nu} \cdot SE^*\big)\\ &= P_{\mu_{1a} - \mu_{2a}}\big((\bar{x_1} - \bar{x_2}) - (\mu_{1a} - \mu_{2a}) \leq (\mu_1 - \mu_2) - (\mu_{1a} - \mu_{2a}) - t_{\alpha/2, \nu} \cdot SE^*\big) + \\ &\ \ \ \ P_{\mu_{1a} - \mu_{2a}}\big((\bar{x_1} - \bar{x_2}) - (\mu_{1a} - \mu_{2a}) \geq (\mu_1 - \mu_2) - (\mu_{1a} - \mu_{2a}) + t_{1-\alpha/2, \nu} \cdot SE^*\big)\\ &= P_{\mu_{1a} - \mu_{2a}}\Big(\frac{(\bar{x_1} - \bar{x_2}) - (\mu_1 - \mu_2)}{SE^*} \leq \frac{(\mu_1 - \mu_2) - (\mu_{1a} - \mu_{2a}) - t_{\alpha/2, \nu} \cdot SE^*}{SE^*}\Big) + \\ &\ \ \ \ P_{\mu_{1a} - \mu_{2a}}\Big(\frac{(\bar{x_1} - \bar{x_2}) - (\mu_{1a} - \mu_{2a})}{SE^*} \geq \frac{(\mu_1 - \mu_2) - (\mu_{1a} - \mu_{2a}) + t_{1-\alpha/2, \nu} \cdot SE^*}{SE^*}\Big)\\ &= P_{\mu_{1a} - \mu_{2a}}\Big(T \leq \frac{(\mu_1 - \mu_2) - (\mu_{1a} - \mu_{2a})}{SE^*} - t_{\alpha/2, \nu}\Big) + \\ &\ \ \ \ P_{\mu_{1a} - \mu_{2a}}\Big(T \geq \frac{(\mu_1 - \mu_2) - (\mu_{1a} - \mu_{2a})}{SE^*} + t_{1-\alpha/2, \nu}\Big)\\ &= P_{\mu_{1a} - \mu_{2a}}\Big(T \leq -t_{\alpha/2, \nu} + \frac{(\mu_1 - \mu_2) - (\mu_{1a} - \mu_{2a})}{SE^*}\Big) + \\ &\ \ \ \ P_{\mu_{1a} - \mu_{2a}}\Big(T \geq t_{1-\alpha/2, \nu} + \frac{(\mu_1 - \mu_2) - (\mu_{1a} - \mu_{2a})}{SE^*}\Big) \end{aligned}

Both $$-t_{\alpha/2, \nu} + \frac{(\mu_1 - \mu_2) - (\mu_{1a} - \mu_{2a})}{SE^*}$$ and $$t_{1-\alpha/2, \nu} + \frac{(\mu_1 - \mu_2) - (\mu_{1a} - \mu_{2a})}{SE^*}$$ have non-central T-distributions with non-centrality parameter $$\frac{(\mu_1 - \mu_2) - (\mu_{1a} - \mu_{2a})}{SE^*}$$.

One Sided Test

For convenience, the power for only the upper tailed test is derived here.
Recall that the symmetry of the t-test allows us to use the decision rule: Reject $$H_0$$ when $$|T| \geq t_{1-\alpha}$$. Thus, where $$T$$ occurs in the derivation below, it may reasonably be replaced with $$|T|$$.

\begin{aligned} \gamma(\mu_{1a} - \mu_{2a}) &= P_{\mu_{1a} - \mu_{2a}}(\bar{x} \in C)\\ &= P_{\mu_{1a} - \mu_{2a}}\big((\bar{x_1} - \bar{x_2} \geq (\mu_1 - \mu_2) + t_{1-\alpha, \nu} \cdot SE^*\big)\\ &= P_{\mu_{1a} - \mu_{2a}}\big((\bar{x_1} - \bar{x_2}) - (\mu_{1a} - \mu_{2a}) \geq (\mu_1 - \mu_2) - (\mu_{1a} - \mu_{2a}) + t_{1-\alpha, \nu} \cdot SE^*\big)\\ &= P_{\mu_{1a} - \mu_{2a}}\Big(\frac{(\bar{x_1} - \bar{x_2}) - (\mu_{1a} - \mu_{2a})}{SE^*} \geq \frac{(\mu_1 - \mu_2) - (\mu_{1a} - \mu_{2a}) + t_{1-\alpha, \nu} \cdot SE^*}{SE^*}\Big)\\ &= P_{\mu_{1a} - \mu_{2a}}\Big(T \geq \frac{(\mu_1 - \mu_2) - (\mu_{1a} - \mu_{2a})}{SE^*} + t_{1-\alpha, \nu}\Big)\\ &= P_{\mu_{1a} - \mu_{2a}}\Big(T \geq t_{1-\alpha, \nu} + \frac{(\mu_1 - \mu_2) - (\mu_{1a} - \mu_{2a})}{SE^*}\Big) \end{aligned}

$$t_{1-\alpha/2, \nu} + \frac{(\mu_1 - \mu_2) - (\mu_{1a} - \mu_{2a})}{SE^*}$$ has a non-central T-distribution with non-centrality parameter $$\frac{(\mu_1 - \mu_2) - (\mu_{1a} - \mu_{2a})}{SE^*}$$.

### 41.3.2 Confidence Interval

The confidence interval for $$\mu_1 - \mu_2$$ is written: $(\bar{x_1} - \bar{x_2}) \pm t_{1-\alpha/2} \cdot SE^*$

The value of the expression on the right is often referred to as the margin of error, and we will refer to this value as $E = t_{1-\alpha/2} \cdot SE^*$

## 41.4 References

1. Wackerly, Mendenhall, Scheaffer, Mathematical Statistics with Applications, 6th ed., Duxbury, 2002, ISBN 0-534-37741-6.
2. Daniel, Biostatistics, 8th ed., John Wiley & Sons, Inc., 2005, ISBN: 0-471-45654-3.
3. Hogg, McKean, Craig, Introduction to Mathematical Statistics, 6th ed., Pearson, 2005, ISBN: 0-13-008507-3
4. Wikipedia, “Student’s T test”, https://en.wikipedia.org/wiki/Student%27s_t-test
5. Wikipedia, “Welch-Satterthwaite Equation”, https://en.wikipedia.org/wiki/Welch%E2%80%93Satterthwaite_equation