
Exercises: Hypothesis tests, resampling
Exercise 1 (Pollen) You want to investigate if the proportion of Swedish students allergic to pollen is greater than 0.3, the proportion in Sweden as a whole. To do this, you observe 20 people in a student group at BMC in Uppsala, 9 of them are allergic to pollen.
Is there reason to believe that the proportion of Swedish students allergic to pollen is greater than 0.3? Perform a hypothesis test to answer the question.
Can you identify any problems with this study setup?
\(H_0: \pi=0.3\) \(H_1: \pi>0.3\)
Set the significance level to \(\alpha=0.05\).
The test statistic is \(X\), the number of allergic people in a sample of size 20.
\(x_{obs} = 9\)
Simulate null distribution
Compute p-value, i.e. if null is true what is the probability to observe \(x_{obs}\) or higher?
xobs <- 9
(p <- mean(xnull>=xobs))[1] 0.1143
As \(p>\alpha\) we fail to reject the null hypothesis. The data do not provide evidence against the null hypothesis, i.e. there is no reason to believe that the students are more allergic than the general Swedish population.
Problems with the study: Discuss in your group! Is the sample random? Is it reasonable to select 20 students at BMC to answer a question about all students in Sweden?
Exercise 2 (Diet) A diet study aims to study how the hemoglobin (Hb) levels in blood are affected by an iron-rich diet consisting of tofu, soybeans, broccoli, lentils and peas. To perform the study the dietician has recruited 40 male participants, who are randomly assigned to the iron-rich diet or control group (no change in participants diet), 20 participants in each group.
The observed Hb levels (in g/L);
ctrl <- c(197, 186, 157, 170, 193, 188, 175, 186, 177, 191, 168, 193, 191, 189, 188, 192, 179, 186, 197, 203)
iron <- c(187, 218, 196, 210, 206, 178, 181, 193, 172, 202, 169, 221, 183, 222, 185, 174, 192, 192, 162, 211)Perform a hypothesis test to investigate if the Hb level is affected (increased or decreased) by the iron-rich diet.
Define \(H_0\) and \(H_1\)
\(H_0: \mu_{iron} = \mu_{ctrl}\) No difference in mean Hb level between control group and iron-rich diet group.
\(H_1: \mu_{iron} \neq \mu_{ctrl}\)
Will use the significance level, \(\alpha=0.05\).
Select test statistic \(D = \bar X_{iron} - \bar X_{ctrl}\), where \(\bar X_{ctrl}\) is the mean Hb level in a control group of 20 people and \(\bar X_{iron}\) is the mean Hb level in a diet group of 20 people.
The observed value; \(d_{obs}\)
miron <- mean(iron)
mctrl <- mean(ctrl)
(dobs <- miron - mctrl)[1] 7.4
Compute null distribution using permutation.
## Under null all observations are equivalent
allobs <- c(iron, ctrl)
dnull <- replicate(10000, {
## Permute the 40 observations and assign first 20 to the iron group
x <- sample(allobs)
d <- mean(x[1:20]) - mean(x[21:40])
})
hist(dnull)
Compute p-value;
(p <- mean(abs(dnull) >= abs(dobs)))[1] 0.1229
As the estimated p-value is 0.1229, \(p>\alpha\), we fail to reject the null hypothesis. The data do not provide evidence against the null hypothesis, i.e. there is no reason to believe that the iron-rich diet affects the mean Hb level.