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('default); % 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 =
0.0572 -0.1055 -0.5736
-0.3845 -0.3966 0.4674
pval =
0.5923 0.3221 0.0000
0.0002 0.0001 0.0000

The small returned *p*-value of 0.001 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')
disp(rho)
disp('p-values, Accounting for Headwind')
disp(pval)

Partial Correlation Coefficients, Accounting for Headwind
Displacement Horsepower Weight
------------ ---------- --------
MPG 0.057197 -0.10555 -0.57358
Acceleration -0.38452 -0.39658 0.4674
P-values, Accounting for Headwind
Displacement Horsepower Weight
------------ ---------- ----------
MPG 0.59233 0.32212 3.4401e-09
Acceleration 0.00018272 0.00010902 3.4091e-06