Lesson 10—Matched-Pairs t tests


First published on April 20, 2019

Learning Objectives

Perform a matched-pair hypothesis t test



Here is the dataset that we are using in this demo from #17.16 in our textbook:



Goal: To conduct a two-sided t test of no difference for a matched-pair t test


Here are the null and alternative hypotheses in this example:

\(H_0: \mu_1 = \mu_2 \)

\(H_a: \mu_1 \neq \mu_2 \)


\( \mu_1 \) = population mean angle in squatting

\( \mu_2 \)= population mean angle in sitting


Here are the steps:

Step 1: Import the dataset

Step 2: Create a column of difference

w = sitting_squatting$Sitting - sitting_squatting$Squatting

DO NOT use name your column of difference as diff  because diff is a built-in function in R.

In this demonstration, we name our column of difference w.


Step 3: Draw a stemplot to check data

Draw a stemplot on the column of difference to check if data are roughly symmetric and without too many extreme outliers:



Step 3: Run the matched-pair t test via the R function t.test

t.test(sitting_squatting$Sitting, sitting_squatting$Squatting, 
               mu=0, paired=TRUE, 
               conf.level = 0.95)


Whenever R runs a hypothesis test, R automatically calculates the corresponding confidence interval —the range of values which the population mean is estimated to lie within.

Given a set of data, the corresponding hypothesis test result and the confidence interval are closely related. Therefore if we want the significance level \(\alpha \) to be 0.05, then we set the argument conf.level = 0.95  because  conf.level = 1 – \(\alpha \) .

By default, R automatically sets \(\mu = 0 \) and conf.level = 0.95 even if you don’t explicitly type these arguments. So you can skip typing these arguments into the t.test function if you are testing a two-sided alternative hypothesis with  \(\alpha =0.05\).




Content is copyright the author. Layout is copyright Corsbook. See for further notices.