本文介绍了从R中的回归输出(lm)中提取最终的p值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有以下数据和代码:

> res = lm(vnum1~vnum2+vch1, data=rndf)
> sumres=summary(res)
>
> sumres

Call:
lm(formula = vnum1 ~ vnum2 + vch1, data = rndf)

Residuals:
     Min       1Q   Median       3Q      Max
-1.48523 -0.42050  0.05919  0.43710  1.93554

Coefficients:
            Estimate Std. Error t value Pr(>|t|)
(Intercept)  -1.0265     1.0192  -1.007   0.3310
vnum2         1.9538     0.9665   2.022   0.0628 .
vch1B        -0.7072     0.8386  -0.843   0.4132
vch1C         0.5502     0.8546   0.644   0.5301
vch1D        -0.6556     0.8412  -0.779   0.4488
vch1E         0.1461     0.8418   0.174   0.8647
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.9181 on 14 degrees of freedom
Multiple R-squared:  0.2799,    Adjusted R-squared:  0.02275
F-statistic: 1.088 on 5 and 14 DF,  p-value: 0.4088


> dput(rndf)
structure(list(vnum1 = c(-1.63272832611568, 0.225401613406123,
-0.412759271404808, 0.0518634835165988, 0.130576187815585, 0.393254112514486,
-0.22429939238377, -1.01640685392138, -0.5419194916071, 0.602275306119663,
-0.378031662946265, -0.357452340621538, 0.178526276590386, -0.138016672074599,
2.13719092448509, 1.03443214036885, 1.34821211116271, -0.718873325233001,
1.80014304090489, -0.497878912730538), vnum2 = c(0.168299512239173,
0.624244463164359, 0.0156862761359662, 0.450781079474837, 0.622718085534871,
0.285390306729823, 0.911491815699264, 0.500363457249478, 0.566354847047478,
0.942464957712218, 0.00690335803665221, 0.860874759964645, 0.786528263241053,
0.337976476177573, 0.346998119959608, 0.549394505331293, 0.71448978385888,
0.865091580431908, 0.967393533792347, 0.539990464225411), vch1 = structure(c(3L,
5L, 5L, 3L, 3L, 3L, 1L, 5L, 4L, 2L, 3L, 4L, 4L, 3L, 3L, 3L, 1L,
2L, 5L, 2L), .Label = c("A", "B", "C", "D", "E"), class = "factor")), .Names = c("vnum1",
"vnum2", "vch1"), class = "data.frame", row.names = c(NA, -20L
))

我可以从sumres $ r.squared和sumres $ adj.r.squared获得R平方和调整后的R平方值.但是我无法从res或sumres中获得最终的p值0.4088.我如何获得该价值?感谢您的帮助.

I can get R-squared and Adjusted R-squared values from sumres$r.squared and sumres$adj.r.squared. But I am not able to get the final p-value 0.4088 from res or sumres. How can I get this value? Thanks for your help.

推荐答案

您可以通过键入

class(sumres)
#> "summary.lm"

获取类,然后通过键入

stats:::print.summary.lm

进入包含以下行的控制台:

into the console which includes these lines:

 cat(...lots of stuff..., "p-value:", format.pval(pf(x$fstatistic[1L],
            x$fstatistic[2L], x$fstatistic[3L], lower.tail = FALSE),
            digits = digits)...morestuff...)

因此,在这种情况下,您需要:

so in this case, you want:

pf(sumres$fstatistic[1L], sumres$fstatistic[2L], sumres$fstatistic[3L], lower.tail = FALSE)

这篇关于从R中的回归输出(lm)中提取最终的p值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 18:38