# partialcorri

Partial correlation coefficients adjusted for internal variables

## Syntax

## Description

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`

= partialcorri(___,`Name,Value`

)

## Examples

### Compute Partial Correlation Coefficients

Compute partial correlation coefficients for each pair of variables in the `x`

and `y`

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

.

Load the sample data.

`load carsmall;`

The data contains measurements from cars manufactured in 1970, 1976, and 1982. It includes `MPG`

and `Acceleration`

as performance measures, and `Displacement`

, `Horsepower`

, and `Weight`

as design variables. `Acceleration`

is the time required to accelerate from 0 to 60 miles per hour, so a high value for `Acceleration`

corresponds to a vehicle with low acceleration.

Define the input matrices. The `y`

matrix includes the performance measures, and the `x`

matrix includes the design variables.

y = [MPG,Acceleration]; x = [Displacement,Horsepower,Weight];

Compute the correlation coefficients. Include only rows with no missing values in the computation.

rho = partialcorri(y,x,'Rows','complete')

`rho = `*2×3*
-0.0537 -0.1520 -0.4856
-0.3994 -0.4008 0.4912

The results suggest, for example, a 0.4912 correlation between weight and acceleration after controlling for the effects of displacement and horsepower. 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',{'Displacement','Horsepower','Weight'}, ... 'RowNames',{'MPG','Acceleration'}); disp('Partial Correlation Coefficients')

Partial Correlation Coefficients

disp(rho)

Displacement Horsepower Weight ____________ __________ ________ MPG -0.053684 -0.15199 -0.48563 Acceleration -0.39941 -0.40075 0.49123

### Test Partial Correlations While Controlling for Additional Variables

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

and `y`

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

plus additional variables in matrix `z`

.

Load the sample data.

`load carsmall;`

The data contains measurements from cars manufactured in 1970, 1976, and 1982. It includes `MPG`

and `Acceleration`

as performance measures, and `Displacement`

, `Horsepower`

, and `Weight`

as design variables. `Acceleration`

is the time required to accelerate from 0 to 60 miles per hour, so a high value for `Acceleration`

corresponds to a vehicle with low acceleration.

Create a new variable `Headwind`

, and randomly generate data to represent the notion of an average headwind along the performance measurement route.

rng(0,"twister"); % For reproducibility Headwind = (10:-0.2:-9.8)' + 5*randn(100,1);

Since headwind can affect the performance measures, control for its effects when testing for partial correlation between the remaining variables.

Define the input matrices. The `y`

matrix includes the performance measures, and the `x`

matrix includes the design variables. The `z`

matrix contains additional variables to control for when computing the partial correlations, such as headwind.

y = [MPG,Acceleration]; x = [Displacement,Horsepower,Weight]; z = Headwind;

Compute the partial correlation coefficients. Include only rows with no missing values in the computation.

`[rho,pval] = partialcorri(y,x,z,Rows="complete")`

`rho = `*2×3*
0.0572 -0.1055 -0.5736
-0.3845 -0.3966 0.4674

`pval = `*2×3*
0.5923 0.3221 0.0000
0.0002 0.0001 0.0000

The small returned $$p$$-value of 0.0001 in `pval`

indicates, for example, a significant negative correlation between horsepower and acceleration, after controlling for displacement, weight, and headwind.

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

rho = array2table(rho, ... VariableNames={'Displacement','Horsepower','Weight'}, ... RowNames={'MPG','Acceleration'}); pval = array2table(pval, ... VariableNames={'Displacement','Horsepower','Weight'}, ... RowNames={'MPG','Acceleration'}); disp("Partial Correlation Coefficients, Accounting for Headwind")

Partial Correlation Coefficients, Accounting for Headwind

disp(rho)

Displacement Horsepower Weight ____________ __________ ________ MPG 0.057197 -0.10555 -0.57358 Acceleration -0.38452 -0.39658 0.4674

`disp("p-values, Accounting for Headwind")`

p-values, Accounting for Headwind

disp(pval)

Displacement Horsepower Weight ____________ __________ __________ MPG 0.59233 0.32212 3.4401e-09 Acceleration 0.00018272 0.00010902 3.4091e-06

## Input Arguments

`x`

— Data matrix

matrix

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 matrix

matrix

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 matrix

matrix

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

correspond to observations, and the
columns correspond to variables.

**Data Types: **`single`

| `double`

### Name-Value Arguments

Specify optional pairs of arguments as
`Name1=Value1,...,NameN=ValueN`

, where `Name`

is
the argument name and `Value`

is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.

*
Before R2021a, use commas to separate each name and value, and enclose*
`Name`

*in quotes.*

**Example: **`'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 either `'Pearson'`

or `'Spearman'`

. `Pearson`

computes
the Pearson (linear) partial correlations. `Spearman`

computes
the 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 regardless of missing `(NaN)` values. |

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

`'pairwise'` | Use all available values in each column of `y` when
computing the partial correlation coefficients and p-values
corresponding to that column. For each column of `y` ,
rows will be dropped corresponding to missing values in `x` (and/or `z` ,
if supplied). However, remaining rows with valid values in that column
of `y` are used, even if there are missing values
in other columns of `y` . |

**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 zero. |

`'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'`

## Output Arguments

`rho`

— Sample linear partial correlation coefficients

matrix

Sample linear partial correlation coefficients, returned as
a *p*_{y}-by-*p*_{x} matrix.

If you input

`x`

and`y`

matrices, the (*i*,*j*)th entry is the sample linear partial correlation between the*i*th column in`y`

and the*j*th column in`x`

, controlled for all the columns of`x`

except column*j*.If you input

`x`

,`y`

, and`z`

matrices, the (*i*,*j*)th entry is the sample linear partial correlation between the*i*th column in`y`

and the*j*th column in`x`

, adjusted for all the columns of`x`

except column*j*, after first controlling both`x`

and`y`

for the variables in`z`

.

`pval`

— *p*-values

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 zero.

`partialcorri`

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.

## References

[1] Stuart, Alan, K. Ord, and S.
Arnold. *Kendall's Advanced Theory of Statistics.* 6th edition,
Volume 2A, Chapter 28, Wiley, 2004.

[2] Fisher, Ronald A. "The
Distribution of the Partial Correlation Coefficient." *Metron* 3
(1924): 329-332

## Extended Capabilities

### Thread-Based Environment

Run code in the background using MATLAB® `backgroundPool`

or accelerate code with Parallel Computing Toolbox™ `ThreadPool`

.

This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.

## Version History

**Introduced in R2013b**

## See Also

## MATLAB Command

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.

Select a Web Site

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

You can also select a web site from the following list:

## How to Get Best Site Performance

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

### Americas

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

### Europe

- 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)