Scatter Matrix and Covariance

Scatter Matrix and Covariance

This package implements functions for computing scatter matrix, as well as weighted covariance matrix.

StatsBase.scattermatFunction.
scattermat(X, [wv::AbstractWeights]; mean=nothing, vardim=1)

Compute the scatter matrix, which is an unnormalized covariance matrix. A weighting vector wv can be specified to weight the estimate.

Arguments

  • mean=nothing: a known mean value. nothing indicates that the mean is unknown, and the function will compute the mean. Specifying mean=0 indicates that the data are centered and hence there's no need to subtract the mean.

  • vardim=1: the dimension along which the variables are organized. When vardim = 1, the variables are considered columns with observations in rows; when vardim = 2, variables are in rows with observations in columns.

source
Base.covFunction.
cov(X, w::AbstractWeights; mean=nothing, vardim=1, corrected=false)

Compute the weighted covariance matrix. Similar to var and std the biased covariance matrix (corrected=false) is computed by multiplying scattermat(X, w) by $\frac{1}{\sum{w}}$ to normalize. However, the unbiased covariance matrix (corrected=true) is dependent on the type of weights used:

  • AnalyticWeights: $\frac{1}{\sum w - \sum {w^2} / \sum w}$

  • FrequencyWeights: $\frac{1}{\sum{w} - 1}$

  • ProbabilityWeights: $\frac{n}{(n - 1) \sum w}$ where $n$ equals count(!iszero, w)

  • Weights: ArgumentError (bias correction not supported)

source
Base.corFunction.
cor(X, w::AbstractWeights, vardim=1)

Compute the Pearson correlation matrix of X along the dimension vardim with a weighting w .

source
mean_and_cov(x, [wv::AbstractWeights]; vardim=1, corrected=false) -> (mean, cov)

Return the mean and covariance matrix as a tuple. A weighting vector wv can be specified. vardim that designates whether the variables are columns in the matrix (1) or rows (2). Finally, bias correction is applied to the covariance calculation if corrected=true. See cov documentation for more details.

source
StatsBase.cov2corFunction.
cov2cor(C, s)

Compute the correlation matrix from the covariance matrix C and a vector of standard deviations s. Use Base.cov2cor! for an in-place version.

source
StatsBase.cor2covFunction.
cor2cov(C, s)

Compute the covariance matrix from the correlation matrix C and a vector of standard deviations s. Use StatsBase.cor2cov! for an in-place version.

source