[英]Interpreting Estimate of categorical variable coefficient in lm() summary() in R
[英]filter lm coefficient summary model
你如何過濾系數摘要?
model = lm(x ~ a + b + c + d + e, data=ds)
ss <- coef(summary(model3))
df.coef <- as.data.frame( coef(summary(model)) )
filter(df.coef, Pr(>|t|) < 0.05)
錯誤:“過濾器(df.coef,Pr(>”)中的意外'>'`
你的ss
是一個矩陣,你可以像這樣子集:
model <- lm(mpg ~ hp + am + gear, mtcars)
ss <- coef(summary(model))
ss[ss[,"Pr(>|t|)"] < .05,]
# Estimate Std. Error t value Pr(>|t|)
# (Intercept) 23.18636779 3.898968754 5.946795 2.111900e-06
# hp -0.05973668 0.007925368 -7.537401 3.283912e-08
# am 3.95611932 1.777326184 2.225883 3.424800e-02
因此,在強制到 dataframe 之后,
df.coef <- as.data.frame(ss)
你會這樣做:
df.coef[df.coef$`Pr(>|t|)` < .05,]
# Estimate Std. Error t value Pr(>|t|)
# (Intercept) 23.18636779 3.898968754 5.946795 2.111900e-06
# hp -0.05973668 0.007925368 -7.537401 3.283912e-08
# am 3.95611932 1.777326184 2.225883 3.424800e-02
注意: gear
從結果中被過濾掉,因為它的 p 值高於 0.05。
要使用filter
,您需要將表轉換為數據框,並將列名包含在反引號中:
mod <- lm(y ~ x, data = data.frame(x = 1:10, y = 1:10 + rnorm(10)))
summary(mod)$coefficients %>%
as.data.frame() %>%
filter(`Pr(>|t|)` < 0.05)
#> Estimate Std. Error t value Pr(>|t|)
#> 1 0.9862634 0.07084972 13.9205 6.866089e-07
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.