<- c(2, 0.4, 0.7, 2, -0.4, 2.2, -1.3, 1.2, 1.1, 2.3)
data
<- mean(data)
xbar xbar
[1] 1.02
Cola manufacturers want to test how much the sweetness of a new cola drink is affected by storage. The sweetness loss due to storage was evaluated by 10 professional tasters (by comparing the sweetness before and after storage):
Taster Sweetness loss
1 2.0
2 0.4
3 0.7
4 2.0
5 −0.4
6 2.2
7 −1.3
8 1.2
9 1.1
10 2.3
Obviously, we want to test if storage results in a loss of sweetness
Let \(\mu\) denote the sweetness loss, thus:
Null hypothesis: \(H_0: \mu = 0\)
Alternate hypothesis: \(H_a: \mu > 0\)
Sample mean (\(\bar{x}\)):
<- c(2, 0.4, 0.7, 2, -0.4, 2.2, -1.3, 1.2, 1.1, 2.3)
data
<- mean(data)
xbar xbar
[1] 1.02
T-statistic:
= xbar/(sd(data)/sqrt(10))
t t
[1] 2.696689
p-value:
1-pt(t, df = 9)
[1] 0.01226316
If the probability of Type I error considered is 5%, then we reject the null hypothesis, and conclude that the sweetness loss is indeed greater than 0.
If the probability of Type I error considered is 1%, then we fail to reject the null hypothesis, and conclude that the sweetness loss is indeed 0.
In a study of lettuce growth, ten seedlings were randomly allocated to be grown in either a standard nutrient solution or in a solution containing extra nitrogen. After 22 days, the plants were harvested and weighed. The table below summarizes the results. Can we conclude that extra nitrogen enhances growth?
Nutrient solution | n | mean | SD |
---|---|---|---|
Standard | 5 | 3.62 | 0.54 |
Extra | 5 | 4.17 | 0.67 |
We will first test the hypothesis if the variance of the responses corresponding to the two treatments are the same or not.
We will assume that the response follows the normal distribution.
Let \(\sigma_{standard}^2\) denote the variance of the observations treated with standard solution, \(\sigma_{extra}^2\) denote the variance of the observations treated with extra nitrogen. Then,
Null hypothesis: \(\sigma_{standard}^2 = \sigma_{extra}^2\)
Alternate hypothesis: \(\sigma_{standard}^2 \ne \sigma_{extra}^2\)
# F-statistic:
= (0.54/0.67)^2
F F
[1] 0.6495879
# Critical values based on a significance level of 5%
<- qf(0.025, 4, 4)
left_tail_critical_value left_tail_critical_value
[1] 0.1041175
<- qf(0.975, 4, 4)
right_tail_critical_value right_tail_critical_value
[1] 9.60453
As the \(F\)-statistic is between the critical values, we do not reject the null hypothesis.
Thus, we will use the pooled-variance to conduct a 2-sample t-test for equality of means.
Let \(\mu_{standard}\) denote the mean growth with the standard solution, \(\mu_{extra}\) denote the mean growth with extra nitrogen. Then,
Null hypothesis: \(\mu_{standard} = \mu_{extra}\)
Alternate hypothesis: \(\mu_{standard} \ne \mu_{extra}\)
# Pooled variance
= (0.54^2 + 0.67^2)/2
sp2
# t-statistic
<- (3.62 - 4.17)/(sqrt(sp2*2/5))
t
#p-value
2*pt(t, 8)
[1] 0.1908168
As the \(p\)-value is high, we do not reject the null hypothesis that the extra nitrogen does not enhance growth.
Alternatively, the Welch’s test for unequal variances can be used without testing for equality of variances in the two samples.
= 5; s1 = 0.54; s2 = 0.67
n = (n-1)*(((s1^2 + s2^2)/n)^2)/(((s1^2)/n)^2+((s2^2)/n)^2)
nu <- (3.62 - 4.17)/(sqrt((s1^2+s2^2)/5))
t0
2*pt(t0, 7.654594)
[1] 0.1924672
As the power of Welch’s t-test is similar to that of Student’s t-test, even when the population variances are equal and sample sizes are balanced, Welch’s test can always be used, irrespective of the variances being equal or not.
However, if the variances are unequal, then Student’s t-test must not be used. Type 1 error rate will be higher for a Student’s t-test, particularly if one of the samples has a relatively higher variance, and a smaller sample size as compared to the other sample.
The functions t.test()
and power.t.test()
can be used to conveniently test the hypothesis, estimate confidence intervals, estimate power of the test, or the observations needed for a certain power of the test. Look at the documentation of these function, by executing the code ?t.test()
or ?power.t.test()
in the R console, to see the parameters you need to specify for using them.