Statistical Hypothesis Testing with SAS and R

by Dirk Taeger and Sonja Kuhnt

(c) John Wiley & Sons, Ltd

Test 2.1.1: One-sample z-test

Description:

Tests if a promotion mean \(\mu\) differ from a specific value \(\mu_0\).

Assumptions:

Hypotheses:

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

Test statistic:

\[Z = \frac{\bar{X} - \mu_0}{\sigma}\sqrt{n}\] with \[\bar{X} = \frac{1}{n}\sum_{i=1}^n X_i\]

Test decision:

Rejection \(H_0\) if for the observed value z of Z:

  1. \(z \lt z_{\alpha/2}\) or \(z \gt z_{1-\alpha/2}\)

  2. \(z \gt z_{1-\alpha}\)

  3. \(z \lt z_\alpha\)

P-value:

  1. \(\rho = 2\phi(-|z|)\)

  2. \(\rho = 1 - \phi(z)\)

  3. \(\rho = \phi(z)\)

Annotation:

Example

To test the hypothesis that the mean systolic blood pressure in a certain population equals 140 mmHg. The standard deviation has a known value of 20 and a data set of 55 patients is available.

#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)
# Calculate sample mean and total sample size
xbar<-mean(blood_pressure$mmhg)
n<-length(blood_pressure$mmhg)

# Set mean value under the nullhypothesis
mu0<-140

# Set known sigma
sigma<-20

# Calculate test statistic and p-values
z<-sqrt(n)*(xbar-mu0)/sigma

p_value_A=2*pnorm(-abs(z))
p_value_B=1-pnorm(z)
p_value_C=pnorm(z)

# Output results
z
## [1] -3.708099
p_value_A
## [1] 0.0002088208
p_value_B
## [1] 0.9998956
p_value_C
## [1] 0.0001044104

Remarks:

  • There is no basic R function to calculate the one-sample z-test directly.
  • The above code also shows how to calculate the p-values for the one-sided tests (B) and (C)