> m1 <- lm(Sepal.Length ~ Sepal.Width + Species, data = iris)
> summary(m1)
Call:
lm(formula = Sepal.Length ~ Sepal.Width + Species, data = iris)
Residuals:
Min 1Q Median 3Q Max
-1.30711 -0.25713 -0.05325 0.19542 1.41253
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.2514 0.3698 6.089 9.57e-09 ***
Sepal.Width 0.8036 0.1063 7.557 4.19e-12 ***
Speciesversicolor 1.4587 0.1121 13.012 < 2e-16 ***
Speciesvirginica 1.9468 0.1000 19.465 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.438 on 146 degrees of freedom
Multiple R-squared: 0.7259, Adjusted R-squared: 0.7203
F-statistic: 128.9 on 3 and 146 DF, p-value: < 2.2e-16
> summary(m2)
Call:
lm(formula = Petal.Length ~ Petal.Width + Species, data = iris)
Residuals:
Min 1Q Median 3Q Max
-1.02977 -0.22241 -0.01514 0.18180 1.17449
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.21140 0.06524 18.568 < 2e-16 ***
Petal.Width 1.01871 0.15224 6.691 4.41e-10 ***
Speciesversicolor 1.69779 0.18095 9.383 < 2e-16 ***
Speciesvirginica 2.27669 0.28132 8.093 2.08e-13 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.3777 on 146 degrees of freedom
Multiple R-squared: 0.9551, Adjusted R-squared: 0.9542
F-statistic: 1036 on 3 and 146 DF, p-value: < 2.2e-16
然后介绍以下
pf()
加
sapply()
,(刚才好好好的,怎么突然间失灵了 :?: :?: :?: 1+2=3的答案竟然变成不是3了?!这是展马啦?!):
How to get F-test p-value
> p.value <- function(x) pf(summary(x)$fstatistic[1], summary(x)$fstatistic[2], summary(x)$fstatistic[3], lower.tail = FALSE)
> sapply(list(m1, m2), p.value)
value value
7.664374e-41 3.698514e-98