var.test
F Test to Compare Two Variances

Description

Performs an F test to compare variances of two samples from normal populations.

Usage

var.test(x, ...)
## Default S3 method:
var.test(x, y, ratio = 1, alternative = c("two.sided", "less", "greater"),
    conf.level = 0.95, ...)
## S3 method for class 'formula':
var.test(formula, data, subset, na.action, ...)

Arguments

x, y numeric vectors or objects of class lm that contain the sample values. Missing values (NAs) and infinite values (Infs) are ignored.
ratio a positive numeric value that specifies the ratio of the two variances.
alternative a character string that specifies the alternative hypothesis. alternative refers to the true population variance for x in relation to that for y. Options are:
"two.sided"
the true ratio of variances of x and y is not equal to ratio.
"greater"
the true ratio of variances of x and y is greater than ratio.
"less"
the true ratio of variances of x and y is less than ratio.
You need enter only enough of the character string to create a unique match.
conf.level a numeric vector in the range [0, 1] that specifies the confidence level for the returned confidence interval.
formula a formula of the form v~g that gives the name of a numeric variable (v) and the name of a grouping factor (g). g must have exactly two levels and length equal to that of v.
data a data frame that contains the variables named in the formula and subset arguments. Defaults to the parent frame from which the function was called.
subset a vector that specifies which subset of the rows of the data should be used. This can be a logical vector that is replicated to have length equal to the number of rows of data, a numeric vector that indicates the row numbers to be included, or a character vector of the row names that should be included. By default, all rows are included.
na.action a function that handles missing values. See na.action for details.
... additional arguments.

Details

Methods
var.test The generic method.
var.test.formula The S3 method implemented for the class formula.
var.test.default The default S3 method.
Null hypothesis
The null hypothesis states that the population variances are equal. The alternative hypothesis states that the variance of the population from which x is drawn is greater than, less than, or simply not equal to the variance of the population from which y is drawn. Use the alternative input argument to specify the alternative hypothesis.
Test assumptions
The var.test function relies on the assumption that the input vectors x and y were drawn from normal populations. Outliers have a relatively strong influence on the variance estimates and may have a significant effect on the results.
Value
returns a list of class htest that contains the following components:
statistic F-statistic with names attribute "F". The value is calculated using the formula:
(var(x)/var(y)) / ratio
parameter degrees of freedom (vector of length 2) of the F-distribution that is associated with statistic along with the names attribute c("num df", "denom df").
p.value p-value for the test.
conf.int confidence interval (vector of length 2) for the ratio of the true population variance of x to y. The confidence level is specified in the conf.level argument.
estimate the ratio of the sample variances as calculated by var(x)/var(y) along with the names attribute "ratio of variances".
null.value the ratio of population variances specified by the null hypothesis along with the names attribute "ratio of variances".
alternative a character string that returns the alternative hypothesis (two.sided, greater, or less) as specified in the alternative argument.
method a character string for the name of the method used for the calculation.
data.name a character string (vector of length 1) that contains the names of the x and y input vectors.
References
Box, G. E. P., Hunter, W. G. and Hunter, J. S. (1978). Statistics for Experimenters. New York: Wiley.
Snedecor, G. W. and Cochran, W. G. (1980). Statistical Methods, 7th ed. Ames, Iowa: Iowa State University Press.
See Also
var, F
Examples
# The null hypothesis is that 'x' and 'y' come from
# populations with the same variance. These populations
# are assumed to be normal. The alternative hypothesis is
# that the population variances are not equal. The
# confidence interval for the ratio of the population
# variances will have a confidence level of 0.90.
x <- rnorm(22)
y <- rnorm(20,0,1.5)
var.test(x, y, conf.level=.9)

# The null hypothesis is as above. The alternative # hypothesis is that the population variance for # 'x' is greater than that for 'y'. var.test(x, y, alternative = "greater") var.test(lm(x ~ 1), lm(y ~ 1)) # The same as var.test(x, y)

# Formula interface - large vs small cars, exclude sporty cars var.test(Mileage ~ I(Type data=Sdatasets::fuel.frame, subset = (Type != "Sporty"))

Package stats version 6.0.0-69
Package Index