Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_correg_corrmat_partial (g02by)

## Purpose

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).

## Syntax

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

## Description

Partial correlation can be used to explore the association between pairs of random variables in the presence of other variables. For three variables, ${y}_{1}$, ${y}_{2}$ and ${x}_{3}$, the partial correlation coefficient between ${y}_{1}$ and ${y}_{2}$ given ${x}_{3}$ is computed as:
 $r12-r13r23 1-r1321-r232 ,$
where ${r}_{ij}$ 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 ${y}_{1}$ and ${y}_{2}$ having eliminated the effect due to both ${y}_{1}$ and ${y}_{2}$ being linearly associated with ${x}_{3}$. That is, it is a measure of association between ${y}_{1}$ and ${y}_{2}$ conditional upon fixed values of ${x}_{3}$. 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 ${n}_{y}$ variables in $Y$ and ${n}_{x}$ variables in $X$ and let the variance-covariance matrix of all ${n}_{y}+{n}_{x}$ variables be partitioned into,
 $Σxx Σxy Σyx Σyy .$
The variance-covariance of $Y$ conditional on fixed values of the $X$ variables is given by:
 $Σy∣x=Σyy-ΣyxΣxx -1Σxy.$
The partial correlation matrix is then computed by standardizing ${\Sigma }_{y\mid x}$,
 $diag⁡Σy∣x -12Σy∣xdiag⁡Σy∣x -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
 $r⁢n-nx-2 1-r2 ,$
which has approximately a Student's $t$-distribution with $n-{n}_{x}-2$ degrees of freedom, where $n$ is the number of observations from which the full correlation coefficients were computed.

## References

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

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{ny}$int64int32nag_int scalar
The number of $Y$ variables, ${n}_{y}$, for which partial correlation coefficients are to be computed.
Constraint: ${\mathbf{ny}}\ge 2$.
2:     $\mathrm{nx}$int64int32nag_int scalar
The number of $X$ variables, ${n}_{x}$, which are to be considered as fixed.
Constraints:
• ${\mathbf{nx}}\ge 1$;
• ${\mathbf{ny}}+{\mathbf{nx}}\le {\mathbf{m}}$.
3:     $\mathrm{isz}\left({\mathbf{m}}\right)$int64int32nag_int array
Indicates which variables belong to set $X$ and $Y$.
${\mathbf{isz}}\left(i\right)<0$
The $\mathit{i}$th variable is a $Y$ variable, for $\mathit{i}=1,2,\dots ,{\mathbf{m}}$.
${\mathbf{isz}}\left(i\right)>0$
The $i$th variable is a $X$ variable.
${\mathbf{isz}}\left(i\right)=0$
The $i$th variable is not included in the computations.
Constraints:
• exactly ny elements of isz must be $\text{}<0$;
• exactly nx elements of isz must be $\text{}>0$.
4:     $\mathrm{r}\left(\mathit{ldr},{\mathbf{m}}\right)$ – double array
ldr, the first dimension of the array, must satisfy the constraint $\mathit{ldr}\ge {\mathbf{m}}$.
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:     $\mathrm{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: ${\mathbf{m}}\ge 3$.

### Output Parameters

1:     $\mathrm{p}\left(\mathit{ldp},{\mathbf{ny}}\right)$ – double array
The strict upper triangle of p contains the strict upper triangular part of the ${n}_{y}$ by ${n}_{y}$ partial correlation matrix. The lower triangle contains the lower triangle of the ${n}_{y}$ by ${n}_{y}$ 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:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{m}}<3$, or ${\mathbf{ny}}<2$, or ${\mathbf{nx}}<1$, or ${\mathbf{ny}}+{\mathbf{nx}}>{\mathbf{m}}$, or $\mathit{ldr}<{\mathbf{m}}$, or $\mathit{ldp}<{\mathbf{ny}}$.
${\mathbf{ifail}}=2$
 On entry, there are not exactly ny elements of ${\mathbf{isz}}<0$, or there are not exactly nx elements of ${\mathbf{isz}}>0$.
${\mathbf{ifail}}=3$
On entry, the variance-covariance/correlation matrix of the $X$ variables, ${\Sigma }_{xx}$, is not of full rank. Try removing some of the $X$ variables by setting the appropriate element of ${\mathbf{isz}}=0$.
${\mathbf{ifail}}=4$
Either a diagonal element of the partial variance-covariance matrix, ${\Sigma }_{y\mid x}$, 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.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

nag_correg_corrmat_partial (g02by) computes the partial variance-covariance matrix, ${\Sigma }_{y\mid x}$, by computing the Cholesky factorization of ${\Sigma }_{xx}$. If ${\Sigma }_{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).

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

## Example

Data, given by Osborn (1979), on the number of deaths, smoke ($\mathrm{mg}/{\mathrm{m}}^{3}$) 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);

fprintf('\n');
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
```

Chapter Contents
Chapter Introduction
NAG Toolbox

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