MATLAB: How to plot partial correlation

correlationplot

Hello,
for my analysis I ran a couple of Pearson partial correlations, controlling for variables such as gender and age. Now I want to plot the correlation in a scatterplot. How would I do that? If I use plot(X,Y,'o') then I get only the normal and (not partialled out) correlation, right?
Thank you very much in advance

Best Answer

The partial correlation of X and Y controlling for some other variables [Z] is the correlation of rX with rY, where rX and rY are the residuals from two separate regression equations predicting X from [Z] and predicting Y from [Z] Wikipedia. If you wanted to represent that partial correlation in a plot, you would have to use fitlm to predict X and Y separately, and then get the residuals from those two fits (see Save residuals) as rX and rY. Then you could use
plot(rX,rY,'o');
I'm not sure this plot will really be what you want, though, since the numbers will not be on the same scale as your original X and Y scores (i.e., they will have means of 0). Of course, a plot is just a display device, so maybe this type of display will be fine for you.
A side comment: It probably isn't a good idea to use partial correlation to control for gender as if it were a normally distributed numerical variable, which it isn't. To display the X/Y relationship controlling for gender, it would be better to make separate scatterplots for males versus females or to make a single scatterplot but use separate symbols for the two genders.
Related Question