First invented by William Gossett when he worked for the Guiness Brewery, the 2-sample t-test compares the sample means of a continuous response variable (Y) measured for two different values of a categorical predictor variable (X, e.g., treatment vs. control, young vs. old, before vs. after treatment). In R, it can be implemented using the t.test() function.
As an example, let’s consider data from Potvin, Lechowicz, and Tardif (1990) on CO2 uptake by the grass Echinochloa crus-galli. In this experiment on cold tolerance, the plants were either experimentally chilled or left unchilled during the night before the gas-exchange measurements were taken.
require(mosaic) # be sure to install and load the usual packages if you have not already
require(lattice)
require(datasets)
data(CO2)
You can find out more about the data using help() and once the data are loaded you can click on the data frame to view the actual dataset in the data window.
help(CO2)
It is always helpful to look at a plot and summary of the data first. In this case we can use a boxplot to see the distribution of uptake values for the two treatments. We can also use favstats() to see a comprehensive summary of the data.
bwplot(uptake~Treatment, data=CO2, xlab="Treatment", ylab=expression(paste(CO[2], " uptake (", mu,"mol ", m^-2, " ", s^-1,")"))) #sorry the y-label is a bit complicated, units sometimes require mathematical expressions...
favstats(uptake~Treatment, data=CO2)
## .group min Q1 median Q3 max mean sd n missing
## 1 nonchilled 10.6 26.47 31.3 38.7 45.5 30.64 9.705 42 0
## 2 chilled 7.7 14.53 19.7 34.9 42.4 23.78 10.884 42 0
From the summary and the boxplot, we can see that the rate of CO2 uptake appears to be higher (on average) in unchilled plants, but there is still quite a bit of overlap between the two treatments. We can now perform the t-test to make a more quantitative inference:
t.test(uptake~Treatment, data=CO2) # note the similarity of the model and plotting statements
##
## Welch Two Sample t-test
##
## data: uptake by Treatment
## t = 3.049, df = 80.94, p-value = 0.003107
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## 2.382 11.337
## sample estimates:
## mean in group nonchilled mean in group chilled
## 30.64 23.78
Like most statistical tests, the t-test is based on a test statistic, t, with a known probability distribution. The larger the magnitude of the test statistic, the less likely it is that the observed difference has simply occurred by chance. The t distribution is centered on zero, so the value observed here t = 3.05 is moderately big. The p-value, technically, is the probability of observing a difference that is at least this large as the measured difference between the means if plants had the same distribution of uptake rates, regardless of the treatment. Since our 95% confidence interval for the difference in uptake rates between chilled and unchilled plants (2.4 - 11.3) does not include zero, it is not too surprising that our p-value is quite small. Thus, there is very little chance that the observed difference has simply occurred “by chance”.
So, we can comfortably conclude that plants exhibit slower CO2 uptake rates when they are chilled the night before.