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)

## 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, y1${y}_{1}$, y2${y}_{2}$ and x3${x}_{3}$, the partial correlation coefficient between y1${y}_{1}$ and y2${y}_{2}$ given x3${x}_{3}$ is computed as:
 (r12 − r13r23)/(sqrt((1 − r132)(1 − r232))), $r12-r13r23 (1-r132)(1-r232) ,$
where rij${r}_{ij}$ is the product-moment correlation coefficient between variables with subscripts i$i$ and j$j$. The partial correlation coefficient is a measure of the linear association between y1${y}_{1}$ and y2${y}_{2}$ having eliminated the effect due to both y1${y}_{1}$ and y2${y}_{2}$ being linearly associated with x3${x}_{3}$. That is, it is a measure of association between y1${y}_{1}$ and y2${y}_{2}$ conditional upon fixed values of x3${x}_{3}$. Like the full correlation coefficients the partial correlation coefficient takes a value in the range (1,1$-1,1$) with the value 0$0$ indicating no association.
In general, let a set of variables be partitioned into two groups Y$Y$ and X$X$ with ny${n}_{y}$ variables in Y$Y$ and nx${n}_{x}$ variables in X$X$ and let the variance-covariance matrix of all ny + nx${n}_{y}+{n}_{x}$ variables be partitioned into,
 [ Σxx Σxy Σyx Σyy ]
.
$[ Σxx Σxy Σyx Σyy ] .$
The variance-covariance of Y$Y$ conditional on fixed values of the X$X$ variables is given by:
 Σy ∣ x = Σyy − ΣyxΣxx − 1Σxy. $Σy∣x=Σyy-ΣyxΣxx -1Σxy.$
The partial correlation matrix is then computed by standardizing Σyx${\Sigma }_{y\mid x}$,
 diag(Σy ∣ x) − (1/2)Σy ∣ xdiag(Σy ∣ x) − (1/2). $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$r$ is the computed partial correlation coefficient then the appropriate t$t$ statistic is
 r×sqrt((n − nx − 2)/(1 − r2)), $r⁢n-nx-2 1-r2 ,$
which has approximately a Student's t$t$-distribution with nnx2$n-{n}_{x}-2$ degrees of freedom, where n$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:     ny – int64int32nag_int scalar
The number of Y$Y$ variables, ny${n}_{y}$, for which partial correlation coefficients are to be computed.
Constraint: ny2${\mathbf{ny}}\ge 2$.
2:     nx – int64int32nag_int scalar
The number of X$X$ variables, nx${n}_{x}$, which are to be considered as fixed.
Constraints:
• nx1${\mathbf{nx}}\ge 1$;
• ny + nxm${\mathbf{ny}}+{\mathbf{nx}}\le {\mathbf{m}}$.
3:     isz(m) – int64int32nag_int array
m, the dimension of the array, must satisfy the constraint m3${\mathbf{m}}\ge 3$.
Indicates which variables belong to set X$X$ and Y$Y$.
isz(i) < 0${\mathbf{isz}}\left(i\right)<0$
The i$\mathit{i}$th variable is a Y$Y$ variable, for i = 1,2,,m$\mathit{i}=1,2,\dots ,{\mathbf{m}}$.
isz(i) > 0${\mathbf{isz}}\left(i\right)>0$
The i$i$th variable is a X$X$ variable.
isz(i) = 0${\mathbf{isz}}\left(i\right)=0$
The i$i$th variable is not included in the computations.
Constraints:
• exactly ny elements of isz must be < 0$\text{}<0$;
• exactly nx elements of isz must be > 0$\text{}>0$.
4:     r(ldr,m) – double array
ldr, the first dimension of the array, must satisfy the constraint ldrm$\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:     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${\mathbf{m}}\ge 3$.

ldr ldp wk

### Output Parameters

1:     p(ldp,ny) – double array
ldpny$\mathit{ldp}\ge {\mathbf{ny}}$.
The strict upper triangle of p contains the strict upper triangular part of the ny${n}_{y}$ by ny${n}_{y}$ partial correlation matrix. The lower triangle contains the lower triangle of the ny${n}_{y}$ by ny${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:     ifail – int64int32nag_int scalar
${\mathrm{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:
ifail = 1${\mathbf{ifail}}=1$
 On entry, m < 3${\mathbf{m}}<3$, or ny < 2${\mathbf{ny}}<2$, or nx < 1${\mathbf{nx}}<1$, or ny + nx > m${\mathbf{ny}}+{\mathbf{nx}}>{\mathbf{m}}$, or ldr < m$\mathit{ldr}<{\mathbf{m}}$, or ldp < ny$\mathit{ldp}<{\mathbf{ny}}$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, there are not exactly ny elements of isz < 0${\mathbf{isz}}<0$, or there are not exactly nx elements of isz > 0${\mathbf{isz}}>0$.
ifail = 3${\mathbf{ifail}}=3$
On entry, the variance-covariance/correlation matrix of the X$X$ variables, Σxx${\Sigma }_{xx}$, is not of full rank. Try removing some of the X$X$ variables by setting the appropriate element of isz = 0${\mathbf{isz}}=0$.
ifail = 4${\mathbf{ifail}}=4$
Either a diagonal element of the partial variance-covariance matrix, Σyx${\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.

## Accuracy

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

```function nag_correg_corrmat_partial_example
ny = int64(2);
nx = int64(1);
isz = [int64(-1);-1;1];
r = [17053.69523809524, 152.8584285714286, 45.94742857142857;
152.8584285714286, 2.397368571428571, 0.6475057142857144;
45.94742857142857, 0.6475057142857144, 0.1793171428571428];
[p, ifail] = nag_correg_corrmat_partial(ny, nx, isz, r)
```
```

p =

1.0e+03 *

5.2803   -0.0007
-0.0131    0.0001

ifail =

0

```
```function g02by_example
ny = int64(2);
nx = int64(1);
isz = [int64(-1);-1;1];
r = [17053.69523809524, 152.8584285714286, 45.94742857142857;
152.8584285714286, 2.397368571428571, 0.6475057142857144;
45.94742857142857, 0.6475057142857144, 0.1793171428571428];
[p, ifail] = g02by(ny, nx, isz, r)
```
```

p =

1.0e+03 *

5.2803   -0.0007
-0.0131    0.0001

ifail =

0

```

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–2013