poisson_reg() is a way to generate a specification of a model before fitting and allows the model to be created using different packages in R or Stan. The main arguments for the model are:

• penalty: The total amount of regularization in the model. Note that this must be zero for some engines.

• mixture: The mixture amounts of different types of regularization (see below). Note that this will be ignored for some engines.

These arguments are converted to their specific names at the time that the model is fit. Other options and argument can be set using set_engine(). If left to their defaults here (NULL), the values are taken from the underlying model functions. If parameters need to be modified, update() can be used in lieu of recreating the object from scratch.

poisson_reg(mode = "regression", penalty = NULL, mixture = NULL)

# S3 method for poisson_reg
update(
object,
parameters = NULL,
penalty = NULL,
mixture = NULL,
fresh = FALSE,
...
)

## Arguments

mode A single character string for the type of model. The only possible value for this model is "regression". A non-negative number representing the total amount of regularization (glmnet only). A number between zero and one (inclusive) that is the proportion of L1 regularization (i.e. lasso) in the model. When mixture = 1, it is a pure lasso model while mixture = 0 indicates that ridge regression is being used. (glmnet and spark only). A boosted tree model specification. A 1-row tibble or named list with main parameters to update. If the individual arguments are used, these will supersede the values in parameters. Also, using engine arguments in this object will result in an error. A logical for whether the arguments should be modified in-place of or replaced wholesale. Not used for update().

## Value

An updated model specification.

## Details

The data given to the function are not saved and are only used to determine the mode of the model. For poisson_reg(), the mode will always be "regression".

The model can be created using the fit() function using the following engines:

• R: "glm" (the default), "glmnet", "hurdle", or "zeroinfl"

• Stan: "stan"

## Engine Details

Engines may have pre-set default arguments when executing the model fit call. For this type of model, the template of the fit calls are:

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


## Poisson Regression Model Specification (regression)
##
## Computational engine: glm
##
## Model fit template:
## stats::glm(formula = missing_arg(), data = missing_arg(), weights = missing_arg(),
##     family = stats::poisson)


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


## Poisson Regression Model Specification (regression)
##
## Computational engine: zeroinfl
##
## Model fit template:
## pscl::zeroinfl(formula = missing_arg(), data = missing_arg(),
##     weights = missing_arg())


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


## Poisson Regression Model Specification (regression)
##
## Computational engine: hurdle
##
## Model fit template:
## pscl::hurdle(formula = missing_arg(), data = missing_arg(), weights = missing_arg())


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


## Poisson Regression Model Specification (regression)
##
## Computational engine: glmnet
##
## Model fit template:
## glmnet::glmnet(x = missing_arg(), y = missing_arg(), weights = missing_arg(),
##     family = "poisson")


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


## Poisson Regression Model Specification (regression)
##
## Computational engine: stan
##
## Model fit template:
## rstanarm::stan_glm(formula = missing_arg(), data = missing_arg(),
##     weights = missing_arg(), family = stats::poisson)


## Examples

poisson_reg()
#> Poisson Regression Model Specification (regression)
#>
# Model from Agresti (2007) Table 7.6
log_lin_mod <-
poisson_reg() %>%
set_engine("glm") %>%
fit(count ~ (.)^2, data = seniors)

summary(log_lin_mod\$fit)
#>
#> Call:
#> stats::glm(formula = count ~ (.)^2, family = stats::poisson,
#>     data = data)
#>
#> Deviance Residuals:
#>        1         2         3         4         5         6         7         8
#>  0.02044  -0.02658  -0.09256   0.02890  -0.33428   0.09452   0.49134  -0.03690
#>
#> Coefficients:
#>                           Estimate Std. Error z value Pr(>|z|)
#> (Intercept)                5.63342    0.05970  94.361  < 2e-16 ***
#> marijuanayes              -5.30904    0.47520 -11.172  < 2e-16 ***
#> cigaretteyes              -1.88667    0.16270 -11.596  < 2e-16 ***
#> alcoholyes                 0.48772    0.07577   6.437 1.22e-10 ***
#> marijuanayes:cigaretteyes  2.84789    0.16384  17.382  < 2e-16 ***
#> marijuanayes:alcoholyes    2.98601    0.46468   6.426 1.31e-10 ***
#> cigaretteyes:alcoholyes    2.05453    0.17406  11.803  < 2e-16 ***
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#>
#> (Dispersion parameter for poisson family taken to be 1)
#>
#>     Null deviance: 2851.46098  on 7  degrees of freedom
#> Residual deviance:    0.37399  on 1  degrees of freedom
#> AIC: 63.417
#>
#> Number of Fisher Scoring iterations: 4
#>
# ------------------------------------------------------------------------------

library(pscl)
#> Classes and Methods for R developed in the
#> Political Science Computational Laboratory
#> Department of Political Science
#> Stanford University
#> Simon Jackman
#> hurdle and zeroinfl functions by Achim Zeileis
data("bioChemists", package = "pscl")

poisson_reg() %>%
set_engine("hurdle") %>%
# Extended formula:
fit(art ~ . | phd, data = bioChemists)
#> parsnip model object
#>
#> Fit time:  33ms
#>
#> Call:
#> pscl::hurdle(formula = art ~ . | phd, data = data)
#>
#> Count model coefficients (truncated poisson with log link):
#> (Intercept)     femWomen   marMarried         kid5          phd         ment
#>     0.67114     -0.22858      0.09648     -0.14219     -0.01273      0.01875
#>
#> Zero hurdle model coefficients (binomial with logit link):
#> (Intercept)          phd
#>      0.3075       0.1750
#>
model <- poisson_reg(penalty = 10, mixture = 0.1)
model
#> Poisson Regression Model Specification (regression)
#>
#> Main Arguments:
#>   penalty = 10
#>   mixture = 0.1
#> update(model, penalty = 1)
#> Poisson Regression Model Specification (regression)
#>
#> Main Arguments:
#>   penalty = 1
#>   mixture = 0.1
#> update(model, penalty = 1, fresh = TRUE)
#> Poisson Regression Model Specification (regression)
#>
#> Main Arguments:
#>   penalty = 1
#>