www.seeingstatistics.com

Student's t-test for unpaired or independent groups

The appropriate statistical test is the unpaired or independent or two-group Student t-test. Also appropriate is the one-way analysis of variance (ANOVA) for between-cases. The difference between the means of the two groups are compared against the estimated standard error of the mean difference. That is,

formula for independent groups t-test

where



The calculated value of Student's t is compared to the t-distribution with degrees of freedom equal to 2(n-1) when there are n observations in each group.

Example

In a study of pain mechanisms, behavioral neuroscientists injected a group of rats with a drug that would increase pain sensitivity if a certain neural pathway was involved in pain. Pain sensitivity was measured by the time (in seconds) it took for the rat to flick its tail away from a heat lamp. Longer times until tail flick indicate less pain sensitivity. Testing was always stopped after ten seconds before there could be any injury to the rats. Data from the injected group were compared to a placebo group in which rats received inert injections. Below are the data for fourteen rats, seven in each group:

Placebo:   2.6   10   9.5   7.4   6.9   8.5   5.2

Drug:   2.2   3.8   7.1   2.7   6.2   5.3   3.1

The neuroscientists want to know whether the drug increased pain sensitivity. If the drug had absolutely no effect, then we would expect the mean tail flick time in the placebo group to be the same as the mean tail flick time in the drug group.

Summary

In a study of pain sensitivity, rats injected with a drug believed to increase pain sensitivity flicked their tails away from a heat source in 4.3 seconds, on average; rats injected with a placebo flicked their tails away in 7.2 seconds, on average. The mean difference of 2.8 seconds is statistically significant (t(12) = 2.33, p = .038). Thus, the drug indeed increased pain sensitivity.


Computer Examples

R

Method 1

Use one variable for the independent variable and another for the dependent variable. The alternative in Method 2 uses separate variables for values of the dependent variable for each group.

> flick <- c(2.6,10,9.5,7.4,6.9,8.5,5.2,2.2,3.8,7.1,2.7,6.2,5.3,3.1)
> group <- factor(c(rep("placebo",7),rep("drug",7)))

> t.test(flick ~ group, var.equal=T)

	Two Sample t-test

data:  flick by group 
t = -2.3315, df = 12, p-value = 0.03797
alternative hypothesis: true difference in means is not equal to 0 
95 percent confidence interval:
 -5.4442552 -0.1843162 
sample estimates:
   mean in group drug mean in group placebo 
             4.342857              7.157143 
             
#tapply is useful for obtaining group statistics.  it 'applies' a function to a variable
# to each subgroup defined by a factor.  the syntax is:
#      tapply(variable, factor, function)
> tapply(flick, group, mean)
    drug  placebo 
4.342857 7.157143 
> tapply(flick, group, sd)
    drug  placebo 
1.875151 2.585122 

Method 2

> placebo <- c(2.6,10,9.5,7.4,6.9,8.5,5.2)
> drug <- c(2.2,3.8,7.1,2.7,6.2,5.3,3.1)
> t.test(placebo,drug,var.equal=TRUE)

	Two Sample t-test

data:  placebo and drug 
t = 2.3315, df = 12, p-value = 0.03797
alternative hypothesis: true difference in means is not equal to 0 
95 percent confidence interval:
 0.1843162 5.4442552 
sample estimates:
mean of x mean of y 
 7.157143  4.342857 


> boxplot(placebo,drug,ylab='Tail flick (seconds)',col=c('red','blue'),
+ names=c('Placebo','Drug'))
Boxplot comparing placebo and drug groups
#ADVANCED: checking the normality assumption
> res <- c(placebo-mean(placebo), drug - mean(drug))
> qqline(res)
> qqline(res, col='blue',lwd=2)
quantile-quantile plot for model residuals

Statview

Prepare a dataset like this one:

dataset for two-group t-test for StatView

Menu: Analyze > ANOVA and t-tests > t-test (Unpaired)

two-group t-test for tail flick data from StatView

Jmp

two-group t-test for tail flick data

Minitab

MTB > TwoSample 95.0 'control' 'drug'; SUBC> Alternative 0. Two Sample T-Test and Confidence Interval Twosample T for control vs drug N Mean StDev SE Mean control 7 7.16 2.59 0.98 drug 7 4.34 1.88 0.71 95% C.I. for mu control - mu drug: ( 0.12, 5.50) T-Test mu control = mu drug (vs not =): T= 2.33 P=0.038 DF= 12

Excel

two-group t-test for tail flick data from Excel

Note: In contrast to the other computer programs above, Excel reports variances instead of standard deviations.



© 2002, Gary McClelland