Two-sample t-test
- sam33frodon
- Feb 2, 2021
- 2 min read
We wish to use a two-sample t-test to determine whether there is any real difference in mean sepal width for the Versicolor and Virginica species of iris.
We can assume that sepal width is normally distributed, and that the variance for the two groups is equal.
The null hypothesis: there is no real difference in mean sepal width for the two species The alternative hypothesis: there is a difference.
head(iris,10)
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3.0 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5.0 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
## 7 4.6 3.4 1.4 0.3 setosa
## 8 5.0 3.4 1.5 0.2 setosa
## 9 4.4 2.9 1.4 0.2 setosa
## 10 4.9 3.1 1.5 0.1 setosa
t.test(Sepal.Width ~ Species,
iris,
Species %in% c("versicolor", "virginica"),
var.equal = T)
##
## Two Sample t-test
##
## data: Sepal.Width by Species
## t = -3.2058, df = 98, p-value = 0.001819
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.33028246 -0.07771754
## sample estimates:
## mean in group versicolor mean in group virginica
## 2.770 2.974
The 95% confidence interval for the difference is –0.33 to –0.08, meaning that the mean sepal width for the Versicolor species is estimated to be between 0.08 and 0.33 cm less than for the Virginica species.
The p-value of 0.001819 is less than the significance level of 0.05, so we can reject the null hypothesis that the mean sepal width is the same for the Versicolor and Virginica species in favor of the alternative hypothesis that the mean sepal width is different for the two species.
head(iris,10)
コメント