Linear or rank partial correlation coefficients

returns
the sample linear partial correlation coefficients with additional
options specified by one or more name-value pair arguments, using
input arguments from any of the previous syntaxes. For example, you
can specify whether to use Pearson or Spearman partial correlations,
or specify how to treat missing values.`rho`

= partialcorr(___,`Name,Value`

)

Compute partial correlation coefficients between pairs of variables in the input matrix.

Load the sample data. Convert the genders in `hospital.Sex`

to numeric group identifiers.

```
load hospital;
hospital.SexID = grp2idx(hospital.Sex);
```

Create an input matrix containing the sample data.

x = [hospital.SexID hospital.Age hospital.Smoker hospital.Weight];

Each row in `x`

contains a patient’s gender, age, smoking status, and weight.

Compute partial correlation coefficients between pairs of variables in `x`

, while controlling for the effects of the remaining variables in `x`

.

rho = partialcorr(x)

`rho = `*4×4*
1.0000 -0.0105 0.0273 0.9421
-0.0105 1.0000 0.0419 0.0369
0.0273 0.0419 1.0000 0.0451
0.9421 0.0369 0.0451 1.0000

The matrix `rho`

indicates, for example, a correlation of 0.9421 between gender and weight after controlling for all other variables in `x`

. You can return the $$p$$-values as a second output, and examine them to confirm whether these correlations are statistically significant.

For a clearer display, create a table with appropriate variable and row labels.

rho = array2table(rho, ... 'VariableNames',{'SexID','Age','Smoker','Weight'},... 'RowNames',{'SexID','Age','Smoker','Weight'}); disp('Partial Correlation Coefficients')

Partial Correlation Coefficients

disp(rho)

SexID Age Smoker Weight ________ ________ ________ ________ SexID 1 -0.01052 0.027324 0.9421 Age -0.01052 1 0.041945 0.036873 Smoker 0.027324 0.041945 1 0.045106 Weight 0.9421 0.036873 0.045106 1

Test for partial correlation between pairs of variables in the input matrix, while controlling for the effects of a second set of variables.

Load the sample data. Convert the genders in `hospital.Sex`

to numeric group identifiers.

```
load hospital;
hospital.SexID = grp2idx(hospital.Sex);
```

Create two matrices containing the sample data.

x = [hospital.Age hospital.BloodPressure]; z = [hospital.SexID hospital.Smoker hospital.Weight];

The `x`

matrix contains the variables to test for partial correlation. The `z`

matrix contains the variables to control for. The measurements for `BloodPressure`

are contained in two columns: The first column contains the upper (systolic) number, and the second column contains the lower (diastolic) number. `partialcorr`

treats each column as a separate variable.

Test for partial correlation between pairs of variables in `x`

, while controlling for the effects of the variables in `z`

. Compute the correlation coefficients.

[rho,pval] = partialcorr(x,z)

`rho = `*3×3*
1.0000 0.1300 0.0462
0.1300 1.0000 0.0012
0.0462 0.0012 1.0000

`pval = `*3×3*
0 0.2044 0.6532
0.2044 0 0.9903
0.6532 0.9903 0

The large values in `pval`

indicate that there is no significant correlation between age and either blood pressure measurement after controlling for gender, smoking status, and weight.

For a clearer display, create tables with appropriate variable and row labels.

rho = array2table(rho, ... 'VariableNames',{'Age','BPTop','BPBottom'},... 'RowNames',{'Age','BPTop','BPBottom'}); pval = array2table(pval, ... 'VariableNames',{'Age','BPTop','BPBottom'},... 'RowNames',{'Age','BPTop','BPBottom'}); disp('Partial Correlation Coefficients')

Partial Correlation Coefficients

disp(rho)

Age BPTop BPBottom ________ _________ _________ Age 1 0.13 0.046202 BPTop 0.13 1 0.0012475 BPBottom 0.046202 0.0012475 1

`disp('p-values')`

p-values

disp(pval)

Age BPTop BPBottom _______ _______ ________ Age 0 0.20438 0.65316 BPTop 0.20438 0 0.99032 BPBottom 0.65316 0.99032 0

Test for partial correlation between pairs of variables in the `x`

and `y`

input matrices, while controlling for the effects of a third set of variables.

Load the sample data. Convert the genders in `hospital.Sex`

to numeric group identifiers.

```
load hospital;
hospital.SexID = grp2idx(hospital.Sex);
```

Create three matrices containing the sample data.

x = [hospital.BloodPressure]; y = [hospital.Weight hospital.Age]; z = [hospital.SexID hospital.Smoker];

`partialcorr`

can test for partial correlation between the pairs of variables in `x`

(the systolic and diastolic blood pressure measurements) and `y`

(weight and age), while controlling for the variables in `z`

(gender and smoking status). The measurements for `BloodPressure`

are contained in two columns: The first column contains the upper (systolic) number, and the second column contains the lower (diastolic) number. `partialcorr`

treats each column as a separate variable.

Test for partial correlation between pairs of variables in `x`

and `y`

, while controlling for the effects of the variables in `z`

. Compute the correlation coefficients.

[rho,pval] = partialcorr(x,y,z)

`rho = `*2×2*
-0.0257 0.1289
0.0292 0.0472

`pval = `*2×2*
0.8018 0.2058
0.7756 0.6442

The results in `pval`

indicate that, after controlling for gender and smoking status, there is no significant correlation between either of a patient’s blood pressure measurements and that patient’s weight or age.

For a clearer display, create tables with appropriate variable and row labels.

rho = array2table(rho, ... 'RowNames',{'BPTop','BPBottom'},... 'VariableNames',{'Weight','Age'}); pval = array2table(pval, ... 'RowNames',{'BPTop','BPBottom'},... 'VariableNames',{'Weight','Age'}); disp('Partial Correlation Coefficients')

Partial Correlation Coefficients

disp(rho)

Weight Age ________ ________ BPTop -0.02568 0.12893 BPBottom 0.029168 0.047226

`disp('p-values')`

p-values

disp(pval)

Weight Age _______ _______ BPTop 0.80182 0.2058 BPBottom 0.77556 0.64424

Test the hypothesis that pairs of variables have no correlation, against the alternative hypothesis that the correlation is greater than 0.

Load the sample data. Convert the genders in `hospital.Sex`

to numeric group identifiers.

```
load hospital;
hospital.SexID = grp2idx(hospital.Sex);
```

Create three matrices containing the sample data.

x = [hospital.BloodPressure]; y = [hospital.Weight hospital.Age]; z = [hospital.SexID hospital.Smoker];

`partialcorr`

can test for partial correlation between the pairs of variables in `x`

(the systolic and diastolic blood pressure measurements) and `y`

(weight and age), while controlling for the variables in `z`

(gender and smoking status). The measurements for `BloodPressure`

are contained in two columns: The first column contains the upper (systolic) number, and the second column contains the lower (diastolic) number. `partialcorr`

treats each column as a separate variable.

Compute the correlation coefficients using a right-tailed test.

[rho,pval] = partialcorr(x,y,z,'Tail','right')

`rho = `*2×2*
-0.0257 0.1289
0.0292 0.0472

`pval = `*2×2*
0.5991 0.1029
0.3878 0.3221

The results in `pval`

indicate that `partialcorr`

does not reject the null hypothesis of nonzero correlations between the variables in `x`

and `y`

, after controlling for the variables in `z`

, when the alternative hypothesis is that the correlations are greater than 0.

For a clearer display, create tables with appropriate variable and row labels.

rho = array2table(rho, ... 'RowNames',{'BPTop','BPBottom'},... 'VariableNames',{'Weight','Age'}); pval = array2table(pval, ... 'RowNames',{'BPTop','BPBottom'},... 'VariableNames',{'Weight','Age'}); disp('Partial Correlation Coefficients')

Partial Correlation Coefficients

disp(rho)

Weight Age ________ ________ BPTop -0.02568 0.12893 BPBottom 0.029168 0.047226

`disp('p-values')`

p-values

disp(pval)

Weight Age _______ _______ BPTop 0.59909 0.1029 BPBottom 0.38778 0.32212

`x`

— Data matrixmatrix

Data matrix, specified as an *n*-by-*p*_{x} matrix.
The rows of `x`

correspond to observations, and the
columns correspond to variables.

**Data Types: **`single`

| `double`

`y`

— Data matrixmatrix

Data matrix, specified as an *n*-by-*p*_{y} matrix.
The rows of `y`

correspond to observations, and the
columns correspond to variables.

**Data Types: **`single`

| `double`

`z`

— Data matrixmatrix

Data matrix, specified as an *n*-by-*p*_{z} matrix.
The rows of `z`

correspond to observations, and columns
correspond to variables.

**Data Types: **`single`

| `double`

Specify optional
comma-separated pairs of `Name,Value`

arguments. `Name`

is
the argument name and `Value`

is the corresponding value.
`Name`

must appear inside quotes. You can specify several name and value
pair arguments in any order as
`Name1,Value1,...,NameN,ValueN`

.

`'Type','Spearman','Rows','complete'`

computes
Spearman partial correlations using only the data in rows that contain
no missing values.`'Type'`

— Type of partial correlations`'Pearson'`

(default) | `'Spearman'`

Type of partial correlations to compute, specified as the comma-separated
pair consisting of `'Type'`

and one of the following.

`'Pearson'` | Compute Pearson (linear) partial correlations. |

`'Spearman'` | Compute Spearman (rank) partial correlations. |

**Example: **`'Type','Spearman'`

`'Rows'`

— Rows to use in computation`'all'`

(default) | `'complete'`

| `'pairwise'`

Rows to use in computation, specified as the comma-separated
pair consisting of `'Rows'`

and one of the following.

`'all'` | Use all rows of the input regardless of missing
values (`NaN` s). |

`'complete'` | Use only rows of the input with no missing values. |

`'pairwise'` | Compute `rho(i,j)` using rows with
no missing values in column `i` or
`j` . |

**Example: **`'Rows','complete'`

`'Tail'`

— Alternative hypothesis`'both'`

(default) | `'right'`

| `'left'`

Alternative hypothesis to test against, specified as the comma-separated
pair consisting of `'Tail'`

and one of the following.

`'both'` | Test the alternative hypothesis that the correlation is not 0. |

`'right'` | Test the alternative hypothesis that the correlation is greater than 0. |

`'left'` | Test the alternative hypothesis that the correlation is less than 0. |

**Example: **`'Tail','right'`

`rho`

— Sample linear partial correlation coefficientsmatrix

Sample linear partial correlation coefficients, returned as a matrix.

If you input only an

`x`

matrix,`rho`

is a symmetric*p*_{x}-by-*p*_{x}matrix. The (*i*,*j*)th entry is the sample linear partial correlation between the*i*-th and*j*-th columns in`x`

.If you input

`x`

and`z`

matrices,`rho`

is a symmetric*p*_{x}-by-*p*_{x}matrix. The (*i*,*j*)th entry is the sample linear partial correlation between the*i*th and*j*th columns in`x`

, controlled for the variables in`z`

.If you input

`x`

,`y`

, and`z`

matrices,`rho`

is a*p*_{x}-by-*p*_{y}matrix, where the (*i*,*j*)th entry is the sample linear partial correlation between the*i*th column in`x`

and the*j*th column in`y`

, controlled for the variables in`z`

.

If the covariance matrix of `[x,z]`

is

$$S=\left(\begin{array}{cc}{S}_{xx}& {S}_{xz}\\ {S}_{xz}{}^{T}& {S}_{zz}\end{array}\right)\text{\hspace{0.17em}},$$

then the partial correlation matrix of
`x`

, controlling for `z`

, can be
defined formally as a normalized version of the covariance matrix:
*S*_{xx} –
(*S*_{xz}*S*_{zz}^{–1}*S*_{xz}^{T}).

`pval`

— matrix

*p*-values, returned as a matrix. Each element
of `pval`

is the *p*-value for the
corresponding element of `rho`

.

If `pval(i,j)`

is small, then the corresponding
partial correlation `rho(i,j)`

is statistically significantly
different from 0.

`partialcorr`

computes *p*-values
for linear and rank partial correlations using a Student's *t* distribution
for a transformation of the correlation. This is exact for linear
partial correlation when `x`

and `z`

are
normal, but is a large-sample approximation otherwise.

`corr`

| `corrcoef`

| `partialcorri`

| `tiedrank`

A modified version of this example exists on your system. Do you want to open this version instead?

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

Select web siteYou can also select a web site from the following list:

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

- América Latina (Español)
- Canada (English)
- United States (English)

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)