[R] Partial correlations and p-values

Juliet Hannah juliet.hannah at gmail.com
Sat Dec 5 17:16:26 CET 2009


Your R code looks correct.

Because this is a straightforward calculation, I would be surprised if there
were any differences with SPSS. It may be worthwhile to check
if SPSS  gives partial correlations or semipartial correlations. For example,
if you take the correlation between

py <- resid(lm(y ~ z1 + z2,data=mydat2))

and

x

where mydat2 has missing values removed, you get 0.47.

On Tue, Dec 1, 2009 at 8:24 PM, dadrivr <dadrivr at gmail.com> wrote:
>
> I am trying to calculate a partial correlation and p-values.  Unfortunately,
> the results in R are different than what SPSS gives.
>
> Here is an example in R (calculating the partial correlation of x and y,
> controlling for z1 and z2):
>
> x <- c(1,20,14,30,9,4,8)
> y <- c(5,6,7,9,NA,10,6)
> z1 <- c(13,8,16,14,26,13,20)
> z2 <- c(12,NA,2,5,8,16,13)
> fmx <- lm(x ~ z1 + z2, na.action = na.exclude)
> fmy <- lm(y ~ z1 + z2, na.action = na.exclude)
> yres <- resid(fmy)
> xres <- resid(fmx)
> cor(xres, yres, use = "p")
> ct <- cor.test(xres, yres)
> ct$estimate
> ct$p.value
>
> R give me:
> r = .65, p = .23
>
> However, SPSS calculates:
> r = .46, p = .70
>
> I think something may be different with R's handling of missing data, as
> when I replace the NA's with values, R and SPSS give the same r-values,
> albeit different p-values still.  I am doing pairwise case exclusion in both
> R and SPSS.  Any ideas why I'm getting different values?  Is something wrong
> with my formula in R?  Any help would be greatly appreciated.  Thanks!
>




More information about the R-help mailing list