Title: Model Wrappers for Poisson Regression
Version: 1.0.1
Description: Bindings for Poisson regression models for use with the 'parsnip' package. Models include simple generalized linear models, Bayesian models, and zero-inflated Poisson models (Zeileis, Kleiber, and Jackman (2008) <doi:10.18637/jss.v027.i08>).
License: MIT + file LICENSE
URL: https://github.com/tidymodels/poissonreg, https://poissonreg.tidymodels.org/
BugReports: https://github.com/tidymodels/poissonreg/issues
Depends: parsnip (≥ 0.2.0), R (≥ 3.4)
Imports: dplyr, generics, glue, purrr, rlang, stats, tibble, tidyr
Suggests: covr, pscl, spelling, testthat (≥ 3.0.0)
Config/Needs/website: tidyverse/tidytemplate
Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
LazyData: true
RoxygenNote: 7.2.1
NeedsCompilation: no
Packaged: 2022-08-22 16:06:49 UTC; hannah
Author: Max Kuhn ORCID iD [aut], Hannah Frick ORCID iD [aut, cre], RStudio [cph, fnd]
Maintainer: Hannah Frick <hannah@rstudio.com>
Repository: CRAN
Date/Publication: 2022-08-22 16:30:02 UTC

parsnip methods for Poisson regression

Description

poissonreg offers a function to fit model to count data using Poisson generalized linear models or via different methods for zero-inflated Poisson (ZIP) models.

Details

The model function works with the tidymodels infrastructure so that the model can be resampled, tuned, tided, etc.

Example

Let’s fit a model to the data from Agresti (2007) Table 7.6:

library(poissonreg)
library(tidymodels)
tidymodels_prefer()

log_lin_fit <-
  # Define the model
  poisson_reg() %>%
  # Choose an engine for fitting. The default is 'glm' so
  # this next line is not strictly needed:
  set_engine("glm") %>%
  # Fit the model to the data:
  fit(count ~ (.)^2, data = seniors)

log_lin_fit
## parsnip model object
## 
## 
## Call:  stats::glm(formula = count ~ (.)^2, family = stats::poisson, 
##     data = data)
## 
## Coefficients:
##               (Intercept)               marijuanayes  
##                    5.6334                    -5.3090  
##              cigaretteyes                 alcoholyes  
##                   -1.8867                     0.4877  
## marijuanayes:cigaretteyes    marijuanayes:alcoholyes  
##                    2.8479                     2.9860  
##   cigaretteyes:alcoholyes  
##                    2.0545  
## 
## Degrees of Freedom: 7 Total (i.e. Null);  1 Residual
## Null Deviance:       2851 
## Residual Deviance: 0.374     AIC: 63.42

The different engines for the model that are provided by this package are:

show_engines("poisson_reg")
## # A tibble: 5 × 2
##   engine   mode      
##   <chr>    <chr>     
## 1 glm      regression
## 2 hurdle   regression
## 3 zeroinfl regression
## 4 glmnet   regression
## 5 stan     regression

Author(s)

Maintainer: Hannah Frick hannah@rstudio.com (ORCID)

Authors:

Other contributors:

See Also

Useful links:


Model predictions across many sub-models

Description

For some models, predictions can be made on sub-models in the model object.

Usage

## S3 method for class ''_fishnet''
predict_raw(object, new_data, opts = list(), ...)

## S3 method for class ''_fishnet''
multi_predict(object, new_data, type = NULL, penalty = NULL, ...)

Arguments

object

A model_fit object.

new_data

A rectangular data object, such as a data frame.

opts

A list of options..

...

Optional arguments to pass to predict.model_fit(type = "raw") such as type.

penalty

A numeric vector of penalty values.

Value

A tibble with the same number of rows as the data being predicted. There is a list-column named .pred that contains tibbles with multiple rows per sub-model.


Objects exported from other packages

Description

These objects are imported from other packages. Follow the links below to see their documentation.

generics

tidy


Alcohol, Cigarette, and Marijuana Use for High School Seniors

Description

Alcohol, Cigarette, and Marijuana Use for High School Seniors

Details

Data are from Table 7.3 of Agresti (2007). The first three columns make up data from a 3-way contingency table.

Value

seniors

a tibble

Source

Agresti, A (2007). An Introduction to Categorical Data Analysis.

Examples

data(seniors)
str(seniors)

Turn zero-inflated model results into a tidy tibble

Description

Turn zero-inflated model results into a tidy tibble

Usage

## S3 method for class 'zeroinfl'
tidy(x, type = "count", ...)

## S3 method for class 'hurdle'
tidy(x, type = "count", ...)

Arguments

x

A hurdle or zeroinfl model object.

type

A character string for which model coefficients to return: "all", "count", or "zero".

...

Not currently used.

Value

A tibble