[R] extract the p value
R. Michael Weylandt
michael.weylandt at gmail.com
Mon Oct 24 20:01:37 CEST 2011
It's not directly extractable since it's calculated on the fly in the
printing method. If you type stats:::print.summary.lm, you can see
the code the leads to the calculation: It's basically (I'm leaving out
some formatting stuff):
pf(x$fstatistic[1L], x$fstatistic[2L], x$fstatistic[3L], lower.tail = FALSE)
where the fstatistic is calculated in summary.lm. You can write a
little helper to calculate this yourself -- just something like
getModelPValue <- function(m) {
stopifnot(inherits(m, "lm"))
s <- summary.lm(m)
pf(s$fstatistic[1L], s$fstatistic[2L], s$fstatistic[3L], lower.tail = FALSE)
}
And you can just extract the necessary parts of summary.lm if speed is
a concern.
Hope this helps,
Michael
On Mon, Oct 24, 2011 at 1:47 PM, Jim Bouldin <bouldinjr at gmail.com> wrote:
> OK, what is the trick to extracting the overall p value from an lm object?
> It shows up in the summary(lm(model)) output but I can't seem to extract it:
>
>> test2 = apply(aa, 1, function(x) summary(lm(x[,1] ~ 0 + x[,3] + x[,6])))
>> test2[[1]]
>
> Call:
> lm(formula = x[, 1] ~ 0 + x[, 3] + x[, 6])
>
> [omitted summary output]
> F-statistic: 40.94 on 2 and 7 DF, p-value: 0.0001371
>
> It does not seem to be obtainable from anova(lm(model)) either, only the p
> values for the individual predictors.
> Stumped.
>
> Jim Bouldin
> Research Ecologist
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
>
More information about the R-help
mailing list