x <- c(154, 140, 147, 162, 172)
## sample mean
m <- mean(x)
## estimated standard error of the sample mean
SE <- sd(x)/sqrt(5)
## Observed value of the test statistic
(tobs <- (m - 140)/SE)[1] 2.676865
Exercise 1 The hemoglobin value (Hb) in women is on average 140 g/L. You observe the following Hb values in a set of five male blood donors: 154, 140, 147, 162, 172. Assume that Hb is normally distributed. Is there a reason to believe that the mean Hb value in men differs from that in women?
Let \(X\) denote the Hb value in g/L for male blood donors.
\[H_0: \mu = 140\] \[H_1: \mu \neq 140\]
Use the significance level \(\alpha=0.05\).
Use the test statistic \(T = \frac{\bar X - \mu_0}{SE},\) where \(\mu_0\) is the population mean under \(H_0\), i.e. 140, and the standard error of the sample mean is estimated by \(SE \approx \frac{s}{\sqrt{n}}.\)
Compute \(t_{obs} = \frac{\bar x-140}{s/\sqrt{n}}.\)
x <- c(154, 140, 147, 162, 172)
## sample mean
m <- mean(x)
## estimated standard error of the sample mean
SE <- sd(x)/sqrt(5)
## Observed value of the test statistic
(tobs <- (m - 140)/SE)[1] 2.676865
Compute the p-value. For a two-sided test \(P(|T|>|t_{obs}|) = P(T>|t_{obs}|) + P(T<-|t_{obs}|)\).
## P(T>tobs)
pt(tobs, df=4, lower.tail=FALSE)[1] 0.02770443
## p = P(t>tobs) + P(t<-tobs) = 2 * P(t>tobs)
(p <- 2*pt(tobs, df=4, lower.tail=FALSE))[1] 0.05540887
As \(p > \alpha\), we fail to reject the null hypothesis. The data do not provide evidence that the Hb value in men differs from that of women (140 g/L).
Note that the same can be achieved using the function t.test;
One Sample t-test
data: x
t = 2.6769, df = 4, p-value = 0.05541
alternative hypothesis: true mean is not equal to 140
95 percent confidence interval:
139.442 170.558
sample estimates:
mean of x
155
Exercise 2 The hemoglobin value (Hb) in men is on average 188 g/L. The Hb values in Exercise 1 were actually measured after the men had donated blood. Is there a reason to believe that the mean Hb level for men after blood donation is less than 188 g/L?
\(H_0: \mu = 188\) \(H_1: \mu < 188\)
Use the significance level \(\alpha=0.05\).
Use the test statistic \(T = \frac{\bar X - \mu_0}{SE},\) where \(\mu_0=188\) and the standard error is estimated by \(SE \approx \frac{s}{\sqrt{n}}.\)
Compute \(t_{obs} = \frac{\bar x - 188}{s/\sqrt{n}}\)
## Observed value of test statistic
(tobs <- (m-188)/SE)[1] -5.889103
Compute the p-value, \(P(T<t_{obs})\)
## p=P(T<tobs)
(p <- pt(tobs, df=4, lower.tail=TRUE))[1] 0.002078429
As \(p < \alpha\) the null hypothesis is rejected and we can conclude that the data provide evidence that the mean Hb value after blood donation is less than 188 g/L.
Note that the same can be achieved using the function t.test;
t.test(x, mu=188, alternative="less")
One Sample t-test
data: x
t = -5.8891, df = 4, p-value = 0.002078
alternative hypothesis: true mean is less than 188
95 percent confidence interval:
-Inf 166.946
sample estimates:
mean of x
155
Exercise 3 By observing the Hb values in 5 male blood donors: 154, 140, 147, 162, 172 g/L, and 5 female blood donors: 123, 140, 137, 132, 127 g/L, is there a reason to believe that the Hb level is higher in men than in women?
Let \(X_m\) denote the Hb value in men and \(X_w\) the Hb value in women.
\[H_0: \mu_m = \mu_w\] \[H_1: \mu_m > \mu_w\]
Use the significance level \(\alpha=0.05\).
Use the test statistic \(T = \frac{\bar X_m - \bar X_w}{SE}\). If we assume equal variances we can use Student’s t-test and compute SE using the pooled standard deviation. An alternative is to use Welch’s t-test (unequal variances t-test) and compute \(SE=\sqrt{\frac{s_m^2}{n_m} + \frac{s_w^2}{n_w}}\). The test statistic is t-distributed and the degrees of freedom are approximated using the Welch-Satterthwaite’s equation, as implemented in t.test.
x <- c(154, 140, 147, 162, 172)
y <- c(123, 140, 137, 132, 127)
## Perform Welch's t-test with unequal variances
tt <- t.test(x, y, alternative="greater")
tt
Welch Two Sample t-test
data: x and y
t = 3.6171, df = 6.2637, p-value = 0.00517
alternative hypothesis: true difference in means is greater than 0
95 percent confidence interval:
10.8297 Inf
sample estimates:
mean of x mean of y
155.0 131.8
As the p-value \(p=0.0051699\) is less than \(\alpha\), we reject the null hypothesis and conclude that the data provide evidence that the mean Hb is higher in male blood donors than in female.
Exercise 4 Based on statistics from blodcentralen we learn that male Hb values (before donation) are normally distributed with mean 188 g/L and standard deviation 16 g/L. Using this new information and the following observed Hb values in five male donors after donation: 154, 140, 147, 162, 172 g/L, is there reason to believe that the mean Hb value for men after blood donation is lower than 188 g/L?
\(H_0: \mu = 188\) \(H_1: \mu < 188\)
Use \(\alpha = 0.05\).
Under \(H_0\), the Hb value for a single male donor is normally distributed with mean 188 g/L and standard deviation 16 g/L.
\(X \sim N(188, 16^2)\)
Since the sample size is 5, the sample mean is normally distributed with \(\bar X \sim N\left(188, \frac{16^2}{5}\right),\) so the standard error of mean is \(SE = \frac{16}{\sqrt{5}}\).
Use the test statistic
\(Z = \frac{\bar X - 188}{16/\sqrt{5}} \sim N(0,1)\)
Compute \(z_{obs}\)
Compute the p-value: \[p=P(\bar X \leq x_{obs}) = P(Z \leq zobs).\]
[1] 1.995119e-06
As \(p < \alpha\), we reject \(H_0\) and conclude that the data provide evidence that the mean Hb value for men after blood donation is lower than 188 g/L.
Exercise 5 In order to study the effect of high-fat diet, 12 mice are fed normal diet (control group) and 12 mice are fed high-fat diet. After a couple of weeks, the mouse weights in grams are recorded:
High-fat mice (g): 25, 30, 23, 18, 31, 24, 39, 26, 36, 29, 23, 32
Normal diet mice (g): 27, 25, 22, 23, 25, 37, 24, 26, 21, 26, 30, 24
Does high-fat diet increase body weight in mice?
## Student's t-test with pooled variances
t.test(xHF, xN, var.equal=TRUE, alternative="greater")
Two Sample t-test
data: xHF and xN
t = 1.0234, df = 22, p-value = 0.1586
alternative hypothesis: true difference in means is greater than 0
95 percent confidence interval:
-1.468785 Inf
sample estimates:
mean of x mean of y
28.00000 25.83333
## Unequal variances with Welch approximation to the degrees of freedom (the default)
t.test(xHF, xN, var.equal=FALSE, alternative="greater")
Welch Two Sample t-test
data: xHF and xN
t = 1.0234, df = 19.818, p-value = 0.1592
alternative hypothesis: true difference in means is greater than 0
95 percent confidence interval:
-1.486449 Inf
sample estimates:
mean of x mean of y
28.00000 25.83333