g02 Chapter Contents
g02 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_partial_corr (g02byc)

## 1  Purpose

nag_partial_corr (g02byc) computes a partial correlation/variance-covariance matrix from a correlation or variance-covariance matrix computed by nag_corr_cov (g02bxc).

## 2  Specification

 #include #include
 void nag_partial_corr (Integer m, Integer ny, Integer nx, const Integer sz[], const double r[], Integer tdr, double p[], Integer tdp, NagError *fail)

## 3  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:
 $r 12 - r 13 r 23 1 - r 13 2 1 - r 23 2 ,$
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 $\left(-1,1\right)$ 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 - 1 2 Σ y∣x diag Σ y∣x - 1 2 .$
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-n x - 2 1 - r 2$
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.

## 4  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

## 5  Arguments

1:     mIntegerInput
On entry: the number of variables in the variance-covariance/correlation matrix given in r.
Constraint: ${\mathbf{m}}\ge 3$.
2:     nyIntegerInput
On entry: the number of $Y$ variables, ${n}_{y}$, for which partial correlation coefficients are to be computed.
Constraint: ${\mathbf{ny}}\ge 2$.
3:     nxIntegerInput
On entry: 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}}$.
4:     sz[m]const IntegerInput
On entry: indicates which variables belong to set $X$ and $Y$.
sz$\left(i\right)<0$
The $\mathit{i}$th variable is a $Y$ variable, for $\mathit{i}=1,2,\dots ,{\mathbf{m}}$.
sz$\left(i\right)>0$
The $i$th variable is a $X$ variable.
sz$\left(i\right)=0$
The $i$th variable is not included in the computations.
Constraints:
• exactly ny elements of sz must be $<0$,
• exactly nx elements of sz must be $>0$.
5:     r[${\mathbf{m}}×{\mathbf{tdr}}$]const doubleInput
Note: the $\left(i,j\right)$th element of the matrix $R$ is stored in ${\mathbf{r}}\left[\left(i-1\right)×{\mathbf{tdr}}+j-1\right]$.
On entry: the variance-covariance or correlation matrix for the m variables as given by nag_corr_cov (g02bxc). Only the upper triangle need be given.
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.
6:     tdrIntegerInput
On entry: the stride separating matrix column elements in the array r.
Constraint: ${\mathbf{tdr}}\ge {\mathbf{m}}$.
7:     p[${\mathbf{ny}}×{\mathbf{tdp}}$]doubleOutput
Note: the $\left(i,j\right)$th element of the matrix $P$ is stored in ${\mathbf{p}}\left[\left(i-1\right)×{\mathbf{tdp}}+j-1\right]$.
On exit: 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 correlation matrix then the variance-covariance matrix is for standardized variables.
8:     tdpIntegerInput
On entry: the stride separating matrix column elements in the array p.
Constraint: ${\mathbf{tdp}}\ge {\mathbf{ny}}$.
9:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_2_INT_ARG_LT
On entry, ${\mathbf{tdp}}=〈\mathit{\text{value}}〉$ while ${\mathbf{ny}}=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{tdp}}\ge {\mathbf{ny}}$.
On entry, ${\mathbf{tdr}}=〈\mathit{\text{value}}〉$ while ${\mathbf{m}}=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{tdr}}\ge {\mathbf{m}}$.
NE_3_INT_ARG_CONS
On entry, ${\mathbf{ny}}=〈\mathit{\text{value}}〉$, ${\mathbf{nx}}=〈\mathit{\text{value}}〉$ and ${\mathbf{m}}=〈\mathit{\text{value}}〉$. These arguments must satisfy ${\mathbf{ny}}+{\mathbf{nx}}\le {\mathbf{m}}$.
NE_ALLOC_FAIL
Dynamic memory allocation failed.
On entry, ${\mathbf{nx}}=〈\mathit{\text{value}}〉$ and there are not exactly nx values of ${\mathbf{sz}}<0$.
On entry, ${\mathbf{ny}}=〈\mathit{\text{value}}〉$ and there are not exactly ny values of ${\mathbf{sz}}<0$.
Number of values of ${\mathbf{sz}}<0=〈\mathit{\text{value}}〉$.
NE_COR_MAT_POSDEF
Either a diagonal element of the partial variance-covariance matrix 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.
NE_COR_MAT_RANK
On entry, either the variance-covariance matrix or the correlation matrix is not of full rank. Try removing some of the nx variables by setting the appropriate elements of sz to zero.
NE_INT_ARG_LT
On entry, ${\mathbf{m}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{m}}\ge 3$.
On entry, ${\mathbf{nx}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{nx}}\ge 1$.
On entry, ${\mathbf{ny}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ny}}\ge 2$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.

## 7  Accuracy

nag_partial_corr (g02byc) 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.

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

## 9  Example

Data, given by Osborn (1979), on the number of deaths, smoke $\left(mg/{m}^{3}\right)$ and sulphur dioxide (parts/million) during an intense period of fog is input. The correlations are computed using nag_corr_cov (g02bxc) and the partial correlation between deaths and smoke given sulphur dioxide is computed using nag_partial_corr (g02byc).

### 9.1  Program Text

Program Text (g02byce.c)

### 9.2  Program Data

Program Data (g02byce.d)

### 9.3  Program Results

Program Results (g02byce.r)