Re: [R] partial correlation significance

From: <gatemaze_at_gmail.com>
Date: Fri, 18 May 2007 21:08:28 +0100

On 18/05/07, gatemaze_at_gmail.com <gatemaze_at_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]]



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri 18 May 2007 - 20:12:48 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 18 May 2007 - 21:31:48 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.