Statistical Hypothesis Testing with SAS and R

by Dirk Taeger and Sonja Kuhnt

(c) John Wiley & Sons, Ltd

Test 2.2.2: Two-sample pooled t-Test

Description:

Tests if two population means \(\mu_1\) and \(\mu_2\) differ less than, more than or by a value \(d_0\).

Assumptions:

Hypotheses:

  1. \(H_0\) : \(\mu_1 - \mu_2 = d_0\) vs \(H_1\) : \(\mu_1 - \mu_2 \neq d_0\).
  2. \(H_0\) : \(\mu_1 - \mu_2 \le d_0\) vs \(H_1\) : \(\mu_1 - \mu_2 \gt d_0\).
  3. \(H_0\) : \(\mu_1 - \mu2 \ge d_0\) vs \(H_1\) : \(\mu_1 - \mu_2 \lt d_0\).

Test statistic:

\[T = \frac{(\bar{X_1} - \bar{X_2}) - d_0}{\left[S_p\sqrt{\frac{1}{n_1} + \frac{1}{n_2}}\right]}\] with \[S_p = \sqrt{\frac{(n_1 - 1)s_1{^2} + (n_2 - 1)s_2^{2}}{n_1 + n_2-1}}\]

where \[S_j = \sqrt{\frac{1}{n_j-1}\sum_{i=1}^n (X_j - \bar{X_j})^2}\]

for \(j= 1,2\)

Test decision:

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

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

  2. \(t \gt t_{1-\alpha, n_1 + n_2-2}\)

  3. \(t \lt t_{\alpha,n_1 + n_2 -2}\)

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 the hypothesis that the mean systolic boold pressures of healthy subjects (status=0) and subjects with hypertention (status=1) are equal, hence \(d_0 = 0\). The dataset contains \(n_1 = 25\) subjects with status 0 and \(n_2 = 30\) with status 1.

#Blood_pressure dataset
no <- seq(1:55)
status <- c(rep(0, 25), rep(1, 30))
mmhg <- c(120,115,94,118,111,102,102,131,104,107,115,139,115,113,114,105,
          115,134,109,109,93,118,109,106,125,150,142,119,127,141,149,144,
          142,149,161,143,140,148,149,141,146,159,152,135,134,161,130,125,
          141,148,153,145,137,147,169)
blood_pressure <-data.frame(no,status,mmhg)
status0<-blood_pressure$mmhg[blood_pressure$status==0]
status1<-blood_pressure$mmhg[blood_pressure$status==1]

t.test(status0,status1,mu=0,alternative="two.sided",var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  status0 and status1
## t = -10.468, df = 53, p-value = 1.66e-14
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -37.31328 -25.31339
## sample estimates:
## mean of x mean of y 
##  112.9200  144.2333
t.test(status0,status1,mu=0,alternative="less",var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  status0 and status1
## t = -10.468, df = 53, p-value = 8.298e-15
## alternative hypothesis: true difference in means is less than 0
## 95 percent confidence interval:
##       -Inf -26.30542
## sample estimates:
## mean of x mean of y 
##  112.9200  144.2333
t.test(status0,status1,mu=0,alternative="great",var.equal=TRUE)
## 
##  Two Sample t-test
## 
## data:  status0 and status1
## t = -10.468, df = 53, p-value = 1
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
##  -36.32125       Inf
## sample estimates:
## mean of x mean of y 
##  112.9200  144.2333

Remarks:

  • \(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