# NAG CL Interfaceg02byc (corrmat_​partial)

## 1Purpose

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

## 2Specification

 #include
 void g02byc (Integer m, Integer ny, Integer nx, const Integer sz[], const double r[], Integer tdr, double p[], Integer tdp, NagError *fail)
The function may be called by the names: g02byc, nag_correg_corrmat_partial or nag_partial_corr.

## 3Description

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.

## 4References

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

## 5Arguments

1: $\mathbf{m}$Integer Input
On entry: the number of variables in the variance-covariance/correlation matrix given in r.
Constraint: ${\mathbf{m}}\ge 3$.
2: $\mathbf{ny}$Integer Input
On entry: the number of $Y$ variables, ${n}_{y}$, for which partial correlation coefficients are to be computed.
Constraint: ${\mathbf{ny}}\ge 2$.
3: $\mathbf{nx}$Integer Input
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: $\mathbf{sz}\left[{\mathbf{m}}\right]$const Integer Input
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: $\mathbf{r}\left[{\mathbf{m}}×{\mathbf{tdr}}\right]$const double Input
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 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: $\mathbf{tdr}$Integer Input
On entry: the stride separating matrix column elements in the array r.
Constraint: ${\mathbf{tdr}}\ge {\mathbf{m}}$.
7: $\mathbf{p}\left[{\mathbf{ny}}×{\mathbf{tdp}}\right]$double Output
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: $\mathbf{tdp}$Integer Input
On entry: the stride separating matrix column elements in the array p.
Constraint: ${\mathbf{tdp}}\ge {\mathbf{ny}}$.
9: $\mathbf{fail}$NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

## 6Error 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.
NE_BAD_NX_SET
On entry, ${\mathbf{nx}}=〈\mathit{\text{value}}〉$ and there are not exactly nx values of ${\mathbf{sz}}<0$.
NE_BAD_NY_SET
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 $1$. 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.

## 7Accuracy

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.

## 8Parallelism and Performance

g02byc is not threaded in any implementation.

## 9Further Comments

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

## 10Example

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 g02bxc and the partial correlation between deaths and smoke given sulphur dioxide is computed using g02byc.

### 10.1Program Text

Program Text (g02byce.c)

### 10.2Program Data

Program Data (g02byce.d)

### 10.3Program Results

Program Results (g02byce.r)