4
$\begingroup$

I am interested to know if there are built-in Mathematica functions that performs partial and semipartial computations.

If not, what would be a simple and efficient way to compute them from the results of a LinearModelFit?

$\endgroup$
2
  • $\begingroup$ The simplest way would be to use RLink and call the functions in the R package ppcor. Alternatively using functions in Mathematica are pretty simple, too. See the description of parial and semipartial correlation at faculty.cas.usf.edu/mbrannick/regression/Part3/Partials.html. $\endgroup$
    – JimB
    Jun 28, 2019 at 22:53
  • $\begingroup$ Thanks JimB. I am not quite sure that installing a second software and establishing links between the two is the simplest way. However, it sure is a useful way to crossvalidate results. $\endgroup$ Jun 30, 2019 at 13:17

1 Answer 1

6
$\begingroup$

Mathematica has a PartialCorrelation function but that is for time series data. However by following the information in Partial and semipartial correlation you can use some simple Mathematica commands.

(* Data *)
SATV = {500, 550, 450, 400, 600, 650, 700, 550, 650, 550};
HSGPA = {3.0, 3.2, 2.8, 2.5, 3.2, 3.8, 3.9, 3.8, 3.5, 3.1};
FGPA = {2.8, 3.0, 2.8, 2.2, 3.3, 3.3, 3.5, 3.7, 3.4, 2.9};
data = Transpose[{SATV, HSGPA, FGPA}];

(* Find residuals for the two regressions on SATV *)
resid1 = LinearModelFit[data[[All, {1, 2}]], x, x]["FitResiduals"];
resid2 = LinearModelFit[data[[All, {1, 3}]], x, x]["FitResiduals"];

(* Partial correlation *)
Correlation[resid1, resid2]
(* 0.7475739092548284 *)

(* Semipartial correlation *)
Correlation[FGPA, resid1]
(* 0.43378526772255077 *)

The results match exactly to the R example in the above link.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.