Learn R Programming

SciencesPo (version 1.02.12)

sampleCovariance: Calculate the Sample Covariance

Description

Computes the sample covariance between two vectors. The Covariance provides a measure of the strength of the correlation between two or more sets of random variates. The covariance for two random variates x and y, each with sample size n, is defined by the expectation value variables cov(x, y) = (x - _x)(y - _y). For uncorrelated variables, cov(x, y) = 0.
x and y must have the same length, greater than one with no missing values.
# Some random data: df = data.frame(id=1:20, x=rnorm(20, mean=2, sd=.5), y=rnorm(20, mean=5, sd=2) ) sampleCovariance(df$x, df$y) [object Object],[object Object] Based on the Google's R Guide Style.

Usage

sampleCovariance(x, y, verbose = TRUE)

Arguments

x
One of two vectors whose sample covariance is to be calculated.
y
The other vector.
verbose
If TRUE, prints sample covariance; if not, not. Default is verbose = TRUE.

Value

  • The sample covariance between x and y.

encoding

UTF-8