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.

Create three matrices containing the sample data.

`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 = *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.

Partial Correlation Coefficients

Weight Age
________ ________
BPTop -0.02568 0.12893
BPBottom 0.029168 0.047226

Weight Age
_______ _______
BPTop 0.80182 0.2058
BPBottom 0.77556 0.64424