【发布时间】:2021-06-29 09:21:14
【问题描述】:
是否可以从扫帚包中的整洁功能中提取截距和斜率?我知道可以一目了然地拉出 r.squared。
df <- tibble(education = c("Low", "Medium", "High", "Low", "Medium", "High", "High"),
wellbeing = c(7, 6, 7, 4, 5, 4, 5))
df$education <- as.factor(df$education)
mdl <- lm(
wellbeing ~ education,
data = df,
family = gaussian
)
# Pulling r.squared from glance
library(dplyr)
library(broom)
mdl %>%
glance() %>%
pull(r.squared)
# Pulling intercept from tidy?
library(dplyr)
library(broom)
mdl %>%
tidy() %>%
pull(Intercept)
【问题讨论】:
-
你的意思是
plot(mdl) mdl %>% tidy() %>% pull(estimate)。然后添加%>% .[1] -
… %>% filter(term == '(Intercept)')?或者,如果您希望将值放在单个列中:… %>% filter(term = '(Intercept)') %>% select(-term) %>% pivot_longer(everything())。