We are going to work with the data in Table 1 from Section 11.2.

First, install the Mosaic package, if necessary.

install.packages("mosaic")

Read the data from Table 1 into R.

Table1 <- read.csv("https://sullystats.github.io/Statistics6e/Data/Chapter11/Table1.csv")
head(Table1,n=3)
##   Dominant Nondominant
## 1    0.177       0.179
## 2    0.210       0.202
## 3    0.186       0.208

Testing Hypotheses Regarding Matched-Pairs Data

We are going to follow Example 1 from Section 11.1. In this problem, we want to know if reaction time in a student’s dominant hand is less than the reaction time in the same student’s nondominant hand. This is matched-pairs data. If we compute the difference in the data as “Dominant - Nondominant”, then we would expect this difference to be negative (assuming reaction time in the dominant hand is lower). Therefore, we are testing

\(H_0:\mu_d = 0\)
\(H_1:\mu_d < 0\)

The syntax for the test is

t.test(~(x - y),data=data frame,mu=0,alternative = less or greater or two.sided)

library(mosaic)
t.test(~(Dominant-Nondominant),data=Table1,mu=0,alternative="less")
## 
##  One Sample t-test
## 
## data:  (Dominant - Nondominant)
## t = -2.7759, df = 11, p-value = 0.009017
## alternative hypothesis: true mean is less than 0
## 95 percent confidence interval:
##          -Inf -0.004648515
## sample estimates:
##   mean of x 
## -0.01316667

The test statistic is \(t_0 = -2.7759\). The P-value for the test is 0.009.

Constructing Confidence Intervals Regarding Matched-Pairs Data

Use the confint command with the t.test command in the Mosaic library. Adjust the level of confidence as desired.

confint(t.test(~(Dominant-Nondominant),data=Table1),conf.level=0.95)
##     mean of x       lower        upper level
## 1 -0.01316667 -0.02360627 -0.002727063  0.95

The lower bound of the confidence interval is -0.024 and the upper bound is -0.003.

Note Try computing the interval as “Nondominant - Dominant”. What do you notice?

Descriptive Statistics from Matched-Pairs Data

To get any descriptive statistics for matched-pairs data, first use the transform command to obtain the differences and store the result in a new data frame. Call the new variable differences.

Table1_diff <- transform(Table1,difference=Dominant-Nondominant)
head(Table1_diff)
##   Dominant Nondominant difference
## 1    0.177       0.179     -0.002
## 2    0.210       0.202      0.008
## 3    0.186       0.208     -0.022
## 4    0.189       0.184      0.005
## 5    0.198       0.215     -0.017
## 6    0.194       0.193      0.001
favstats(~difference,data=Table1_diff)
##     min       Q1  median     Q3   max        mean         sd  n missing
##  -0.043 -0.02275 -0.0145 0.0015 0.008 -0.01316667 0.01643075 12       0
bwplot(~difference,data=Table1_diff,horizontal=TRUE,main="Difference in Reaction Time",fill="#6897bb")