0

参考: 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)
4

1 回答 1

2

我推测您正在使用 R 4.0,因为我们已经看到其他用户也有同样的问题。词法范围发生了变化,这会影响方法(例如tidy方法)的 S3 注册。您可以在这里查看遇到类似问题的人

我们已经在欧洲防风草的开发版中解决了这个问题,它将尽快提交给 CRAN。在新的 CRAN 版本发布之前,您可以使用

devtools::install_dev("parsnip")

获取新版本。

于 2020-04-30T19:59:57.933 回答