hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_correg_corrmat_partial (g02by)


    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example


nag_correg_corrmat_partial (g02by) computes a partial correlation/variance-covariance matrix from a correlation or variance-covariance matrix computed by nag_correg_corrmat (g02bx).


[p, ifail] = g02by(ny, nx, isz, r, 'm', m)
[p, ifail] = nag_correg_corrmat_partial(ny, nx, isz, r, 'm', m)


Partial correlation can be used to explore the association between pairs of random variables in the presence of other variables. For three variables, y1, y2 and x3, the partial correlation coefficient between y1 and y2 given x3 is computed as:
r12-r13r23 1-r1321-r232 ,  
where rij is the product-moment correlation coefficient between variables with subscripts i and j. The partial correlation coefficient is a measure of the linear association between y1 and y2 having eliminated the effect due to both y1 and y2 being linearly associated with x3. That is, it is a measure of association between y1 and y2 conditional upon fixed values of x3. Like the full correlation coefficients the partial correlation coefficient takes a value in the range (-1,1) with the value 0 indicating no association.
In general, let a set of variables be partitioned into two groups Y and X with ny variables in Y and nx variables in X and let the variance-covariance matrix of all ny+nx variables be partitioned into,
Σxx Σxy Σyx Σyy .  
The variance-covariance of Y conditional on fixed values of the X variables is given by:
Σyx=Σyy-ΣyxΣxx -1Σxy.  
The partial correlation matrix is then computed by standardizing Σyx,
diagΣyx -12ΣyxdiagΣyx -12.  
To test the hypothesis that a partial correlation is zero under the assumption that the data has an approximately Normal distribution a test similar to the test for the full correlation coefficient can be used. If r is the computed partial correlation coefficient then the appropriate t statistic is
rn-nx-2 1-r2 ,  
which has approximately a Student's t-distribution with n-nx-2 degrees of freedom, where n is the number of observations from which the full correlation coefficients were computed.


Krzanowski W J (1990) Principles of Multivariate Analysis Oxford University Press
Morrison D F (1967) Multivariate Statistical Methods McGraw–Hill
Osborn J F (1979) Statistical Exercises in Medical Research Blackwell
Snedecor G W and Cochran W G (1967) Statistical Methods Iowa State University Press


Compulsory Input Parameters

1:     ny int64int32nag_int scalar
The number of Y variables, ny, for which partial correlation coefficients are to be computed.
Constraint: ny2.
2:     nx int64int32nag_int scalar
The number of X variables, nx, which are to be considered as fixed.
  • nx1;
  • ny+nxm.
3:     iszm int64int32nag_int array
Indicates which variables belong to set X and Y.
The ith variable is a Y variable, for i=1,2,,m.
The ith variable is a X variable.
The ith variable is not included in the computations.
  • exactly ny elements of isz must be <0;
  • exactly nx elements of isz must be >0.
4:     rldrm – double array
ldr, the first dimension of the array, must satisfy the constraint ldrm.
The variance-covariance or correlation matrix for the m variables as given by nag_correg_corrmat (g02bx). Only the upper triangle need be given.
Note:  the matrix must be a full rank variance-covariance or correlation matrix and so be positive definite. This condition is not directly checked by the function.

Optional Input Parameters

1:     m int64int32nag_int scalar
Default: the dimension of the array isz and the first dimension of the array r and the second dimension of the array r. (An error is raised if these dimensions are not equal.)
The number of variables in the variance-covariance/correlation matrix given in r.
Constraint: m3.

Output Parameters

1:     pldpny – double array
The strict upper triangle of p contains the strict upper triangular part of the ny by ny partial correlation matrix. The lower triangle contains the lower triangle of the ny by ny partial variance-covariance matrix if the matrix given in r is a variance-covariance matrix. If the matrix given in r is a partial correlation matrix then the variance-covariance matrix is for standardized variables.
2:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Errors or warnings detected by the function:
On entry,m<3,
On entry,there are not exactly ny elements of isz<0,
orthere are not exactly nx elements of isz>0.
On entry, the variance-covariance/correlation matrix of the X variables, Σxx, is not of full rank. Try removing some of the X variables by setting the appropriate element of isz=0.
Either a diagonal element of the partial variance-covariance matrix, Σyx, is zero and/or a computed partial correlation coefficient is greater than one. Both indicate that the matrix input in r was not positive definite.
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.


nag_correg_corrmat_partial (g02by) computes the partial variance-covariance matrix, Σyx, by computing the Cholesky factorization of Σxx. If Σxx is not of full rank the computation will fail. For a statement on the accuracy of the Cholesky factorization see nag_lapack_dpptrf (f07gd).

Further Comments

Models that represent the linear associations given by partial correlations can be fitted using the multiple regression function nag_correg_linregm_fit (g02da).


Data, given by Osborn (1979), on the number of deaths, smoke (mg/m3) and sulphur dioxide (parts/million) during an intense period of fog is input. The correlations are computed using nag_correg_corrmat (g02bx) and the partial correlation between deaths and smoke given sulphur dioxide is computed using nag_correg_corrmat_partial (g02by). Both correlation matrices are printed using the function nag_file_print_matrix_real_gen (x04ca).
function g02by_example

fprintf('g02by example results\n\n');

x = [ 112 0.30 0.09;
      140 0.49 0.16;
      143 0.61 0.22;
      120 0.49 0.14;
      196 2.64 0.75;
      294 3.45 0.86;
      513 4.46 1.34;
      518 4.46 1.34;
      430 1.22 0.47;
      274 1.22 0.47;
      255 0.32 0.22;
      236 0.29 0.23;
      256 0.50 0.26;
      222 0.32 0.16;
      213 0.32 0.16];

% Calculate correlation matrix
[xbar, std, v, r, ifail] = g02bx(x);

% Calculate partial correlation matrix
nx = int64(1);
ny = int64(2);
isz = [int64(-1); -1; 1];

[p, ifail] = g02by(ny, nx, isz, r);

mtitle = 'Correlation matrix:';
matrix = 'Upper';
diag   = 'Non-unit';

[ifail] = x04ca( ...
                 matrix, diag, r, mtitle);

mtitle = 'Partial Correlation matrix:';
diag   = 'Unit';

[ifail] = x04ca( ...
                 matrix, diag, p, mtitle);

g02by example results

 Correlation matrix:
          1       2       3
 1   1.0000  0.7560  0.8309
 2           1.0000  0.9876
 3                   1.0000

 Partial Correlation matrix:
          1       2
 1   1.0000 -0.7381
 2           1.0000

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015