r descr_models("poisson_reg", "hurdle")

Tuning Parameters

This engine has no tuning parameters.

Translation from parsnip to the underlying model call (regression)

r uses_extension("poisson_reg", "hurdle", "regression")

library(poissonreg)

poisson_reg() %>%
  set_engine("hurdle") %>%
  translate()

Preprocessing and special formulas for zero-inflated Poisson models


Specifying the statistical model details

For this particular model, a special formula is used to specify which columns affect the counts and which affect the model for the probability of zero counts. These sets of terms are separated by a bar. For example, y ~ x | z. This type of formula is not used by the base R infrastructure (e.g. model.matrix())

When fitting a parsnip model with this engine directly, the formula method is required and the formula is just passed through. For example:

library(tidymodels)
library(tidymodels)
tidymodels_prefer()

data("bioChemists", package = "pscl")
poisson_reg() %>% 
  set_engine("hurdle") %>% 
  fit(art ~ fem + mar | ment, data = bioChemists)

However, when using a workflow, the best approach is to avoid using [workflows::add_formula()] and use [workflows::add_variables()] in conjunction with a model formula:

data("bioChemists", package = "pscl")
spec <- 
  poisson_reg() %>% 
  set_engine("hurdle")

workflow() %>% 
  add_variables(outcomes = c(art), predictors = c(fem, mar, ment)) %>% 
  add_model(spec, formula = art ~ fem + mar | ment) %>% 
  fit(data = bioChemists) %>% 
  extract_fit_engine()

The reason for this is that [workflows::add_formula()] will try to create the model matrix and either fail or create dummy variables prematurely.

Case weights




Try the parsnip package in your browser

Any scripts or data that you put into this service are public.

parsnip documentation built on Aug. 18, 2023, 1:07 a.m.