Chapter 4 Paired Procedures
Sometimes we get two measurements on a subject under different circumstances, or perhaps we treat every experimental unit with two different treatments and get the responses for the two treatments for each unit. These data are paired, because we expect that the two responses for the same subject or unit to both be high or both be low. They are correlated with each other because they share some aspect of the subject or unit that causes the responses to be similar.
When working with paired data you should take that correlation into account. (If you treat the data as unpaired, you get a very inefficient analysis. For example, you confidence intervals will typically be much wider than necessary.) Generally speaking, this can be done by taking the difference between the two measurements for each subject or unit and then doing your analysis on the differences. Because the mean of the differences is the same as the difference of the means, you get inference about the same thing: the difference of means under the two conditions.
Will will demonstrate using the data from the RunStitch
example
in cfcdae
. Each worker run stitches collars using two different
setups: the conventional setup and an ergonomic setup. The two
runs are made in random order for each worker, and the interest
is in any difference in average speed between the two setups.
Load the runstitch data from the package and look at the first few values.
data(RunStitch)
head(RunStitch)
Standard Ergonomic
1 4.90 3.87
2 4.50 4.54
3 4.86 4.60
4 5.57 5.27
5 4.62 5.59
6 4.65 4.61
The columns are named Standard and Ergonomic. The most obvious way to work with these data is to compute differences and then work with the differences Standard minus Ergonomic.
<- RunStitch[,"Standard"]-RunStitch[,"Ergonomic"]
differences head(differences)
[1] 1.03 -0.04 0.26 0.30 -0.97 0.04
It’s almost always a good idea to begin with simple summary statistics. Data lean somewhat toward positive differences
summary(differences)
Min. 1st Qu. Median Mean 3rd Qu. Max.
-1.0800 -0.2025 0.2550 0.1753 0.4450 1.7500
stem(differences)
The decimal point is at the |
-1 | 10
-0 | 86655
-0 | 220
0 | 002233334444
0 | 5678
1 | 001
1 | 8
hist(differences,freq=FALSE)

Figure 4.1: Histogram of runstitch differences
4.1 Paired T Test
The paired t-test (confidence interval) just does a one-sample test (confidence interval) on the differences. There is little evidence of difference.
t.test(differences)
One Sample t-test
data: differences
t = 1.49, df = 29, p-value = 0.147
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-0.06532811 0.41599478
sample estimates:
mean of x
0.1753333
Should this be a one or two-sided alternative? That is a good question without an obvious answer. I could hypothesize that the employees will be faster with the standard because they are used to it, or I could hypothesize that they will be faster with the ergonomic, because it’s just better. I don’t know which is reasonable, so it is probably best to use a two-sided alternative that will check for either.
You
can also do the paired test using the two sets of responses but setting
paired=TRUE
. Results are the same as above.
t.test(RunStitch$Standard,RunStitch$Ergonomic,paired=TRUE)
Paired t-test
data: RunStitch$Standard and RunStitch$Ergonomic
t = 1.49, df = 29, p-value = 0.147
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-0.06532811 0.41599478
sample estimates:
mean of the differences
0.1753333
Finally, you can choose a null mean other than 0.
t.test(differences,mu=.5)
One Sample t-test
data: differences
t = -2.7591, df = 29, p-value = 0.009934
alternative hypothesis: true mean is not equal to 0.5
95 percent confidence interval:
-0.06532811 0.41599478
sample estimates:
mean of x
0.1753333
4.2 Randomization (permutation) Paired T Test
permsign.test()
does the randomization
version of the paired t. The randomization null hypothesis is
that the grouping is irrelevant, implying that either the positive
or negative version of the difference could have occurred with
equal probability. We simulate from this
null distribution by randomly changing signs of the differences
and looking at the distribution of the resulting means.
The main advantage of this procedure over the t test is that the permutation test does not assume or depend on normality.
The p-values are computed by a simulation, so they will vary a bit if you repeat the command. We note that they are close to the t-test in this case.
The histogram plots all of the randomization outcomes, and the red line on the plot is at the observed value.
permsign.test(differences,plot=TRUE)

Figure 4.2: Histogram of pairwise randomization outcomes
Permutation Sign Test for differences
Null hypothesis mean value: 0
Lower tail p-value 0.9216
Upper tail p-value 0.0785
Two tail p-value 0.157
95% confidence interval: -0.06067, 0.4113
There is also a version of permsign.test()
that will save
you the toil of computing the differences, along with
the possibility of using a data frame source.
permsign.test(Standard,Ergonomic,plot=FALSE,data=RunStitch)
Permutation Sign Test for Standard - Ergonomic
Null hypothesis mean value: 0
Lower tail p-value 0.9303
Upper tail p-value 0.07
Two tail p-value 0.14
95% confidence interval: -0.05467, 0.4053