参考: TidyModels 入门
我无法将 _lm 类的模型整理一下。使用新的 tidymodel.org 入门网站的确切代码并生成错误。我的猜测是我需要一些软件包更新。
Error: No tidy method for objects of class _lm
以下是从网站复制的代码:
library(tidymodels)
library(readr)
urchins <-
# Data were assembled for a tutorial
# at https://www.flutterbys.com.au/stats/tut/tut7.5a.html
read_csv("https://tidymodels.org/start/models/urchins.csv") %>%
# Change the names to be a little more verbose
setNames(c("food_regime", "initial_volume", "width")) %>%
# Factors are very helpful for modeling, so we convert one column
mutate(food_regime = factor(food_regime, levels = c("Initial", "Low", "High")))
#> Parsed with column specification:
#> cols(
#> TREAT = col_character(),
#> IV = col_double(),
#> SUTW = col_double()
#> )
urchins
ggplot(urchins,
aes(x = initial_volume,
y = width,
group = food_regime,
col = food_regime)) +
geom_point() +
geom_smooth(method = lm, se = FALSE) +
scale_color_viridis_d(option = "plasma", end = .7)
lm_mod <-
linear_reg() %>%
set_engine("lm")
lm_fit <-
lm_mod %>%
fit(width ~ initial_volume * food_regime, data = urchins)
lm_fit
tidy(lm_fit)