I know that we are able to use a partial correlation when we want to correlate X and Y but Z affects both of them and that we may use a semi-partial correlation when we want to correlate X and Y and we know that Z only affects X.
- In my case, I have two different "Zs"/third variables.The idea is the following: I want to correlate X1 and X2, but I know that Z1 is extremely correlated to X1 and that Z2 is extremely correlated to X2.
So, I'm not assuming that Z1 and Z2 are correlated to both X1 and X2 (as it would be via a partial correlation, right?) I'm not assuming that Z1 and Z2 only effects X1 or X2 (as it would be for a semi-partial)
To put it simpler:
Z1 is correlated to X1
Z2 is correlated to X2
I want to see if X1 and X2 are correlated controlling for the effects of Z1 on X1 and of Z2 on X2
Obs: all variables are continuos
- Edit1: reproducible data: HERE
Any ideas would be MUCH appreaciated! Thanks in advance!
- Edit2:
I was thinking about this solution after watching this video and from the kind comment below, I'm really hoping that this may be a good path :
If I apply the same logic as the video's for the partial corr, I guess that maybe it would be all right?
res1 <- rstandard(lm(X1 ~ Z1))
res 2 <- rstandard(lm(X2 ~ Z2))
so,
res1 = > the portion of X1 that is not explained by Z1
res2 = > the portion of X2 that is not explained by Z2
so,
cor(res1,res2) = > should be the correlation between X1 (accouting for Z1's effect on it) and X2 (accounting for Z2's effect on it), right?
Question 1: I'm assuming this would be fine for a Pearson's correlation, but my data is non-parametric. Would it be okay to apply a Spearman's correlation cor(res1, res2) ?
Question 2 : why
rstandard
? Should we always apply this, even if data is non-parametric? (I guess so, since even Spearman corr is going to use Pearson's equation, after ranking the data, right?) but, still, I didn't quite understand why standartizing is a "must"
Edit 3 : Using
rstandard
or not
So,
When I standartize the residuals, I get a value of
Pearson's rho cor(res1, res2)
(0.95) andslope lm(res1 ~ res2)
(0.95), which differs fromPearson's rho pcor.test(X1, X2, Z)
(0.96) (I know the difference in this case seems minimal, but I'd want to understand why is there a difference in the first place...)when I don't standartize, the
Pearson's rho(res1, res2)
(0.96) is equal toPearson's rho pcor.test(X1, X2, Z)
(0.96) , but not to theslope lm(res1 ~ res2)
(1.477e-04) anymore...why is that?
rstandard
correctly, then I believe it would be fairly safe to drop it. Since it's based on a leave-one-out tactic, for a sufficiently large number of points and extreme outliers notwithstanding, its impact on the result is negligible anyway. I'm not a statistician, though. $\endgroup$