【发布时间】:2021-10-24 12:24:49
【问题描述】:
在基础 R 中,很容易使用 anova() 函数比较两个模型并获得 F 检验。
library(MASS)
lm.fit1 <- lm(medv ~ . , data = Boston)
lm.fit1a <- update(lm.fit1, ~ . - age - black)
anova(lm.fit1a, lm.fit1)
如果我正在使用 tidymodels 工作流程。我如何进行相同的比较?我有这样的代码:
library(tidymodels)
lm_spec <- linear_reg() %>%
set_mode("regression") %>%
set_engine("lm")
the_rec <- recipe(medv ~ ., data = Boston)
the_workflow <- workflow() %>%
add_recipe(the_rec) %>%
add_model(lm_spec)
the_workflow_fit1 <-
fit(the_workflow, data = Boston)
tidy(the_workflow_fit1)
the_workflow_fit1a <-
the_workflow_fit1 %>%
update_recipe(the_rec %>% step_rm(age, black)) %>%
fit(data = Boston)
tidy(the_workflow_fit1a)
我不知道如何提取正确的对象(事物)来提供这样的语句:
anova(the_workflow_fit1a$thingy, the_workflow_fit1$thingy)
我需要什么东西?在tidymodels 生态系统中是否有一种优雅的方法可以做到这一点?
【问题讨论】:
标签: r tidymodels