The basics

The normal distribution, as awesome as it is, requires that we work with large sample sizes.

The \(t\)-distribution is similar but better suited to small sample sizes.

Just as with the normal distribution, there’s not just one \(t\)-distribution but, rather, a family of distributions.

Just as there’s a formula for the normal distribution, there’s a formula for the \(t\)-distribution. It’s a bit more complicated, though.

Like all continuous distributions, we compute probabilities with the \(t\)-distribution by computing the area under a curve. We do so using either a computer or a table.

The degree to which the \(t\)-distribution is “spread out” is determined by the “degrees of freedom” parameter \(df\). Generally, the degrees of freedom is one less than the sample size.

The mean of the \(t\)-distribution is zero and its variance is related to the degrees of freedom \(df\) by \[\sigma^2 = \frac{df}{df-2}.\]

Unlike the normal distribution, there’s no easy way to translate from a \(t\)-distribution with one standard deviation to another standard one. As a result, it’s less common to use tables than it is with the normal.

Given a particular number of degrees of freedom, however, there is a standard way to derive a \(t\)-score that’s analagous to the \(z\)-score for the normal distribution.

The \(t\)-test for one sample mean

In statistics, our main use of the \(t\)-distribution is in hypothesis testing. The main tool for this is the so called \(t\)-test. The \(t\)-test is to the \(t\)-distribution as the \(p\)-test is to the normal distribution. The \(t\)-test a little tricky due to the lack of a “standard” version of the \(t\)-distribution. R has a built command to automate the procedure, though.

Given a relatively small sample, the one sample mean \(t\)-test finds a 95% confidence interval for the population mean based on the sample.

Example

The following data set mimics data presented in our text measuring the average mercury content in dolphin muscle of 19 Risso’s dolphins from the Taiji area in Japan:

d = c(2.57,4.43,2.09,7.68,4.77,2.12,5.13,5.71,5.33,3.31,7.49,4.91,2.58,-1.08,6.60,3.91,3.97,6.18,5.90)

Here’s how we apply the \(t\)-test to the data in R.

t.test(d, mu=3.6)
## 
##  One Sample t-test
## 
## data:  d
## t = 1.6247, df = 18, p-value = 0.1216
## alternative hypothesis: true mean is not equal to 3.6
## 95 percent confidence interval:
##  3.365534 5.434466
## sample estimates:
## mean of x 
##       4.4

There’s quite a bit going on here that we need to parse. First, there’s the command itself:

t.test(d, mu=3.6)

I guess it’s pretty clear that we’re applying t.test to our data set d. The mu=3.6 option is used to specify an assumed null-value that we are comparing the data against. Thus, in the ouput we see the lines:

## t = 1.6247, df = 18, p-value = 0.1216
## alternative hypothesis: true mean is not equal to 3.6

Note that the value of \(3.6\) appears in the statement of the alternative hypothesis; the associated \(p\)-value for the alternative hypotesis is, evidentally, \(0.1216\). Thus, we can’t reject the null hypothesis that the true mean is \(3.6\), even though the measured mean was \(4.4\), as we see in the last line of the output.

The computation of the \(p\)-value is based on the \(t\)-score in much the same way that the \(p\)-value for the normal distribution is based on the \(z\)-score. In the output above, the \(t\)-score is indicated the t = 1.6247 in the output.

Finally, the \(95\%\) confidence interval is just what you’d probably think - we have a \(95\%\) level of confidence that the interval contains the actual mean.

Using the distribution itself

Direct use of the t.test command is generally the ideal way to use the \(t\)-distribution. However, we should be able to gain a deeper understanding of the \(t\)-test and it’s relationship to the normal distribution by using the fundamental distribution functions pt and qt.

pt

The cummulative probability distribution function for the \(t\)-distribution

Given a random variable \(X\) with a \(t\)-distribution with df degrees of freedom and a real number \(x\), pt(x,df) computes the area under the graph from \(-\infty\) to \(x\). In the picture below, \(df=18\) and \(x=-1\).

For example, the following command computes the probability that a random variable \(X\) generated by the \(t\) distribution with \(18\) degrees of freedom is less than \(-1\):

pt(-1,18)
## [1] 0.1652825

This is illustrated by the following picture:

qt

The quantiles for the \(t\)-distribution

This is an inverse to pt. Thus, given a probability \(p\) and some number \(df\) of degrees of freedom, qt(p,df) computes the real number \(x\) such that pt(x,df) produces that probability \(p\). Symbolically, \[\texttt{pt}(\texttt{qt}(p,df),df) = p.\] Reffering again to the picture above, we saw that \(\texttt{pt}(-1,18)=0.165\); thus, we should have \(\texttt{qt}(0.165,18)=-1\) (or maybe just close due to round off):

qt(0.165,18)
## [1] -1.001201

The interpretation is that just over \(16.5\%\) of the population lies below \(x=-1\) in this \(t\)-distribution.

The \(t\)-score and the \(p\)-value

The \(t\)-score for a \(t\)-distribution is computed in much the same way that a \(z\)-score is computed for a normal distribution. That is, given a sample of size \(n\), with mean \(\bar{x}\), and standard deviation \(s\) the \(t\)-score of the observation \(x\) is \[T = \frac{x-\bar{x}}{s/\sqrt{n}}.\] In our dolphin example above, the assumed mean is \(3.6\) and the observed mean is \(4.4\). We can compute the standard error easily enough:

n = length(d)
se = sd(d)/sqrt(n)
se
## [1] 0.4923865

Thus, the \(t\)-score is

t_score = (4.4-3.6)/se
t_score
## [1] 1.62474

In aggreement with the first line from our application of t.test.

The \(p\)-value is then computed from the \(t\)-score in the same way that the normal \(p\)-value is computed from the \(z\)-score. In this case, we have an observation of the mean that is larger than the assumed mean. Thus, the probability that the mean might be this large or larger, assuming the null value is

1 - pt(t_score, 18)
## [1] 0.0607995

Of course, the alternative hypothesis, as stated by the output of t.test is that the true mean is unequal to 3.6; thus, we should double this number to obtain the result in that output.

Computing confidence intervals

Center zero

A \(95\%\) confidence interval for a \(t\)-distribution looks like so:

Note that the gray portions must contain \(5\%\) of the area under the curve. As a result, the endpoints of the interval can be computed as follows:

c(qt(0.025, 18), qt(0.975,18))
## [1] -2.100922  2.100922

Of course, you should adjust the 18 to whatever value of \(df\) you need.

Note that we can also find that \(t^*=2.1\) in the \(t\)-table in appendix B of our textbook, where we see something that looks like so:

one tail 0.100 0.050 0.025 0.010 0.005
two tails 0.200 0.100 0.050 0.020 0.010
df 1 3.08 6.31 12.71 31.82 63.66
2 1.89 2.92 4.30 6.96 9.92
18 1.33 1.73 2.10 2.55 2.88

The entries in this table are called critical \(t^*\) values. The columns indicate several common choices for confidence level and are alternately labeled either one-sided or two. The rows correspond to degrees of freedom. Now, look in the row where \(df=18\) and where the two-sided test is equal to 0.05. we see that \(t^*=2.1\).

Shifted and scaled

In our dolphin example, the data is not centered at zero and it’s standard deviation is not \(18/16\). To compute a confidence interval, we simply shift and scale the centered one. This is pretty much the inverse operation of computing a \(z\)-score.

base = c(qt(0.025,18), qt(0.975,18))
m = mean(d)
n = length(d)
s = sd(d)/sqrt(n)
base*s + m
## [1] 3.365534 5.434466

Again, in agreement of the results of t.test.

Examples

Chips Ahoy!

In 1998, Nabisco announced its 1000 chip challenge, claiming that every bag of Chips Ahoy cookies contained at least 1000 chips. A group of students counted the chips in 12 cookies and found the following data

chips = c(1219,1214,1087,1200,1419,1121,1325,1345,1244,1258,1356,1132,1191,1270,1295,1135)
  • Create a \(99\%\) confidence interval for the number of chips in the bag.
  • What is the \(p\)-value that the average number of chips is larger than 1000?

Solution: We’ll just use the t.test.

For the first part a simple call to t.test with the conf.level parameter set to \(0.99\) should do it.

t.test(chips, conf.level=0.99)
## 
##  One Sample t-test
## 
## data:  chips
## t = 52.531, df = 15, p-value < 2.2e-16
## alternative hypothesis: true mean is not equal to 0
## 99 percent confidence interval:
##  1168.732 1307.643
## sample estimates:
## mean of x 
##  1238.188

For the second part, we’ll also need to set alternative hypotheses and null value:

t.test(chips, conf.level=0.99, alternative = "greater", mu=1000)
## 
##  One Sample t-test
## 
## data:  chips
## t = 10.105, df = 15, p-value = 2.176e-08
## alternative hypothesis: true mean is greater than 1000
## 99 percent confidence interval:
##  1176.846      Inf
## sample estimates:
## mean of x 
##  1238.188