Skip to content
Prev 82514 / 398506 Next

retrieving p-values in lm

On Fri, 2005-12-09 at 14:19 +0100, Patrick Kuss wrote:
Judging from your code, you mean p-value of the F-statistic for the
whole model - this isn't stored anywhere, see:

getAnywhere(print.summary.lm)

In particular this section:

 cat("\nResidual standard error:", format(signif(x$sigma,
        digits)), "on", rdf, "degrees of freedom\n")
    if (!is.null(x$fstatistic)) {
        cat("Multiple R-Squared:", formatC(x$r.squared, digits = digits))
        cat(",\tAdjusted R-squared:", formatC(x$adj.r.squared,
            digits = digits), "\nF-statistic:", formatC(x$fstatistic[1],
            digits = digits), "on", x$fstatistic[2], "and", x$fstatistic[3],
            "DF,  p-value:", format.pval(pf(x$fstatistic[1],
                x$fstatistic[2], x$fstatistic[3], lower.tail = FALSE),
                digits = digits), "\n")
    }

The relevant bit being:

format.pval(pf(x$fstatistic[1],
                x$fstatistic[2], x$fstatistic[3], lower.tail = FALSE)

The reason this works for the first model is that with one covariate the
value in $coefficients is the overall model p-value, in that case. With
two covariates, the things in $coefficients relate to these, not to the
overall model - your assumption was wrong in the first usage, you just
lucked out that it gave the same result.

So,

p1 <- pf(lm.res$fstatistic[1],
         lm.res$fstatistic[2], lm.res$fstatistic[3], 
         lower.tail = FALSE)

p2 <- pf(lm.res.2$fstatistic[1],
         lm.res.2$fstatistic[2], lm.res.2$fstatistic[3], 
         lower.tail = FALSE)

Gives you the p-values:
value
0.01368545
value
0.0461472

HTH

G