Statistical Hypothesis Testing with SAS and R

by Dirk Taeger and Sonja Kuhnt

(c) John Wiley & Sons, Ltd

Test 2.2.5: Paired t-test

Description:

Tests if the difference of two population means \(\mu_d = \mu_1 - \mu_2\) differ from a value \(d_0\) in the case that observations are collected in pairs.

Assumptions:

Hypotheses:

  1. \(H_0\) : \(\mu_d = d_0\) vs \(H_1\) : \(\mu_d \neq d_0\).
  2. \(H_0\) : \(\mu_d \le d_0\) vs \(H_1\) : \(\mu_d \gt d_0\).
  3. \(H_0\) : \(\mu_d \ge d_0\) vs \(H_1\) : \(\mu_d \lt d_0\).

Test statistic:

\[T = \frac{\bar{D} - d_0}{\sigma_d}\sqrt{S_d}\] with \[S_d = \sqrt{\frac{1}{n-1}\sum_{i=1}^n (D_i - \bar{D})^2}\]

\[\bar{D} = \frac{1}{n}\sum_{i=1}^n D_i\] and \(D_i = X_{1i} - X_{2i}\), \(i = 1,...,n\)

Test decision:

Rejection \(H_0\) if for the observed value t of T:

  1. \(t \lt t_{\alpha/2, n-1}\) or \(t \gt t_{1-\alpha/2, n-1}\)

  2. \(t \gt t_{1-\alpha, n-1}\)

  3. \(t \lt t_{\alpha,n-1}\)

P-value:

  1. \(\rho = 2P(T \le (-|t|))\)

  2. \(\rho = 1 - P(T \le t)\)

  3. \(\rho = P(T \le t)\)

Annotation:

Example

To test if the mean intelligence quotient increases by 10 comparing before training (IQ1) and after training (IQ2). Note: Because we are interested in a negative difference of means of \(IQ1 - IQ2\), we must test against \(d_0 = -10\)

#iq dataset
no <- seq(1:20)
IQ1 <- c(127, 98,105,83,133,90,107,98,91,100,88,96,110,87,88,88,105,95,79,106)
IQ2 <- c(137, 108,115,93,143,100,117,108,101,110,98,106,120,97,98,100,115,111,89,116)
iq <-data.frame(no,IQ1, IQ2)
t.test(iq$IQ1,iq$IQ2,mu=-10,alternative="two.sided",paired=TRUE)
## 
##  Paired t-test
## 
## data:  iq$IQ1 and iq$IQ2
## t = -1.2854, df = 19, p-value = 0.2141
## alternative hypothesis: true difference in means is not equal to -10
## 95 percent confidence interval:
##  -11.051338  -9.748662
## sample estimates:
## mean of the differences 
##                   -10.4

Remarks:

  • The command \(paired=TRUE\) forces R to calculate the paired t-test.
  • \(mu=value\) is optional and defines the value \(mu_0\) to test against. Default is 0.
  • \(alternative="value"\) is optional and defines the type of alternative hypothesis: “two.sided”= two sided (A); “greater”=true mean difference is greater (B); “less”=true mean difference is lower (C). Default is “two.sided”.

Noted: Sang Nguyen
Nashville,TN - NOV 2016