Scatter Matrix and Covariance
This package implements functions for computing scatter matrix, as well as weighted covariance matrix.
StatsBase.scattermat — Function.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.nothingindicates that the mean is unknown, and the function will compute the mean. Specifyingmean=0indicates 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. Whenvardim = 1, the variables are considered columns with observations in rows; whenvardim = 2, variables are in rows with observations in columns.
Base.cov — Function.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$ equalscount(!iszero, w)Weights:ArgumentError(bias correction not supported)
Base.cor — Function.cor(X, w::AbstractWeights, vardim=1)Compute the Pearson correlation matrix of X along the dimension vardim with a weighting w .
StatsBase.mean_and_cov — Function.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.
StatsBase.cov2cor — Function.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.
StatsBase.cor2cov — Function.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.