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 strings 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 =
1.0000 0.1300 0.0462
0.1300 1.0000 0.0012
0.0462 0.0012 1.0000
pval =
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',{'SexID','Smoker','Weight'});
pval = array2table(pval, ...
'VariableNames',{'Age','BPTop','BPBottom'},...
'RowNames',{'SexID','Smoker','Weight'});
disp('Partial Correlation Coefficients')
disp(rho)
disp('p-values')
disp(pval)

Partial Correlation Coefficients
Age BPTop BPBottom
-------- --------- ---------
SexID 1 0.13 0.046202
Smoker 0.13 1 0.0012475
Weight 0.046202 0.0012475 1
p-values
Age BPTop BPBottom
------- ------- --------
SexID 0 0.20438 0.65316
Smoker 0.20438 0 0.99032
Weight 0.65316 0.99032 0