## Function

Code
• methods {utils}
• getAnywhere {utils}
[1] var.test.default* var.test.formula*
see '?methods' for accessing help and source code

[[1]]
A single object matching 'var.test.default' was found
It was found in the following places
registered S3 method for var.test from namespace stats
namespace:stats
with value

function (x, y, ratio = 1, alternative = c("two.sided", "less",
"greater"), conf.level = 0.95, ...)
{
if (!((length(ratio) == 1L) && is.finite(ratio) && (ratio >
0)))
stop("'ratio' must be a single positive number")
alternative <- match.arg(alternative)
if (!((length(conf.level) == 1L) && is.finite(conf.level) &&
(conf.level > 0) && (conf.level < 1)))
stop("'conf.level' must be a single number between 0 and 1")
DNAME <- paste(deparse(substitute(x)), "and", deparse(substitute(y)))
if (inherits(x, "lm") && inherits(y, "lm")) {
DF.x <- x$df.residual DF.y <- y$df.residual
V.x <- sum(x$residuals^2)/DF.x V.y <- sum(y$residuals^2)/DF.y
}
else {
x <- x[is.finite(x)]
DF.x <- length(x) - 1L
if (DF.x < 1L)
stop("not enough 'x' observations")
y <- y[is.finite(y)]
DF.y <- length(y) - 1L
if (DF.y < 1L)
stop("not enough 'y' observations")
V.x <- var(x)
V.y <- var(y)
}
ESTIMATE <- V.x/V.y
STATISTIC <- ESTIMATE/ratio
PARAMETER <- c(num df = DF.x, denom df = DF.y)
PVAL <- pf(STATISTIC, DF.x, DF.y)
if (alternative == "two.sided") {
PVAL <- 2 * min(PVAL, 1 - PVAL)
BETA <- (1 - conf.level)/2
CINT <- c(ESTIMATE/qf(1 - BETA, DF.x, DF.y), ESTIMATE/qf(BETA,
DF.x, DF.y))
}
else if (alternative == "greater") {
PVAL <- 1 - PVAL
CINT <- c(ESTIMATE/qf(conf.level, DF.x, DF.y), Inf)
}
else CINT <- c(0, ESTIMATE/qf(1 - conf.level, DF.x, DF.y))
names(STATISTIC) <- "F"
names(ESTIMATE) <- names(ratio) <- "ratio of variances"
attr(CINT, "conf.level") <- conf.level
RVAL <- list(statistic = STATISTIC, parameter = PARAMETER,
p.value = PVAL, conf.int = CINT, estimate = ESTIMATE,
null.value = ratio, alternative = alternative, method = "F test to compare two variances",
data.name = DNAME)
attr(RVAL, "class") <- "htest"
return(RVAL)
}
<bytecode: 0x000000002707ca58>
<environment: namespace:stats>

[[2]]
A single object matching 'var.test.formula' was found
It was found in the following places
registered S3 method for var.test from namespace stats
namespace:stats
with value

function (formula, data, subset, na.action, ...)
{
if (missing(formula) || (length(formula) != 3L) || (length(attr(terms(formula[-2L]),
"term.labels")) != 1L))
stop("'formula' missing or incorrect")
m <- match.call(expand.dots = FALSE)
if (is.matrix(eval(m$data, parent.frame()))) m$data <- as.data.frame(data)
m[[1L]] <- quote(stats::model.frame)
m$... <- NULL mf <- eval(m, parent.frame()) DNAME <- paste(names(mf), collapse = " by ") names(mf) <- NULL response <- attr(attr(mf, "terms"), "response") g <- factor(mf[[-response]]) if (nlevels(g) != 2L) stop("grouping factor must have exactly 2 levels") DATA <- setNames(split(mf[[response]], g), c("x", "y")) y <- do.call("var.test", c(DATA, list(...))) y$data.name <- DNAME
y
}
<bytecode: 0x0000000027072588>
<environment: namespace:stats>

Help
• tools:::Rd2HTML
• utils:::.getHelpFile
 var.test R Documentation

## F Test to Compare Two Variances

### Description

Performs an F test to compare the 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 of data values, or fitted linear model objects (inheriting from class “lm”). ratio the hypothesized ratio of the population variances of x and y. alternative a character string specifying the alternative hypothesis, must be one of “two.sided” (default), “greater” or “less”. You can specify just the initial letter. conf.level confidence level for the returned confidence interval. formula a formula of the form lhs ~ rhs where lhs is a numeric variable giving the data values and rhs a factor with two levels giving the corresponding groups. data an optional matrix or data frame (or similar: see model.frame) containing the variables in the formula formula. By default the variables are taken from environment(formula). subset an optional vector specifying a subset of observations to be used. na.action a function which indicates what should happen when the data contain NAs. Defaults to getOption(“na.action”). … further arguments to be passed to or from methods.

### Details

The null hypothesis is that the ratio of the variances of the populations from which x and y were drawn, or in the data to which the linear models x and y were fitted, is equal to ratio.

### Value

A list with class “htest” containing the following components:

 statistic the value of the F test statistic. parameter the degrees of the freedom of the F distribution of the test statistic. p.value the p-value of the test. conf.int a confidence interval for the ratio of the population variances. estimate the ratio of the sample variances of x and y. null.value the ratio of population variances under the null. alternative a character string describing the alternative hypothesis. method the character string “F test to compare two variances”. data.name a character string giving the names of the data.

bartlett.test for testing homogeneity of variances in more than two samples from normal distributions; ansari.test and mood.test for two rank based (nonparametric) two-sample tests for difference in scale.
x <- rnorm(50, mean = 0, sd = 2)