Skip to contents

wcov computes the estimates of the weighted covariance matrix and the weighted mean of the data.

Usage

.wcov(x, w)

Arguments

x

A matrix with \(m\) columns and \(n\) rows, where each column represents a different variable and each row a different observation.

w

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

Value

A list with two components:

  • center: an estimate for the center (mean) of the data.

  • cov: the estimated (weighted) covariance matrix.

Author

Simon Garnier, garnier@njit.edu

Examples

m <- matrix(c(rnorm(500, 6), rnorm(500, 11, 3)), ncol = 2)
w <- runif(500)
wcec:::.wcov(m, w)
#> $center
#> [1]  6.079087 11.054456
#> 
#> $cov
#>          [,1]     [,2]
#> [1,] 1.104458 0.156673
#> [2,] 0.156673 8.448055
#>