Variance
Var()
computes the variance of x
. If x
is a matrix variances of the columns of x
are computed.
Var(x, ...) ## S3 method for class 'Freq' Var(x, breaks, ...) ## Default S3 method: Var(x, weights = NULL, na.rm = FALSE, method = c("unbiased", "ML"), ...)
x |
a numeric vector, matrix or data frame. |
weights |
a numerical vector of weights the same length as |
na.rm |
logical. Should missing values be removed? |
method |
determines the estimator type; if |
breaks |
breaks for calculating the variance for classified data as composed by |
... |
further arguments passed to or from other methods. |
Var
is just another interface to Cov
.
The denominator n - 1 is used which gives an unbiased estimator
of the (co)variance for i.i.d. observations.
These functions return NA
when there is only one
observation (whereas S-PLUS has been returning NaN
), and
fail if x
has length zero.
For r <- Cor(*, use = "all.obs")
, it is now guaranteed that
all(abs(r) <= 1)
.
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
cor.test
for confidence intervals (and tests).
cov.wt
for weighted covariance computation.
sd
for standard deviation (vectors).
Var(1:10) # 9.166667 Var(1:5, 1:5) # 2.5 # weighted Variance set.seed(45) (z <- as.numeric(names(w <- table(x <- sample(-10:20, size=50, replace=TRUE))))) Var(z, w=w) # check! all.equal(Var(x), Var(z, w=w)) # Variance for frequency tables Var(Freq(as.table(c(6,16,24,25,17))), breaks=c(0, 10, 20, 30, 40, 50))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.