Section 39 Comparison of Means
39.1 Steps of Hypothesis testing
- Identify the parameter of interest: Population mean \(\large \mu\)
- Define \(\large H_O\) and \(\large H_A\)
\[\large H_O: \mu_1 = \mu_2\]
\[\large H_A: \mu_1 \ne \mu_2\]
- Define \(\large \alpha\): \(\large \alpha = 0.05\)
- Calculate an estimate of the parameter
Sample Means: \(\large \bar{y_1}, \bar{y_2}\)
- Determine test statistic, its distribution when \(\large H_O\) is correct, calculate the value of test statistic from the sample.
\[ \large t_{Cal} = \frac{(\bar{y_1}-\bar{y_2}) - (\mu_1 - \mu_2)} {\sqrt{Var(\bar{y_1}-\bar{y_2})}} \]
\[ \large t_{Cal} = \frac{(\bar{y_1}-\bar{y_2})} {\sqrt{Var(\bar{y_1}-\bar{y_2})}} \]
\[ \large t_{Cal} = \frac{(\bar{y_1}-\bar{y_2})} {\sqrt{2MSE/n}} \]
- Note - The test statistic is the difference of Observed Difference & Expected Difference - The test statistic represents the ratio of signal to error - The test statistic is centred and scaled
Distribution of the test statistic
\[\large t \space distribution \space with \space error \space df \]
39.2 R code
fm <- lm(SBP ~ Group, data=BP)
summary(fm)
sigma <- summary(fm)$sigma
anova(fm)
MSE <- anova(fm)[2,3]
n <- sum(BP$Group=='A')
SE <- sqrt(MSE/n)
tstat <- qt(p = 0.025, df = n, lower.tail = FALSE)
Group <- unique(BP$Group)
Mean <- predict(fm, newdata = Group)
LCL <- Mean - tstat*SE
UCL <- Mean + tstat*SE
# Difference between A and B
meanA <- unname(Mean[1])
meanB <- unname(Mean[2])
se_diff <- sqrt(2*MSE/n)
t_cal <- (meanA-meanB)/se_diff
2*pt(q=abs(t_cal), df=fm$df.residual, lower.tail=FALSE)
# Compare with the summary(fm)
summary(fm)