One sample t-test
- sam33frodon
- Dec 28, 2020
- 3 min read
Updated: Feb 2, 2021
A. Two-tailed test
Example 1:
A sample of nine customers spent for lunch ($) at a fast food restaurant:
4.20 5.03 5.86 6.45 7.38 7.54 8.46 8.47 9.87
At the 0.05 level of confidence, is there evidence that the mean amount spent for lunch is different from 6.50$ ?
The null hypothesis H0 : The mean amount spent for lunch is 6.50$
The alternative hypotheses H0 : The mean amount spent for lunch is different from 6.50$
spend = c(4.20, 5.03, 5.86, 6.45, 7.38, 7.54, 8.46, 8.47, 9.87)
mean(spend) # sample mean
## [1] 7.028889
sd(spend) # standard deviation
## [1] 1.812488
t.test(spend, mu = 6.50)
##
## One Sample t-test
##
## data: spend
## t = 0.87541, df = 8, p-value = 0.4069
## alternative hypothesis: true mean is not equal to 6.5
## 95 percent confidence interval:
## 5.635688 8.422090
## sample estimates:
## mean of x
## 7.028889
The p-value = 0.4069 > 0.05. Therefore, we can not reject the null hypothesis.
The data does not provide enough evidence to conclude that the mean amount spent for lunch is different from 6.50$
Example 2:
Labels on 3.79 liter(l) cans of paint usually indicate the drying time and the area can be covered in one coat. Most brands of paint indicate that, in one coat, 3.79 l will cover between 23.2 and 46.4 square meters (m2), depending on the texture of the surface to be painted. One manufacturer, however, claims that 3.79 l of its paint will cover 37.2 square meters of surface area. To test this claim, a random sample of ten 3.79 l cans of white paint were used to paint ten identical areas using the same kind of equipment. The actual areas (in square meters) covered by these 3.79l of paint are given here :
28.9 38.3 34.2 41.5 34.9 28.2 38.1 33.9 32.5
Do the data present sufficient evidence to indicate that the average coverage differs from 37.2 m2 ?
(Mendenhall, Introduction to Probability and Statistic, Nelson education, p.418)
The null hypothesis H0 : mu = 37.2
The alternative hypothesis Ha : mu ≠ 37.2
surface = c(28.8, 28.9, 38.3, 34.2, 41.5, 34.9, 28.2, 38.1, 33.9, 32.5)
mean(surface)
## [1] 33.93
sd(surface)
## [1] 4.488269
t.test(surface, mu = 37.2)
##
## One Sample t-test
##
## data: surface
## t = -2.3039, df = 9, p-value = 0.0467
## alternative hypothesis: true mean is not equal to 37.2
## 95 percent confidence interval:
## 30.71929 37.14071
## sample estimates:
## mean of x
## 33.93
p-value = 0.034939 < 0.05.
We reject the null hypothesis.
There is sufficient evidence to indicate that the average coverage differs from 37.2 m2.
B. One-tailed test
Example 1:
From 58 sales, an analyst finds that the mean amount spent is 26.05$ with a standard deviation of 10.20$. Test the hypothesis that the mean is still $24.85, as it was last year, against the alternative that it is has increased.
set.seed(0)
sale <- c(rnorm(58, mean = 26.05, sd = 10.20))
t.test(sale, mu = 24.85, alternative = c('less'), conf.level= 0.95)
##
## One Sample t-test
##
## data: sale
## t = 1.4551, df = 57, p-value = 0.9244
## alternative hypothesis: true mean is less than 24.85
## 95 percent confidence interval:
## -Inf 28.70364
## sample estimates:
## mean of x
## 26.64316
Example 2:
A bottle filling machine is set to fill bottles with soft drink to a volume of 500 milliliters. The actual volume is known to follow a normal distribution. The manufacturer believes the machine is under-filling bottles. A sample of 20 bottles is taken and the volume of liquid inside is measured.
bottles <- c(484.11,459.49,471.38,512.01,494.48,
528.63,493.64,485.03,473.88,501.59,
502.85,538.08,465.68,495.03,475.32,
529.41,518.13,464.32,449.08,489.27)
We want to know whether the volume is less than 500 milliliters.
We have to determine whether the bottles are being consistently under filled, or whether the low mean volume for the sample could be the result of random variation.
The sample mean is calculated as follow:
mean(bottles)
## [1] 491.5705
The null hypothesis: the mean filling volume is equal to 500 milliliters.
The alternative hypothesis: the mean filling volume is less than 500 milliliters.
A significance level of 0.01 is to be used.
t.test(bottles,
mu = 500,
alternative = "less",
conf.level = 0.99)
##
## One Sample t-test
##
## data: bottles
## t = -1.5205, df = 19, p-value = 0.07243
## alternative hypothesis: true mean is less than 500
## 99 percent confidence interval:
## -Inf 505.6495
## sample estimates:
## mean of x
## 491.5705
The mean volume of bottles for the sample is 491.6 ml.
The one-sided 99% confidence interval means the filling volume is likely to be less than 505.64 ml.
Because the p-value of 0.07243, the probability of selecting a sample with a mean volume less than or equal to 500 ml would be approximately 7%.
Because the p-value is not less than the significance level of 0.01, we cannot reject the null hypothesis that the mean filling volume is equal to 500 ml. In conclusion, there is no evidence that the bottles are being under-filled.
Comments