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)
gravitree:::.wcov(m, w)
#> $center
#> [1]  6.063627 10.943649
#> 
#> $cov
#>             [,1]        [,2]
#> [1,]  0.87686308 -0.01177558
#> [2,] -0.01177558  9.23585747
#>