Learn R Programming

factormodel (version 1.0)

weighted.cov: weighted.cov

Description

This function is to compute an unbiased sample weighted covariance. The function uses only pairwise complete observations.

Usage

weighted.cov(x, y, w = NULL)

Arguments

x

An input vector to compute a covariance, cov(x,y)

y

An input vector to compute a covariance, cov(x,y)

w

A weight vector

Value

Returns an unbiased sample weighted covariance

Examples

Run this code
# NOT RUN {
# If you do not specify weights, 
# it returns the usual unweighted sample covariance 
weighted.cov(x=c(1,3,5),y=c(2,3,1)) 

weighted.cov(x=c(1,3,5),y=c(2,3,1),w=c(0.1,0.5,0.4))

# }

Run the code above in your browser using DataLab