cov.wtR Documentation

Weighted Covariance Matrices

Description

Returns a list containing estimates of the weighted covariance matrix and the mean of the data, and optionally of the (weighted) correlation matrix.

Usage

## S4 method for signature 'fm'
cov.wt(x, wt = rep(1/nrow(x), nrow(x)), cor = FALSE,
  center = TRUE, method = c("unbiased", "ML"))

Arguments

x

a matrix. As usual, rows are observations and columns are variables.

wt

a non-negative and non-zero vector of weights for each observation. Its length must equal the number of rows of x.

cor

a logical indicating whether the estimated correlation weighted matrix will be returned as well.

center

either a logical or a numeric vector specifying the centers to be used when computing covariances. If TRUE, the (weighted) mean of each variable is used, if FALSE, zero is used. If center is numeric, its length must equal the number of columns of x.

method

string specifying how the result is scaled, see Details below. Can be abbreviated.

Details

By default, method = "unbiased", The covariance matrix is divided by one minus the sum of squares of the weights, so if the weights are the default (1/n) the conventional unbiased estimate of the covariance matrix with divisor (n - 1) is obtained. This differs from the behaviour in S-PLUS which corresponds to method = "ML" and does not divide.

Value

A list containing the following named components:

Examples

mat <- fm.runif.matrix(100, 10)
cov.wt(mat, fm.runif(nrow(mat)))