CovarianceAndCorrelationMatrix: 'CovarianceAndCorrelationMatrix'

View source: R/covariancecorrelation.R

CovarianceAndCorrelationMatrixR Documentation

CovarianceAndCorrelationMatrix

Description

Generate a covariance or correlation matrix from weighted or unweighted data using either the set of complete observations, or using pairwise-complete observations.

Usage

CovarianceAndCorrelationMatrix(
  data,
  weights = NULL,
  pairwise = FALSE,
  use.correlation = TRUE
)

Arguments

data

A data frame containing the input data.

weights

A numeric vector containing the value of the weight for each row of data. If weights is NULL then this function is just a wrapper for the base functions cov and cor.

pairwise

A logical value. If TRUE the correlations or covariances will be computed using the complete data for each pair of variables from data. If FALSE then cases with missing data will be excluded from the computation.

use.correlation

A logical value specifying whether a correlation or covariance matrix should be returned.

Examples

my.data <- cbind(c(-0.9, 0.05, 0.1, 0.8), c(1, NaN, 0, -0.9))
my.weight <- c(1.2, 0.8, 0.8, 1.2)
CovarianceAndCorrelationMatrix(my.data, weights = my.weight, pairwise = TRUE)

NumbersInternational/flipStatistics documentation built on April 12, 2024, 9:25 a.m.