Reputation: 818
I am trying to perform a linear regression fit using tidymodels
,parsnip
but encounters the following error:
Error: No tidy method for objects of class function
routine:
library(tidymodels)
library(parsnip)
library(broom.mixed)
linear_reg() %>%
set_engine("lm") %>%
fit(formula = cnt ~ temp_raw, data = bikeshare)
fit %>% tidy()
fit %>% glance()
Having read this post Tidy function gives this error: No tidy method for objects of class lmerMod. It will not work on my computer, but works in pdf with same code
and I tried broom.mixed
but still the error persists.
Upvotes: 1
Views: 2057
Reputation: 226362
The main issue is that you need to assign the fitted model to an object; in your case it would also be fit
.
There are two other points to consider:
fit0
or my_fit
or something rather than fit
); usually you can get away with it but it breaks, confusingly, in some contextsbroom.mixed
is a red herring. The broom
package is actually used for lm
fits (and you don't need to load it, apparently tidymodels
loads it (and parsnip
) automatically ...)library(tidymodels)
fit <- linear_reg() %>%
set_engine("lm") %>%
fit(formula = mpg ~ cyl, data = mtcars)
fit %>% tidy()
fit %>% glance()
Upvotes: 4