Partial correlations are great in that you can perform a correlation between two continuous variables whilst controlling for various confounders. However, the partial correlation option in SPSS is defaulted to performing a Pearson’s partial correlation which assumes normality of the two variables of interest.
But what if you want to perform a Spearman’s partial correlation on non-normally distributed data?
If you go to
Analyze > Correlate > Partial … you will see that there is no option to select a Spearman correlation. There is, however, a way around this using a little coding.
In this guide, I will explain how to perform a non-parametric, partial correlation in SPSS.
The required dataset
To be able to conduct a Spearman partial correlation in SPSS, you need a dataset, of course. For our example, we have the age and weight of 20 volunteers, as well as gender. What we want to test is if there is a correlation between age and weight, after controlling for gender.
For this to work, you need to enter a small piece of script into the SPSS Syntax Editor. Open up the Syntax Editor by going to
File > New > Syntax.
Next, copy and paste the following code:
NONPAR CORR /MISSING = LISTWISE /MATRIX OUT(*). RECODE rowtype_ ('RHO'='CORR') . PARTIAL CORR /significance = twotail /MISSING = LISTWISE /MATRIX IN(*).
You now need to add the appropriate variables next to the
NONPAR CORR and
PARTIAL CORR sections.
So, next to the
NONPAR CORR enter all of the variables that will be involved in the partial correlation. In our example, this would be Age, Weight and Gender.
PARTIAL CORR line you need to enter the two variables of interest in the correlation followed by a
BY then the variables you want to control for. Make sure all of the variables you enter match the ones in your file correctly, otherwise the script will fail.
Here is what our example will look like:
NONPAR CORR Age Weight Gender /MISSING = LISTWISE /MATRIX OUT(*). RECODE rowtype_ ('RHO'='CORR') . PARTIAL CORR Age Weight BY Gender /significance = twotail /MISSING = LISTWISE /MATRIX IN(*).
And here is what it looks like in the Syntax Editor:
The script itself is separated into 3 parts:
The first is to perform a Spearman bivariate correlation for all variables and to add the Spearman rank correlation coefficients into a new file.
RECODE converts the row type from a Spearman (RHO) to a Pearson (CORR).
PARTIAL CORR performs the partial correlation on the desired variables by using the newly created Spearman correlation coefficients from the
NONPAR CORR script.
Here is how to run the script:
1. To run the script, go to the Syntax Editor and with the
NONPAR CORR section selected, hit the green play button.
You will also notice that a new SPSS data file has been created and is now open. This is usually named ‘Untitled’, or something similar. Within this file, you will see the Spearman’s rho values and n numbers for each correlation.
2. You next need to go back to the Syntax Editor window and run the
RECODE part of the script. Make sure you select the new dataset as the active worksheet for this, as you want to perform the
RECODE on the new sheet. You can toggle between datasets by clicking on the drop-down menu next to
Active:. In this case, we select the
3. Finally, still in the Syntax window, select the
PARTIAL CORR code and run this on the same
Unnamed dataset. This will perform the final partial correlation.
By looking in the output file, you should now see a
Partial Corr box which contains the partial correlation coefficients and P values for the test:
Therefore, there is not a significant correlation for age and weight after accounting for gender.