Learn R Programming

rv (version 1.0)

Covariance, Correlation, Variance, and Standard deviation Statistics: Distributions of Various Statistics of a Random Vector and Array

Description

var, cov and cor compute the distribution of the variance statistic of x and the distribution of the covariance statistic or the correlation statistic of x and y if these are vectors. If x and y are matrices then the covariances (or correlations) between the columns of x and the columns of y are computed.

Usage

cov(x, ...)
  cor(x, ...)
  var(x, ...)

## S3 method for class 'rv': cov(x, y=NULL, \dots) ## S3 method for class 'rv': cor(x, y=NULL, \dots) ## S3 method for class 'rv': var(x, \dots)

sd(x, na.rm=FALSE)

Arguments

x
a numeric or random vector, matrix, or a data frame
y
NULL (default) or a vector, matrix or data frame with compatible dimensions to x. The default is equivalent to y = x (but more efficient).
...
further arguments passed to corresponding numeric functions

Value

  • A random vector or array.

Details

The functions cov, var, cor are now generic - whenever the rv package is loaded.

The original functions in the stats package are the default functions of these generic functions.

To access the original help page in the stats package, go to cov2cor or detach the rv package and then access the help pages in the stat package.

sd is not generic but it is rewritten to catch the possibility that the argument is a random variable object.

cov gives the distribution (that is, a random variable object) of the covariance statistic, as computed by the standard R function cov.

This is implemented simply by applying the numerical cov function to the rows of the simulation matrices of x and y and forming a new rv object from the resulting vector of simulations. Alternatively x may be a random matrix (and y NULL). Then the numerical function cov is m cor works similarly, but returns the distribution of the correlation statistic (i.e. function).

var computes the distribution of the variance statistic.

References

Kerman, J. and Gelman, A. (2007). Manipulating and Summarizing Posterior Simulations Using Random Variable Objects. Statistics and Computing 17:3, 235-244.

See also vignette("rv").

See Also

cov, cor, var, sd for details.

Examples

Run this code
#

Run the code above in your browser using DataLab