PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_correg_ssqmat_to_corrmat (g02bw)
Purpose
nag_correg_ssqmat_to_corrmat (g02bw) calculates a matrix of Pearson product-moment correlation coefficients from sums of squares and cross-products of deviations about the mean.
Syntax
[
r,
ifail] = nag_correg_ssqmat_to_corrmat(
m,
r)
Description
nag_correg_ssqmat_to_corrmat (g02bw) calculates a matrix of Pearson product-moment correlation coefficients from sums of squares and cross-products about the mean for observations on
variables which can be computed by a single call to
nag_correg_ssqmat (g02bu) or a series of calls to
nag_correg_ssqmat_update (g02bt). The sums of squares and cross-products are stored in an array packed by column and are overwritten by the correlation coefficients.
Let
be the cross-product of deviations from the mean, for
and
, then the product-moment correlation coefficient,
is given by
References
None.
Parameters
Compulsory Input Parameters
- 1:
– int64int32nag_int scalar
-
, the number of variables.
Constraint:
.
- 2:
– double array
-
Contains the upper triangular part of the sums of squares and cross-products matrix of deviations from the mean. These are stored packed by column, i.e., the cross-product between variable and , , is stored in .
Optional Input Parameters
None.
Output Parameters
- 1:
– double array
-
The Pearson product-moment correlation coefficients.
These are stored packed by column corresponding to the input cross-products.
- 2:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Note: nag_correg_ssqmat_to_corrmat (g02bw) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
-
-
- W
-
A variable has a zero variance. All correlations involving the variable with zero variance will be returned as zero.
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
The accuracy of
nag_correg_ssqmat_to_corrmat (g02bw) is entirely dependent upon the accuracy of the elements of array
r.
Further Comments
nag_correg_ssqmat_to_corrmat (g02bw) may also be used to calculate the correlations between parameter estimates from the variance-covariance matrix of the parameter estimates as is given by several functions in this chapter.
Example
A program to calculate the correlation matrix from raw data. The sum of squares and cross-products about the mean are calculated from the raw data by a call to
nag_correg_ssqmat (g02bu). The correlation matrix is then calculated from these values.
Open in the MATLAB editor:
g02bw_example
function g02bw_example
fprintf('g02bw example results\n\n');
wt = [ 0.1300 1.3070 0.3700];
x = [ 9.1231 3.7011 4.5230;
0.9310 0.0900 0.8870;
0.0009 0.0099 0.0999];
[m, n] = size(x);
m = int64(m);
[sw, wmean, c, ifail] = g02bu(x, 'wt', wt);
[r, ifail] = g02bw(m, c);
mtitle = 'Correlation matrix:';
uplo = 'Upper';
diag = 'Non-unit';
[ifail] = x04cc( ...
uplo, diag, m, r, mtitle);
g02bw example results
Correlation matrix:
1 2 3
1 1.0000 0.9908 0.9903
2 1.0000 0.9624
3 1.0000
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015