Returns a list containing estimates of the weighted covariance matrix and the mean of the data, and optionally of the (weighted) correlation matrix.
cov.wt(x, wt = rep(1/nrow(x), nrow(x)), cor = FALSE, center = TRUE,
method = c("unbiased", "ML"))
a matrix or data frame. As usual, rows are observations and columns are variables.
a non-negative and non-zero vector of weights for each
observation. Its length must equal the number of rows of x
.
a logical indicating whether the estimated correlation weighted matrix will be returned as well.
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
.
string specifying how the result is scaled, see ‘Details’ below. Can be abbreviated.
A list containing the following named components:
the estimated (weighted) covariance matrix
an estimate for the center (mean) of the data.
the number of observations (rows) in x
.
the weights used in the estimation. Only returned if given as an argument.
the estimated correlation matrix. Only returned if
cor
is TRUE
.
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 (method = "ML"
and does not divide.
# NOT RUN {
(xy <- cbind(x = 1:10, y = c(1:3, 8:5, 8:10)))
w1 <- c(0,0,0,1,1,1,1,1,0,0)
cov.wt(xy, wt = w1) # i.e. method = "unbiased"
cov.wt(xy, wt = w1, method = "ML", cor = TRUE)
# }
Run the code above in your browser using DataLab