Following along Example 1 in Section 10.4, we want to determine whether the standard deviation of the weight of the Snickers bar is now less than 0.75 gram.
weight <- c(19.68, 20.66, 19.56, 21.5, 19.98, 20.65, 19.61, 19.74, 20.55, 20.36, 21.02)
We will use the EnvStats package.
install.packages("EnvStats")
Use the varTest command in the EnvStats package.
The syntax for the command is
varTest(data, alternative = “less” or “greater* or”two.sided,sigma.squared = variance in null hypothesis*)
library(EnvStats)
varTest(weight,alternative="less",sigma.squared=0.75^2)
##
## Chi-Squared Test on Variance
##
## data: weight
## Chi-Squared = 7.2901, df = 10, p-value = 0.3022
## alternative hypothesis: true variance is less than 0.5625
## 95 percent confidence interval:
## 0.000000 1.040705
## sample estimates:
## variance
## 0.4100691
The P-value is 0.3022.