# Syntax

C# |
---|

public static void g02by( int m, int ny, int nx, int[] isz, double[,] r, double[,] p, out int ifail ) |

Visual Basic |
---|

Public Shared Sub g02by ( _ m As Integer, _ ny As Integer, _ nx As Integer, _ isz As Integer(), _ r As Double(,), _ p As Double(,), _ <OutAttribute> ByRef ifail As Integer _ ) |

Visual C++ |
---|

public: static void g02by( int m, int ny, int nx, array<int>^ isz, array<double,2>^ r, array<double,2>^ p, [OutAttribute] int% ifail ) |

F# |
---|

static member g02by : m : int * ny : int * nx : int * isz : int[] * r : float[,] * p : float[,] * ifail : int byref -> unit |

#### Parameters

- m
- Type: System..::..Int32
*On entry*: the number of variables in the variance-covariance/correlation matrix given in r.*Constraint*: ${\mathbf{m}}\ge 3$.

- ny
- Type: System..::..Int32
*On entry*: the number of $Y$ variables, ${n}_{y}$, for which partial correlation coefficients are to be computed.*Constraint*: ${\mathbf{ny}}\ge 2$.

- nx
- Type: System..::..Int32
*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}}$.

- isz
- Type: array<System..::..Int32>[]()[][]An array of size [m]
*On entry*: indicates which variables belong to set $X$ and $Y$.- ${\mathbf{isz}}\left[i-1\right]<0$
- The $\mathit{i}$th variable is a $Y$ variable, for $\mathit{i}=1,2,\dots ,{\mathbf{m}}$.
- ${\mathbf{isz}}\left[i-1\right]>0$
- The $i$th variable is a $X$ variable.
- ${\mathbf{isz}}\left[i-1\right]=0$
- The $i$th variable is not included in the computations.

- r
- Type: array<System..::..Double,2>[,](,)[,][,]An array of size [dim1, m]
**Note:**dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{m}}$*On entry*: the variance-covariance or correlation matrix for the m variables as given by 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 method.

- p
- Type: array<System..::..Double,2>[,](,)[,][,]An array of size [dim1, ny]
**Note:**dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{ny}}$*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 partial correlation matrix then the variance-covariance matrix is for standardized variables.

- ifail
- Type: System..::..Int32%
*On exit*: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

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

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.

$$\frac{{r}_{12}-{r}_{13}{r}_{23}}{\sqrt{\left(1-{r}_{13}^{2}\right)\left(1-{r}_{23}^{2}\right)}}\text{,}$$ |

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,

The variance-covariance of $Y$ conditional on fixed values of the $X$ variables is given by:

The partial correlation matrix is then computed by standardizing ${\Sigma}_{y\mid x}$,

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

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.

$$\left[\begin{array}{ll}{\Sigma}_{xx}& {\Sigma}_{xy}\\ {\Sigma}_{yx}& {\Sigma}_{yy}\end{array}\right]\text{.}$$ |

$${\Sigma}_{y\mid x}={\Sigma}_{yy}-{\Sigma}_{yx}{\Sigma}_{xx}^{-1}{\Sigma}_{xy}\text{.}$$ |

$$\mathrm{diag}\u200a{\left({\Sigma}_{y\mid x}\right)}^{-\frac{1}{2}}{\Sigma}_{y\mid x}\mathrm{diag}\u200a{\left({\Sigma}_{y\mid x}\right)}^{-\frac{1}{2}}\text{.}$$ |

$$r\sqrt{\frac{n-{n}_{x}-2}{1-{r}^{2}}}\text{,}$$ |

# References

Krzanowski W J (1990)

*Principles of Multivariate Analysis*Oxford University PressMorrison D F (1967)

*Multivariate Statistical Methods*McGraw–HillOsborn J F (1979)

*Statistical Exercises in Medical Research*BlackwellSnedecor G W and Cochran W G (1967)

*Statistical Methods*Iowa State University Press# Error Indicators and Warnings

Errors or warnings detected by the method:

Some error messages may refer to parameters that are dropped from this interface
(LDR, LDP) In these
cases, an error in another parameter has usually caused an incorrect value to be inferred.

- ${\mathbf{ifail}}=1$
On entry, ${\mathbf{m}}<3$, or ${\mathbf{ny}}<2$, or ${\mathbf{nx}}<1$, or ${\mathbf{ny}}+{\mathbf{nx}}>{\mathbf{m}}$,

- ${\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}}=-9000$
- An error occured, see message report.
- ${\mathbf{ifail}}=-6000$
- Invalid Parameters $\u2329\mathit{\text{value}}\u232a$
- ${\mathbf{ifail}}=-4000$
- Invalid dimension for array $\u2329\mathit{\text{value}}\u232a$
- ${\mathbf{ifail}}=-8000$
- Negative dimension for array $\u2329\mathit{\text{value}}\u232a$
- ${\mathbf{ifail}}=-6000$
- Invalid Parameters $\u2329\mathit{\text{value}}\u232a$

# Accuracy

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 (F07GDF not in this release).

# Parallelism and Performance

None.

# Further Comments

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