naginterfaces.library.correg.corrmat¶
- naginterfaces.library.correg.corrmat(x, nonzwt='W', wt=None)[source]¶
corrmat
calculates the sample means, the standard deviations, the variance-covariance matrix, and the matrix of Pearson product-moment correlation coefficients for a set of data. Weights may be used.For full information please refer to the NAG Library document for g02bx
https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/g02/g02bxf.html
- Parameters
- xfloat, array-like, shape
must contain the th observation for the th variable, for , for .
- nonzwtstr, length 1, optional
The variance calculation uses a divisor which is either the number of weights or the number of nonzero weights.
- wtNone or float, array-like, shape , optional
, the optional frequency weighting for each observation, with . Usually will be an integral value corresponding to the number of observations associated with the th data value, or zero if the th data value is to be ignored. If , is set to for all .
- Returns
- xbarfloat, ndarray, shape
The sample means. contains the mean of the th variable.
- stdfloat, ndarray, shape
The standard deviations. contains the standard deviation for the th variable.
- vfloat, ndarray, shape
The variance-covariance matrix. contains the covariance between variables and , for , for .
- rfloat, ndarray, shape
The matrix of Pearson product-moment correlation coefficients. contains the correlation coefficient between variables and .
- Raises
- NagValueError
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: .
- (errno )
On entry, .
Constraint: , or
- (errno )
On entry, at least one value of is negative.
Constraint: , for .
- (errno )
On entry, observations have nonzero weight.
Constraint: at least two observations must have a nonzero weight.
- (errno )
On entry, Sum of the weights is .
Constraint: Sum of the weights must be greater than .
- Warns
- NagAlgorithmicWarning
- (errno )
A variable has a zero variance. In this case and are returned as calculated but will contain zero for any correlation involving a variable with zero variance.
- Notes
In the NAG Library the traditional C interface for this routine uses a different algorithmic base. Please contact NAG if you have any questions about compatibility.
For observations on variables the one-pass algorithm of West (1979) as implemented in
ssqmat()
is used to compute the means, the standard deviations, the variance-covariance matrix, and the Pearson product-moment correlation matrix for selected variables. Suitables weights may be used to indicate multiple observations and to remove missing values. The quantities are defined by:The means
The variance-covariance matrix
The standard deviations
The Pearson product-moment correlation coefficients
where is the value of the th observation on the th variable and is the weight for the th observation which will be in the unweighted case.
Note that the denominator for the variance-covariance is , so the weights should be scaled so that the sum of weights reflects the true sample size.
- References
Chan, T F, Golub, G H and Leveque, R J, 1982, Updating Formulae and a Pairwise Algorithm for Computing Sample Variances, Compstat, Physica-Verlag
West, D H D, 1979, Updating mean and variance estimates: An improved method, Comm. ACM (22), 532–555