cov.wt
Weighted Covariance Estimation

Description

Returns a list containing estimates of the covariance matrix and of the mean vector for the data, and optionally of the correlation matrix.

Usage

cov.wt(x, wt = rep(1/nrow(x), nrow(x)), cor = FALSE, center = TRUE, 
    method = c("unbiased", "ML"))

Arguments

x a matrix of data. Rows represent observations and columns represent variables. Only finite values are accepted.
wt a vector of weights for each observation. This vector must have the same length as the number of rows in x. Missing values are not accepted. Weights should not be negative.
cor a logical flag. If TRUE, then the estimated correlation matrix is returned as a component of the answer. The default is FALSE.
center a logical value or a numeric vector providing the center about which the covariance is to be taken.
  • If center is TRUE (the default), then the mean of each column is used.
  • If center is FALSE, then zero is used for each variable.
  • If center is numeric, then its length must equal the number of columns in x.
method a character string specifying whether to use the unbiased estimator (the default) or the maximum likelihood estimator of the covariance matrix.
Value
returns a list with the following components:
cov the estimated covariance matrix.
center an estimate for the center (mean) of the data.
wt the weights that were used in the computation. This is returned only if the wt argument was given.
n.obs the number of observations (rows) in x.
cor the estimated correlation matrix for the data. This is returned only if the input cor is TRUE.
See Also
cov.mve, var, mahalanobis.
Examples
cov.wt(Sdatasets::freeny.x)  # unweighted estimate 
cov.wt(Sdatasets::freeny.x, center=FALSE)  # take covariance about zero 
Package stats version 6.1.4-13
Package Index