6
$\begingroup$

For instance if I were trying to relate Age and Height, I would do something like this:

df <- data.frame(Age, Height)
cor(df)

How could I get Pearson's r value and the p-value for the relationship between Age and Height while accounting for the effect of Gender?

$\endgroup$
2
  • $\begingroup$ That was exactly what I needed. I had never heard the phrase "partial correlation" before. If you will propose that as the answer (preferably with an example of usage) I will accept it. $\endgroup$
    – Rilcon42
    Commented Sep 24, 2015 at 17:54
  • 2
    $\begingroup$ The problem here was not so much "how to use R" but how to find a correlation coefficient while taking another variable into account, which suggests it ought to be on-topic. (I wonder whether we have another thread on partial correlation that this duplicates.) $\endgroup$
    – Silverfish
    Commented Sep 24, 2015 at 21:49

1 Answer 1

8
$\begingroup$

This is called partial correlation, basically it, as Wikipedia notices,

measures the degree of association between two random variables, with the effect of a set of controlling random variables removed

Having correlation coefficients of three variables $X$, $Y$ and $Z$ we can correct correlation $\rho_{XY}$ by controlling correlations of $X$ and $Y$ with $Z$:

$$ \rho_{XY \cdot Z } = \frac{\rho_{XY} - \rho_{XZ}\rho_{ZY}} {\sqrt{(1-\rho_{XZ}^2) (1-\rho_{ZY}^2)}} $$

This is related to multiple linear regression. To test the hypothesis about partial correlation you use $t$-statistic in similar fashion as with regular correlation but with $N-3$ degrees of freedom. The same formula can be used for Pearson's or Spearman's correlation coefficients (for more see Altman, 1991 or Revelle, n.d.).

There are multiple R functions and libraries that enable you to calculate partial correlations like pcor, ggm or psych.


Altman, D.G. (1991). Practical Statistics for Medical Research. Chapman and Hall, pp. 288-299.

Revelle, W. (n.d.). Multiple Correlation and Multiple Regression In: An introduction to psychometric theory with applications in R.

$\endgroup$
1
  • $\begingroup$ I think this could be on topic if it is more about how this can be done / what it means, as opposed to what R code to use. Can you say more about what kind of thing a partial correlation is & how it works? $\endgroup$ Commented Sep 24, 2015 at 18:10

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.