On 18/05/07, gatemaze@gmail.com <gatemaze@gmail.com> wrote:
>
> Hi,
>
> among the many (5) methods that I found in the list to do partial
> correlation in the following two that I had a look I am getting different
> t-values. Does anyone have any clues on why is that? The source code is
> below. Thanks.
>
> pcor3 <- function (x, test = T, p = 0.05) {
>   nvar <- ncol(x)
>   ndata <- nrow(x)
>   conc <- solve(cor(x))
>   resid.sd <- 1/sqrt(diag(conc))
>   pcc <- -sweep(sweep(conc, 1, resid.sd, "*"), 2, resid.sd, "*")
>   #colnames(pcc) <- rownames(pcc) <- colnames(x)
>   if (test) {
>     t.df <- ndata - nvar
>     t <- pcc/sqrt((1 - pcc^2)/t.df)
>     print(t);
>     pcc <- list(coefs = pcc, sig = t > qt(1 - (p/2), df = t.df))
>   }
>   return(pcc)
> }
>
>
> pcor4 <- function(x, y, z) {
>   return(cor.test (lm(x~z)$resid,lm(y~z)$resid));
> }
>
>

Just to self-reply my question since I found the answer. The difference is
in the degrees of freedom. The variable t.df in pcor3 is smaller than the df
used for the test in pcor4, and how smaller it is depends on the number of
variables used in the partial correlation.

	[[alternative HTML version deleted]]

