[ top | up ]

Covariance Matrices

Syntax

var(x, y=x, na.rm=FALSE, pairwise=FALSE)

Arguments

x a matrix or vector.
y a matrix or vector.
pairwise logical.
na.rm logical.

Description

var computes the variance of x and the covariance of x and y if x and y are vectors. If x and y are matrices then the covariance between the columns of x and the the columns of y are computed.

If na.rm is TRUE then missing values are removed from the vectors before calculation. If pairwise is FALSE (the default), missing values in matrices are handled by casewise deletion. If pairwise is TRUE, all cases which are complete for a pair of variables is used to compute the covariance for that pair of variables. This can result in covariance matrices which are not positive semidefinite.

Examples

var(1:10) # 9.166667 var(1:5,1:5) # 2.5