tidymodels / tidymodels.org-legacy

Legacy Source of tidymodels.org
https://github.com/tidymodels/tidymodels_dot_org
Creative Commons Attribution Share Alike 4.0 International
99 stars 31 forks source link

tidy(lm_fit) in tidymodels get started example throws an error , no tidy method for objects of class lm #147

Closed baletercero closed 4 years ago

baletercero commented 4 years ago

I was trying the Build Model tutorial on tidymodels.org new website here (https://www.tidymodels.org/start/models/) and when I got to display the tidy model output I recevied an error : Error: No tidy method for objects of class _lm . I've used tidy from broom before so I'm frustrated I can't get it to work, thanks for any help you can provide!

Here's a reprex .

library(tidymodels)  # for the parsnip package, along with the rest of tidymodels
#> -- Attaching packages ---------------------------------------------------------------------------------------------------------------------------------------------- tidymodels 0.1.0 --
#> v broom     0.5.6      v recipes   0.1.10
#> v dials     0.0.6      v rsample   0.0.6 
#> v dplyr     0.8.5      v tibble    3.0.1 
#> v ggplot2   3.3.0      v tune      0.1.0 
#> v infer     0.5.1      v workflows 0.1.1 
#> v parsnip   0.1.0      v yardstick 0.0.6 
#> v purrr     0.3.4
#> -- Conflicts ------------------------------------------------------------------------------------------------------------------------------------------------- tidymodels_conflicts() --
#> x purrr::discard()  masks scales::discard()
#> x dplyr::filter()   masks stats::filter()
#> x dplyr::lag()      masks stats::lag()
#> x ggplot2::margin() masks dials::margin()
#> x recipes::step()   masks stats::step()

# Helper packages
library(readr)       # for importing data
#> 
#> Attaching package: 'readr'
#> The following object is masked from 'package:yardstick':
#> 
#>     spec
#> The following object is masked from 'package:scales':
#> 
#>     col_factor

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()
#> )

lm_mod <- 
  linear_reg() %>% 
  set_engine("lm") %>% set_mode('regression')

lm_fit <- 
  lm_mod %>% 
  fit(width ~ initial_volume * food_regime, data = urchins)
lm_fit
#> parsnip model object
#> 
#> Fit time:  0ms 
#> 
#> Call:
#> stats::lm(formula = formula, data = data)
#> 
#> Coefficients:
#>                    (Intercept)                  initial_volume  
#>                      0.0331216                       0.0015546  
#>                 food_regimeLow                 food_regimeHigh  
#>                      0.0197824                       0.0214111  
#>  initial_volume:food_regimeLow  initial_volume:food_regimeHigh  
#>                     -0.0012594                       0.0005254

## for a summary , summary() can work but better is tidy()
summary(lm_fit)
#>         Length Class      Mode   
#> lvl      0     -none-     NULL   
#> spec     5     linear_reg list   
#> fit     13     lm         list   
#> preproc  1     -none-     list   
#> elapsed  5     proc_time  numeric
**tidy(lm_fit)
#> Error: No tidy method for objects of class _lm**

Created on 2020-04-28 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 4.0.0 (2020-04-24)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United States.1252  
#>  ctype    English_United States.1252  
#>  tz       America/Chicago             
#>  date     2020-04-28                  
#> 
#> - Packages -------------------------------------------------------------------
#>  package       * version    date       lib source        
#>  assertthat      0.2.1      2019-03-21 [1] CRAN (R 4.0.0)
#>  backports       1.1.6      2020-04-05 [1] CRAN (R 4.0.0)
#>  base64enc       0.1-3      2015-07-28 [1] CRAN (R 4.0.0)
#>  bayesplot       1.7.1      2019-12-01 [1] CRAN (R 4.0.0)
#>  boot            1.3-25     2020-04-26 [1] CRAN (R 4.0.0)
#>  broom         * 0.5.6      2020-04-20 [1] CRAN (R 4.0.0)
#>  callr           3.4.3      2020-03-28 [1] CRAN (R 4.0.0)
#>  class           7.3-16     2020-03-25 [1] CRAN (R 4.0.0)
#>  cli             2.0.2      2020-02-28 [1] CRAN (R 4.0.0)
#>  codetools       0.2-16     2018-12-24 [1] CRAN (R 4.0.0)
#>  colorspace      1.4-1      2019-03-18 [1] CRAN (R 4.0.0)
#>  colourpicker    1.0        2017-09-27 [1] CRAN (R 4.0.0)
#>  crayon          1.3.4      2017-09-16 [1] CRAN (R 4.0.0)
#>  crosstalk       1.1.0.1    2020-03-13 [1] CRAN (R 4.0.0)
#>  curl            4.3        2019-12-02 [1] CRAN (R 4.0.0)
#>  desc            1.2.0      2018-05-01 [1] CRAN (R 4.0.0)
#>  devtools        2.3.0      2020-04-10 [1] CRAN (R 4.0.0)
#>  dials         * 0.0.6      2020-04-03 [1] CRAN (R 4.0.0)
#>  DiceDesign      1.8-1      2019-07-31 [1] CRAN (R 4.0.0)
#>  digest          0.6.25     2020-02-23 [1] CRAN (R 4.0.0)
#>  dplyr         * 0.8.5      2020-03-07 [1] CRAN (R 4.0.0)
#>  DT              0.13       2020-03-23 [1] CRAN (R 4.0.0)
#>  dygraphs        1.1.1.6    2018-07-11 [1] CRAN (R 4.0.0)
#>  ellipsis        0.3.0      2019-09-20 [1] CRAN (R 4.0.0)
#>  evaluate        0.14       2019-05-28 [1] CRAN (R 4.0.0)
#>  fansi           0.4.1      2020-01-08 [1] CRAN (R 4.0.0)
#>  fastmap         1.0.1      2019-10-08 [1] CRAN (R 4.0.0)
#>  foreach         1.5.0      2020-03-30 [1] CRAN (R 4.0.0)
#>  fs              1.4.1      2020-04-04 [1] CRAN (R 4.0.0)
#>  furrr           0.1.0      2018-05-16 [1] CRAN (R 4.0.0)
#>  future          1.17.0     2020-04-18 [1] CRAN (R 4.0.0)
#>  generics        0.0.2      2018-11-29 [1] CRAN (R 4.0.0)
#>  ggplot2       * 3.3.0      2020-03-05 [1] CRAN (R 4.0.0)
#>  ggridges        0.5.2      2020-01-12 [1] CRAN (R 4.0.0)
#>  globals         0.12.5     2019-12-07 [1] CRAN (R 4.0.0)
#>  glue            1.4.0      2020-04-03 [1] CRAN (R 4.0.0)
#>  gower           0.2.1      2019-05-14 [1] CRAN (R 4.0.0)
#>  GPfit           1.0-8      2019-02-08 [1] CRAN (R 4.0.0)
#>  gridExtra       2.3        2017-09-09 [1] CRAN (R 4.0.0)
#>  gtable          0.3.0      2019-03-25 [1] CRAN (R 4.0.0)
#>  gtools          3.8.2      2020-03-31 [1] CRAN (R 4.0.0)
#>  highr           0.8        2019-03-20 [1] CRAN (R 4.0.0)
#>  hms             0.5.3      2020-01-08 [1] CRAN (R 4.0.0)
#>  htmltools       0.4.0      2019-10-04 [1] CRAN (R 4.0.0)
#>  htmlwidgets     1.5.1      2019-10-08 [1] CRAN (R 4.0.0)
#>  httpuv          1.5.2      2019-09-11 [1] CRAN (R 4.0.0)
#>  igraph          1.2.5      2020-03-19 [1] CRAN (R 4.0.0)
#>  infer         * 0.5.1      2019-11-19 [1] CRAN (R 4.0.0)
#>  inline          0.3.15     2018-05-18 [1] CRAN (R 4.0.0)
#>  ipred           0.9-9      2019-04-28 [1] CRAN (R 4.0.0)
#>  iterators       1.0.12     2019-07-26 [1] CRAN (R 4.0.0)
#>  janeaustenr     0.1.5      2017-06-10 [1] CRAN (R 4.0.0)
#>  knitr           1.28       2020-02-06 [1] CRAN (R 4.0.0)
#>  later           1.0.0      2019-10-04 [1] CRAN (R 4.0.0)
#>  lattice         0.20-41    2020-04-02 [1] CRAN (R 4.0.0)
#>  lava            1.6.7      2020-03-05 [1] CRAN (R 4.0.0)
#>  lhs             1.0.2      2020-04-13 [1] CRAN (R 4.0.0)
#>  lifecycle       0.2.0      2020-03-06 [1] CRAN (R 4.0.0)
#>  listenv         0.8.0      2019-12-05 [1] CRAN (R 4.0.0)
#>  lme4            1.1-23     2020-04-07 [1] CRAN (R 4.0.0)
#>  loo             2.2.0      2019-12-19 [1] CRAN (R 4.0.0)
#>  lubridate       1.7.8      2020-04-06 [1] CRAN (R 4.0.0)
#>  magrittr        1.5        2014-11-22 [1] CRAN (R 4.0.0)
#>  markdown        1.1        2019-08-07 [1] CRAN (R 4.0.0)
#>  MASS            7.3-51.5   2019-12-20 [1] CRAN (R 4.0.0)
#>  Matrix          1.2-18     2019-11-27 [1] CRAN (R 4.0.0)
#>  matrixStats     0.56.0     2020-03-13 [1] CRAN (R 4.0.0)
#>  memoise         1.1.0      2017-04-21 [1] CRAN (R 4.0.0)
#>  mime            0.9        2020-02-04 [1] CRAN (R 4.0.0)
#>  miniUI          0.1.1.1    2018-05-18 [1] CRAN (R 4.0.0)
#>  minqa           1.2.4      2014-10-09 [1] CRAN (R 4.0.0)
#>  munsell         0.5.0      2018-06-12 [1] CRAN (R 4.0.0)
#>  nlme            3.1-147    2020-04-13 [1] CRAN (R 4.0.0)
#>  nloptr          1.2.2.1    2020-03-11 [1] CRAN (R 4.0.0)
#>  nnet            7.3-13     2020-02-25 [1] CRAN (R 4.0.0)
#>  parsnip       * 0.1.0      2020-04-09 [1] CRAN (R 4.0.0)
#>  pillar          1.4.3      2019-12-20 [1] CRAN (R 4.0.0)
#>  pkgbuild        1.0.7      2020-04-25 [1] CRAN (R 4.0.0)
#>  pkgconfig       2.0.3      2019-09-22 [1] CRAN (R 4.0.0)
#>  pkgload         1.0.2      2018-10-29 [1] CRAN (R 4.0.0)
#>  plyr            1.8.6      2020-03-03 [1] CRAN (R 4.0.0)
#>  prettyunits     1.1.1      2020-01-24 [1] CRAN (R 4.0.0)
#>  pROC            1.16.2     2020-03-19 [1] CRAN (R 4.0.0)
#>  processx        3.4.2      2020-02-09 [1] CRAN (R 4.0.0)
#>  prodlim         2019.11.13 2019-11-17 [1] CRAN (R 4.0.0)
#>  promises        1.1.0      2019-10-04 [1] CRAN (R 4.0.0)
#>  ps              1.3.2      2020-02-13 [1] CRAN (R 4.0.0)
#>  purrr         * 0.3.4      2020-04-17 [1] CRAN (R 4.0.0)
#>  R6              2.4.1      2019-11-12 [1] CRAN (R 4.0.0)
#>  Rcpp            1.0.4.6    2020-04-09 [1] CRAN (R 4.0.0)
#>  readr         * 1.3.1      2018-12-21 [1] CRAN (R 4.0.0)
#>  recipes       * 0.1.10     2020-03-18 [1] CRAN (R 4.0.0)
#>  remotes         2.1.1      2020-02-15 [1] CRAN (R 4.0.0)
#>  reshape2        1.4.4      2020-04-09 [1] CRAN (R 4.0.0)
#>  rlang           0.4.5      2020-03-01 [1] CRAN (R 4.0.0)
#>  rmarkdown       2.1        2020-01-20 [1] CRAN (R 4.0.0)
#>  rpart           4.1-15     2019-04-12 [1] CRAN (R 4.0.0)
#>  rprojroot       1.3-2      2018-01-03 [1] CRAN (R 4.0.0)
#>  rsample       * 0.0.6      2020-03-31 [1] CRAN (R 4.0.0)
#>  rsconnect       0.8.16     2019-12-13 [1] CRAN (R 4.0.0)
#>  rstan           2.19.3     2020-02-11 [1] CRAN (R 4.0.0)
#>  rstanarm        2.19.3     2020-02-11 [1] CRAN (R 4.0.0)
#>  rstantools      2.0.0      2019-09-15 [1] CRAN (R 4.0.0)
#>  rstudioapi      0.11       2020-02-07 [1] CRAN (R 4.0.0)
#>  scales        * 1.1.0      2019-11-18 [1] CRAN (R 4.0.0)
#>  sessioninfo     1.1.1      2018-11-05 [1] CRAN (R 4.0.0)
#>  shiny           1.4.0.2    2020-03-13 [1] CRAN (R 4.0.0)
#>  shinyjs         1.1        2020-01-13 [1] CRAN (R 4.0.0)
#>  shinystan       2.5.0      2018-05-01 [1] CRAN (R 4.0.0)
#>  shinythemes     1.1.2      2018-11-06 [1] CRAN (R 4.0.0)
#>  SnowballC       0.7.0      2020-04-01 [1] CRAN (R 4.0.0)
#>  StanHeaders     2.19.2     2020-02-11 [1] CRAN (R 4.0.0)
#>  statmod         1.4.34     2020-02-17 [1] CRAN (R 4.0.0)
#>  stringi         1.4.6      2020-02-17 [1] CRAN (R 4.0.0)
#>  stringr         1.4.0      2019-02-10 [1] CRAN (R 4.0.0)
#>  survival        3.1-12     2020-04-10 [1] CRAN (R 4.0.0)
#>  testthat        2.3.2      2020-03-02 [1] CRAN (R 4.0.0)
#>  threejs         0.3.3      2020-01-21 [1] CRAN (R 4.0.0)
#>  tibble        * 3.0.1      2020-04-20 [1] CRAN (R 4.0.0)
#>  tidymodels    * 0.1.0      2020-02-16 [1] CRAN (R 4.0.0)
#>  tidyposterior   0.0.2      2018-11-15 [1] CRAN (R 4.0.0)
#>  tidypredict     0.4.5      2020-02-10 [1] CRAN (R 4.0.0)
#>  tidyr           1.0.2      2020-01-24 [1] CRAN (R 4.0.0)
#>  tidyselect      1.0.0      2020-01-27 [1] CRAN (R 4.0.0)
#>  tidytext        0.2.4      2020-04-17 [1] CRAN (R 4.0.0)
#>  timeDate        3043.102   2018-02-21 [1] CRAN (R 4.0.0)
#>  tokenizers      0.2.1      2018-03-29 [1] CRAN (R 4.0.0)
#>  tune          * 0.1.0      2020-04-02 [1] CRAN (R 4.0.0)
#>  usethis         1.6.0      2020-04-09 [1] CRAN (R 4.0.0)
#>  vctrs           0.2.4      2020-03-10 [1] CRAN (R 4.0.0)
#>  withr           2.2.0      2020-04-20 [1] CRAN (R 4.0.0)
#>  workflows     * 0.1.1      2020-03-17 [1] CRAN (R 4.0.0)
#>  xfun            0.13       2020-04-13 [1] CRAN (R 4.0.0)
#>  xtable          1.8-4      2019-04-21 [1] CRAN (R 4.0.0)
#>  xts             0.12-0     2020-01-19 [1] CRAN (R 4.0.0)
#>  yaml            2.2.1      2020-02-01 [1] CRAN (R 4.0.0)
#>  yardstick     * 0.0.6      2020-03-17 [1] CRAN (R 4.0.0)
#>  zoo             1.8-7      2020-01-10 [1] CRAN (R 4.0.0)
#> 
#> [1] C:/Users/pablo/Documents/R/win-library/4.0
#> [2] C:/Program Files/R/R-4.0.0/library
topepo commented 4 years ago

The problem is with parsnip and S3 registration for tidy methods. It was overlooked in previous versions of R.

Until a new CRAN release, you can use

devtools::install_dev("parsnip")

to get the new version.