Computes a matrix of weighted covariances between the columns of x and the columns of y.

weighted.cov2(x, y = NULL, weights = NULL, na.rm = FALSE)

Arguments

x

a data frame of numeric vectors

y

an optional data frame of numeric vectors. Default is NULL, which means that covariances between the columns of x are computed.

weights

numeric vector of weights. If NULL (default), uniform weights (i.e. all equal to 1) are used.

na.rm

logical, indicating whether NA values should be silently removed before the computation proceeds. Default is FALSE.

Value

a matrix of covariances

Author

Nicolas Robette

See also

Examples

data(Movies)
weighted.cov2(Movies[,c("Budget", "Critics", "BoxOffice")], weights = rep(c(.8,1.2), 500))
#>                  Budget       Critics    BoxOffice
#> Budget     8.993511e+14 -2.480319e+06 1.954705e+13
#> Critics   -2.480319e+06  7.187403e-01 4.903814e+04
#> BoxOffice  1.954705e+13  4.903814e+04 1.142739e+12