varTest {EnvStats}  R Documentation 
Estimate the variance, test the null hypothesis using the chisquared test that the variance is equal to a userspecified value, and create a confidence interval for the variance.
varTest(x, alternative = "two.sided", conf.level = 0.95,
sigma.squared = 1, data.name = NULL)
x 
numeric vector of observations. Missing ( 
alternative 
character string indicating the kind of alternative hypothesis. The possible values are

conf.level 
numeric scalar between 0 and 1 indicating the confidence level associated with the confidence
interval for the population variance. The default value is 
sigma.squared 
a numeric scalar indicating the hypothesized value of the variance. The default value is

data.name 
character string indicating the name of the data used for the test of variance. 
The function varTest
performs the onesample chisquared test of the hypothesis
that the population variance is equal to the user specified value given by the argument
sigma.squared
, and it also returns a confidence interval for the population variance.
The R function var.test
performs the Ftest for comparing two variances.
A list of class "htest"
containing the results of the hypothesis test.
See the help file for htest.object
for details.
Just as you can perform tests of hypothesis on measures of location (mean, median, percentile, etc.), you can do the same thing for measures of spread or variability. Usually, we are interested in estimating variability only because we want to quantify the uncertainty of our estimated location or percentile. Sometimes, however, we are interested in estimating variability and quantifying the uncertainty in our estimate of variability (for example, for performing a sensitivity analysis for power or sample size calculations), or testing whether the population variability is equal to a certain value. There are at least two possible methods of performing a onesample hypothesis test on variability:
Perform a hypothesis test for the population variance based on the chisquared statistic, assuming the underlying population is normal.
Perform a hypothesis test for any kind of measure of spread assuming any kind of underlying distribution based on a bootstrap confidence interval (using, for example, the package boot).
You can use varTest
for the first method.
Note: For a onesample test of location, Student's ttest is fairly robust to departures from normality (i.e., the Type I error rate is maintained), as long as the sample size is reasonably "large." The chisquared test on the population variance, however, is extremely sensitive to departures from normality. For example, if the underlying population is skewed, the actual Type I error rate will be larger than assumed.
Steven P. Millard (EnvStats@ProbStatInfo.com)
van Belle, G., L.D. Fisher, Heagerty, P.J., and Lumley, T. (2004). Biostatistics: A Methodology for the Health Sciences, 2nd Edition. John Wiley & Sons, New York.
Millard, S.P., and N.K. Neerchal. (2001). Environmental Statistics with SPLUS. CRC Press, Boca Raton, FL.
Zar, J.H. (2010). Biostatistical Analysis. Fifth Edition. PrenticeHall, Upper Saddle River, NJ.
# Generate 20 observations from a normal distribution with parameters
# mean=2 and sd=1. Test the null hypothesis that the true variance is
# equal to 0.5 against the alternative that the true variance is not
# equal to 0.5.
# (Note: the call to set.seed allows you to reproduce this example).
set.seed(23)
dat < rnorm(20, mean = 2, sd = 1)
varTest(dat, sigma.squared = 0.5)
#Results of Hypothesis Test
#
#
#Null Hypothesis: variance = 0.5
#
#Alternative Hypothesis: True variance is not equal to 0.5
#
#Test Name: ChiSquared Test on Variance
#
#Estimated Parameter(s): variance = 0.753708
#
#Data: dat
#
#Test Statistic: ChiSquared = 28.64090
#
#Test Statistic Parameter: df = 19
#
#Pvalue: 0.1436947
#
#95% Confidence Interval: LCL = 0.4359037
# UCL = 1.6078623
# Note that in this case we would not reject the
# null hypothesis at the 5% or even the 10% level.
# Clean up
rm(dat)