Giter Site home page Giter Site logo

poissonreg's Introduction

poissonreg Six fishes, each in a different color: red, green, orange, purple, yellow, blue.

R-CMD-check CRAN status Codecov test coverage Lifecycle: experimental

poissonreg enables the parsnip package to fit various types of Poisson regression models including ordinary generalized linear models, simple Bayesian models (via rstanarm), and two zero-inflated Poisson models (via pscl).

Installation

You can install the released version of poissonreg from CRAN with:

install.packages("poissonreg")

Install the development version from GitHub with:

# install.packages("pak")
pak::pak("tidymodels/poissonreg")

Available Engines

The poissonreg package provides engines for the models in the following table.

model engine mode
poisson_reg glm regression
poisson_reg hurdle regression
poisson_reg zeroinfl regression
poisson_reg glmnet regression
poisson_reg stan regression

Example

A log-linear model for categorical data analysis:

library(poissonreg)

# 3D contingency table from Agresti (2007):
poisson_reg() %>%
  set_engine("glm") %>%
  fit(count ~ (.)^2, data = seniors)
#> 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

Contributing

This project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

poissonreg's People

Contributors

emilhvitfeldt avatar hfrick avatar juliasilge avatar simonpcouch avatar topepo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

poissonreg's Issues

Setting `relax = TRUE` for glmnet models fails

Slightly adapted from this SO post

library(poissonreg)
#> Loading required package: parsnip

set.seed(123)
df <- tibble::tibble(
  y = rpois(1000, lambda = 3),
  x_1 = 2 * y + rnorm(1000),
  x_2 = 0.1 * y + rnorm(1000)
)

# setting `relax` by itself works
mod <- poisson_reg(penalty = 0.5) %>%
  set_engine("glmnet", relax = TRUE) |> 
  fit(y ~ ., data = df) 

# setting `family` by itself works
mod <- poisson_reg(penalty = 0.5) %>%
  set_engine("glmnet", family = "poisson") |> 
  fit(y ~ ., data = df)

# setting both together fails
mod <- poisson_reg(penalty = 0.5) %>%
  set_engine("glmnet", family = "poisson", relax = TRUE) |> 
  fit(y ~ ., data = df)
#> Error in glmnet.path(x, y, weights, lambda, nlambda, lambda.min.ratio, : Invalid family argument; must be either character, function or family object

# glmnet directly works
mod <- glmnet::glmnet(x = as.matrix(df[,2:3]), y = df$y, family = "poisson")
mod <- glmnet::glmnet(x = as.matrix(df[,2:3]), y = df$y, family = "poisson", relax = TRUE)

Created on 2024-02-03 with reprex v2.1.0

HTML5 issues in new R devel check

Dear maintainer,

Please see the problems shown on
https://cran.r-project.org/web/checks/check_results_poissonreg.html.

In particular, please see the "Found the following HTML validation
problems" NOTEs in the "HTML version of manual" check for at least some
of the r-devel checks results.

R 4.2.0 switched to use HTML5 for documentation pages. Now validation
using HTML Tidy finds problems in the HTML generated from your Rd
files.

To fix, in most cases it suffices to re-generate the Rd files using the
current CRAN version of roxygen2. To check whether this already fixes
things, or whether additional changes you made fixed the problems (e.g.,
if the problem is from yourself directly generating HTML output), you
can grab HTML Tidy version 5.8.0 binaries from
https://binaries.html-tidy.org/ and, with FOO.Rd an Rd file for which
problems were found, run

R CMD Rdconv -t html /path/to/FOO.Rd -o FOO.html
tidy -qe --drop-empty-elements no FOO.html

(Alternatively, you can use R CMD check --as-cran using a current
version of R-devel.)

Can you please fix as necessary?

Please correct before 2022-09-09 to safely retain your package on CRAN.

Release poissonreg 0.2.0

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::cloud_check()
  • Update cran-comments.md
  • Review pkgdown reference index for, e.g., missing topics
  • git push
  • Draft blog post
  • Slack link to draft blog in #open-source-comms

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted ๐ŸŽ‰
  • git push
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • git push
  • Finish blog post
  • Tweet
  • Add link to blog post in pkgdown news menu

Upkeep for poissonreg

Pre-history

  • usethis::use_readme_rmd()
  • usethis::use_roxygen_md()
  • usethis::use_github_links()
  • usethis::use_pkgdown_github_pages()
  • usethis::use_tidy_labels()
  • usethis::use_tidy_style()
  • usethis::use_tidy_description()
  • urlchecker::url_check()

2020

  • usethis::use_package_doc()
    Consider letting usethis manage your @importFrom directives here.
    usethis::use_import_from() is handy for this.
  • usethis::use_testthat(3) and upgrade to 3e, testthat 3e vignette
  • Align the names of R/ files and test/ files for workflow happiness.
    usethis::rename_files() can be helpful.

2021

  • usethis::use_tidy_dependencies()
  • usethis::use_tidy_github_actions() and update artisanal actions to use setup-r-dependencies
  • Remove check environments section from cran-comments.md
  • Bump required R version in DESCRIPTION to 3.4
  • Use lifecycle instead of artisanal deprecation messages, as described in Communicate lifecycle changes in your functions
  • Add RStudio to DESCRIPTION as funder, if appropriate

changes for parsnip 1.0.0

Revdeps fail with:

> revdep_details(, "poissonreg")
โ•โ• Reverse dependency check โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• poissonreg 0.2.0 โ•โ•

Status: BROKEN

โ”€โ”€ Newly failing

โœ– checking tests ...

โ”€โ”€ Before โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
0 errors โœ” | 0 warnings โœ” | 0 notes โœ”

โ”€โ”€ After โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โฏ checking tests ...
  See below...

โ”€โ”€ Test failures โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ testthat โ”€โ”€โ”€โ”€

> library(testthat)
> library(poissonreg)
Loading required package: parsnip
> 
> test_check("poissonreg")

Attaching package: 'rlang'

The following objects are masked from 'package:testthat':

    is_false, is_null, is_true


Attaching package: 'tidyr'

The following object is masked from 'package:testthat':

    matches

[ FAIL 1 | WARN 0 | SKIP 4 | PASS 35 ]

โ•โ• Skipped tests โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
โ€ข On CRAN (4)

โ•โ• Failed tests โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
โ”€โ”€ Failure (test-poisson-reg.R:130:3): updating โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
update(expr3, mixture = 1, fresh = TRUE) not equal to `expr3_exp`.
Component "eng_args": target is NULL, current is quosures

[ FAIL 1 | WARN 0 | SKIP 4 | PASS 35 ]
Error: Test failures
Execution halted

1 error โœ– | 0 warnings โœ” | 0 notes โœ”

Release poissonreg 0.1.1

Prepare for release:

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted ๐ŸŽ‰
  • usethis::use_github_release()
  • usethis::use_dev_version()

multi_predict fails for glmnet models when generating predictions for only a single row

multi_predict() fails on glmnet models when passing only a single row of data.

library(tidyverse)
library(tidymodels)
library(poissonreg)
# This works:
> m <- poisson_reg() %>% 
+   set_engine("glmnet") %>% 
+   fit(count ~ (.)^2, data = seniors[,2:4])
> 
> multi_predict(m,new_data = seniors[1:2,])
# A tibble: 2 ร— 1
  .pred            
  <list>           
1 <tibble [72 ร— 2]>
2 <tibble [72 ร— 2]>

versus...

# This does not:
> m <- poisson_reg() %>% 
+   set_engine("glmnet") %>% 
+   fit(count ~ (.)^2, data = seniors[,2:4])
> 
> multi_predict(m,new_data = seniors[1,])
Error in predict.glmnet(object = object$fit, newx = as.matrix(new_data[,  : 
  The number of variables in newx must be 3

Session info:

R version 4.1.2 (2021-11-01)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.0.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] poissonreg_1.0.1   yardstick_1.0.0    workflowsets_1.0.0 workflows_1.0.0    tune_1.0.0        
 [6] rsample_1.1.0      recipes_1.0.3      parsnip_1.0.0      modeldata_1.0.1    infer_1.0.4       
[11] dials_1.0.0        scales_1.2.1       broom_1.0.2        tidymodels_1.0.0   forcats_0.5.1     
[16] stringr_1.4.0      dplyr_1.0.9        purrr_0.3.4        readr_2.1.0        tidyr_1.2.0       
[21] tibble_3.1.7       ggplot2_3.4.0      tidyverse_1.3.1   

loaded via a namespace (and not attached):
 [1] fs_1.5.0                lubridate_1.8.0         DiceDesign_1.9          httr_1.4.2             
 [5] tools_4.1.2             backports_1.3.0         utf8_1.2.2              R6_2.5.1               
 [9] rpart_4.1-15            DBI_1.1.1               colorspace_2.0-2        nnet_7.3-16            
[13] withr_2.5.0             tidyselect_1.2.0        compiler_4.1.2          glmnet_4.1-6           
[17] cli_3.4.1               rvest_1.0.2             xml2_1.3.2              digest_0.6.28          
[21] pkgconfig_2.0.3         parallelly_1.28.1       lhs_1.1.3               dbplyr_2.1.1           
[25] rlang_1.0.6             readxl_1.3.1            rstudioapi_0.13         shape_1.4.6            
[29] generics_0.1.2          jsonlite_1.7.2          magrittr_2.0.1          Matrix_1.3-4           
[33] Rcpp_1.0.7              munsell_0.5.0           fansi_0.5.0             GPfit_1.0-8            
[37] lifecycle_1.0.3         furrr_0.2.3             stringi_1.7.5           MASS_7.3-54            
[41] grid_4.1.2              parallel_4.1.2          listenv_0.8.0           crayon_1.4.2           
[45] lattice_0.20-45         haven_2.4.3             splines_4.1.2           hms_1.1.1              
[49] pillar_1.7.0            future.apply_1.8.1-9001 codetools_0.2-18        reprex_2.0.1           
[53] glue_1.6.2              modelr_0.1.8            vctrs_0.5.1             tzdb_0.3.0             
[57] foreach_1.5.1           cellranger_1.1.0        gtable_0.3.0            future_1.23.0          
[61] assertthat_0.2.1        gower_0.2.2             prodlim_2019.11.13      class_7.3-19           
[65] survival_3.2-13         timeDate_3043.102       iterators_1.0.13        hardhat_1.2.0          
[69] lava_1.6.10             globals_0.14.0          ellipsis_0.3.2          ipred_0.9-12   

handle quasi-likelihood glmnet models better

Similar to tidymodels/parsnip#483

library(tidymodels)
#> Registered S3 method overwritten by 'tune':
#>   method                   from   
#>   required_pkgs.model_spec parsnip
library(poissonreg)

n <- 2e3
set.seed(123)
x1 <- MASS::rnegbin(n, mu = 28, theta = 0.6)
x2 <- rnorm(n, 5, 10)
x3 <- as.factor(rnorm(n) < 0)
y <- as.integer(x1 + x2 + as.numeric(x3))
y[y < 0] <- 0
data <- tibble(y, x1, x2, x3)

poisson_reg(penalty = 0.5) %>% 
  set_engine("glmnet") %>% 
  fit(y ~ x1 + x2, data = data) %>% 
  pluck("fit") %>% 
  class()
#> [1] "fishnet" "glmnet"

# 'fishnet' is their class of Poisson models

poisson_reg(penalty = 0.5) %>% 
  set_engine("glmnet", family = quasipoisson()) %>% 
  fit(y ~ x1 + x2, data = data) %>% 
  pluck("fit") %>% 
  class()
#> [1] "glmnetfit" "glmnet"

# Now the class is not Poisson specific, so our methods don't know what to do

Created on 2021-05-04 by the reprex package (v1.0.0.9000)

We should add class to the parsnip model or restrict this family for this engine.

poisson_reg() with "glmnet" engine fails if there is only one covariate

Any poisson_reg() model fails with the glmnet engine if there is only one covariate.

library(tidyverse)
library(tidymodels)
library(poissonreg)
# Using only two columns from seniors
> poisson_reg() %>% 
    set_engine("glmnet") %>% 
    fit(count ~ (.)^2, data = seniors[,3:4])
Error in glmnet::glmnet(x = maybe_matrix(x), y = y, family = "poisson") : 
  x should be a matrix with 2 or more columns

versus

# Using just one more column from seniors
> poisson_reg() %>% 
   set_engine("glmnet") %>% 
   fit(count ~ (.)^2, data = seniors[,2:4])
parsnip model object


Call:  glmnet::glmnet(x = maybe_matrix(x), y = y, family = "poisson") 

   Df  %Dev  Lambda
1   0  0.00 254.000
2   1 10.36 231.500
3   1 18.38 210.900
4   1 24.70 192.200
5   1 29.76 175.100

Session info:

R version 4.1.2 (2021-11-01)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.0.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] poissonreg_1.0.1   yardstick_1.0.0    workflowsets_1.0.0 workflows_1.0.0    tune_1.0.0        
 [6] rsample_1.1.0      recipes_1.0.3      parsnip_1.0.0      modeldata_1.0.1    infer_1.0.4       
[11] dials_1.0.0        scales_1.2.1       broom_1.0.2        tidymodels_1.0.0   forcats_0.5.1     
[16] stringr_1.4.0      dplyr_1.0.9        purrr_0.3.4        readr_2.1.0        tidyr_1.2.0       
[21] tibble_3.1.7       ggplot2_3.4.0      tidyverse_1.3.1   

loaded via a namespace (and not attached):
 [1] fs_1.5.0                lubridate_1.8.0         DiceDesign_1.9          httr_1.4.2             
 [5] tools_4.1.2             backports_1.3.0         utf8_1.2.2              R6_2.5.1               
 [9] rpart_4.1-15            DBI_1.1.1               colorspace_2.0-2        nnet_7.3-16            
[13] withr_2.5.0             tidyselect_1.2.0        compiler_4.1.2          glmnet_4.1-6           
[17] cli_3.4.1               rvest_1.0.2             xml2_1.3.2              digest_0.6.28          
[21] pkgconfig_2.0.3         parallelly_1.28.1       lhs_1.1.3               dbplyr_2.1.1           
[25] rlang_1.0.6             readxl_1.3.1            rstudioapi_0.13         shape_1.4.6            
[29] generics_0.1.2          jsonlite_1.7.2          magrittr_2.0.1          Matrix_1.3-4           
[33] Rcpp_1.0.7              munsell_0.5.0           fansi_0.5.0             GPfit_1.0-8            
[37] lifecycle_1.0.3         furrr_0.2.3             stringi_1.7.5           MASS_7.3-54            
[41] grid_4.1.2              parallel_4.1.2          listenv_0.8.0           crayon_1.4.2           
[45] lattice_0.20-45         haven_2.4.3             splines_4.1.2           hms_1.1.1              
[49] pillar_1.7.0            future.apply_1.8.1-9001 codetools_0.2-18        reprex_2.0.1           
[53] glue_1.6.2              modelr_0.1.8            vctrs_0.5.1             tzdb_0.3.0             
[57] foreach_1.5.1           cellranger_1.1.0        gtable_0.3.0            future_1.23.0          
[61] assertthat_0.2.1        gower_0.2.2             prodlim_2019.11.13      class_7.3-19           
[65] survival_3.2-13         timeDate_3043.102       iterators_1.0.13        hardhat_1.2.0          
[69] lava_1.6.10             globals_0.14.0          ellipsis_0.3.2          ipred_0.9-12   

Cannot predict with glmnet engine

Hello,

I'm having a hard time making predictions with poisson models fit using glmnet, whereas glm works fine. I'm new to the tidymodels universe so forgive me if I've overlooked something trivial...

poisson_reg() %>%
  set_engine("glm") %>%
  fit(count ~ (.)^2, data = seniors) %>%
  predict(new_data=seniors)

#> # A tibble: 8 x 1
#>    .pred
#>    <dbl>
#> 1 910.  
#> 2 539.  
#> 3  44.6 
#> 4 455.  
#> 5   3.62
#> 6  42.4 
#> 7   1.38
#> 8 280. 

Same thing but with glmnet

library(poissonreg)

poisson_reg() %>% 
  set_engine("glmnet") %>% 
  fit(count ~ (.)^2, data = seniors) %>%
  predict(new_data=seniors)

#> Error: `penalty` should be a single numeric value. `multi_predict()` can be used to get multiple predictions per row of data.
#> Run `rlang::last_error()` to see where the error occurred.

and with multi_predict()

poisson_reg() %>% 
  set_engine("glmnet") %>% 
  fit(count ~ (.)^2, data = seniors) %>%
  multi_predict(new_data=seniors)

#> Error in class() : 0 argument passed to 'class' which requires 1

sessionInfo() output:

R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 10 (buster)

Matrix products: default
BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.3.5.so

locale:
 [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8        LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8   
 [6] LC_MESSAGES=C          LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C           LC_TELEPHONE=C        
[11] LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] reprex_0.3.0          poissonreg_0.0.1.9000 parsnip_0.1.1        

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6      pillar_1.4.4      compiler_3.6.3    prettyunits_1.1.1 iterators_1.0.12  tools_3.6.3       digest_0.6.25    
 [8] evaluate_0.14     lifecycle_0.2.0   tibble_3.0.1      lattice_0.20-38   pkgconfig_2.0.3   rlang_0.4.6       Matrix_1.2-18    
[15] foreach_1.5.0     cli_2.0.2         rstudioapi_0.11   xfun_0.12         knitr_1.28        dplyr_0.8.5       generics_0.0.2   
[22] vctrs_0.3.0       fs_1.4.0          glmnet_4.0        grid_3.6.3        tidyselect_1.1.0  glue_1.4.1        R6_2.4.1         
[29] processx_3.4.2    fansi_0.4.1       rmarkdown_2.1     callr_3.4.3       whisker_0.4       tidyr_1.0.3       purrr_0.3.4      
[36] clipr_0.7.0       magrittr_1.5      ps_1.3.2          htmltools_0.4.0   codetools_0.2-16  ellipsis_0.3.1    assertthat_0.2.1 
[43] shape_1.4.4       utf8_1.1.4        crayon_1.3.4  

Release poissonreg 1.0.1

Prepare for release:

  • git pull
  • Check current CRAN check results
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::cloud_check()
  • Update cran-comments.md
  • git push

Submit to CRAN:

  • usethis::use_version('patch')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted ๐ŸŽ‰
  • git push
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • git push

Release poissonreg 0.1.0

Prepare for release:

  • devtools::build_readme()
  • Check current CRAN check results
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::revdep_check(num_workers = 4)
  • Update cran-comments.md
  • Polish NEWS
  • Review pkgdown reference index for, e.g., missing topics
  • Draft blog post

Submit to CRAN:

  • usethis::use_version('minor')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted ๐ŸŽ‰
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • Finish blog post
  • Tweet
  • Add link to blog post in pkgdown news menu

Update `predict(type = "conf_int")` for stan engine to use `posterior_epred()`

Looks like posterior_linpred() has been deprecated in favor of posterior_epred()

library(poissonreg)
#> Loading required package: parsnip

res_xy <- fit_xy(
  poisson_reg() %>%
    set_engine("stan", seed = 1333, chains = 10, iter = 1000, refresh = 0),
  x = seniors[, 1:3],
  y = seniors$count
)

confidence_parsnip <- 
  predict(res_xy,
          new_data = seniors[1:5,],
          type = "conf_int",
          level = 0.93)
#> Instead of posterior_linpred(..., transform=TRUE) please call posterior_epred(), which provides equivalent functionality.

Created on 2023-11-10 with reprex v2.0.2

Upkeep for poissonreg 2023

2022

2023

Necessary:

  • Update copyright holder in DESCRIPTION: person(given = "Posit Software, PBC", role = c("cph", "fnd"))
  • Double check license file uses '[package] authors' as copyright holder. Run use_mit_license()
  • Update email addresses *@rstudio.com -> *@posit.co
  • Update logo (https://github.com/rstudio/hex-stickers); run use_tidy_logo()
  • usethis::use_tidy_coc()
  • usethis::use_tidy_github_actions()

Optional:

  • Review 2022 checklist to see if you completed the pkgdown updates
  • Prefer pak::pak("org/pkg") over devtools::install_github("org/pkg") in README
  • Consider running use_tidy_dependencies() and/or replace compat files with use_standalone()
  • use_standalone("r-lib/rlang", "types-check") instead of home grown argument checkers
  • Add alt-text to pictures, plots, etc; see https://posit.co/blog/knitr-fig-alt/ for examples

move model definition to parsnip

We are standardizing to have our parsnip-adjacent package keep their model definitions in parsnip so that other packages can add engines.

This package should take a version dependency of parsnip >= 0.1.7.9000.

Release poissonreg 1.0.0

Prepare for release:

  • Check current CRAN check results
  • Polish NEWS
  • devtools::build_readme()
  • urlchecker::url_check()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • revdepcheck::cloud_check()
  • Update cran-comments.md
  • Review pkgdown reference index for, e.g., missing topics
  • Draft blog post
  • Ping Tracy Teal on Slack

Submit to CRAN:

  • usethis::use_version('major')
  • devtools::submit_cran()
  • Approve email

Wait for CRAN...

  • Accepted ๐ŸŽ‰
  • usethis::use_github_release()
  • usethis::use_dev_version()
  • Finish blog post
  • Tweet
  • Add link to blog post in pkgdown news menu

glmnet: Default to mean count for `multi_predict()`

Both predict() and multi_predict() have a default of type = NULL. For poisson_reg(engine = "glmnet"), predict() returns the mean count (glmnet's type "response") while multi_predict() returns the linear predictor (glmnet's type "link").

I would expect both to default to the same, and I would expect that to be the mean count.

Side note: we introduced a prediction type "linear_pred" for censored regression, which we might extend to other modes.

library(poissonreg)
#> Loading required package: parsnip

data(seniors, package = "poissonreg")

spec <- poisson_reg(penalty = 0.1, mixture = 0.3) %>%
  set_engine("glmnet", nlambda = 15)
f_fit <- fit(spec, count ~ ., data = seniors)

# default: type = NULL -> "numeric"
our_pred <- predict(f_fit, seniors, penalty = 0.1)
our_pred
#> # A tibble: 8 ร— 1
#>   .pred
#>   <dbl>
#> 1 540. 
#> 2 740. 
#> 3 282. 
#> 4 387. 
#> 5  90.7
#> 6 124. 
#> 7  47.4
#> 8  65.0
identical(our_pred, predict(f_fit, seniors, penalty = 0.1, type = "numeric"))
#> [1] TRUE

# default: type = NULL
our_multi_pred <- multi_predict(f_fit, seniors, penalty = 0.1) %>% 
  tidyr::unnest(cols = .pred)
our_multi_pred
#> # A tibble: 8 ร— 2
#>   penalty .pred
#>     <dbl> <dbl>
#> 1     0.1  6.29
#> 2     0.1  6.61
#> 3     0.1  5.64
#> 4     0.1  5.96
#> 5     0.1  4.51
#> 6     0.1  4.82
#> 7     0.1  3.86
#> 8     0.1  4.17


seniors_x <- model.matrix(~ ., data = seniors[, -4])[, -1]
seniors_y <- seniors$count
glmnet_fit <- glmnet::glmnet(x = seniors_x, y = seniors_y, family = "poisson",
                          alpha = 0.3, nlambda = 15)
waldo::compare(
  our_pred$.pred,
  predict(glmnet_fit, seniors_x, s = 0.1, type = "response") %>% as.vector()
)
#> โœ” No differences

waldo::compare(
  our_multi_pred$.pred,
  predict(glmnet_fit, seniors_x, s = 0.1, type = "link") %>% as.vector()
)
#> โœ” No differences

Created on 2023-01-21 with reprex v2.0.2

Support for negative binomial models

Hi,

Will this package (or an adjacent package) ever consider support for negative binomial, zero-inflated negative binomial, and hurdle negative binomial models?

I think it would be somewhat straightforward to implement using stats::glm(dist = MASS::negative.binomial()) / MASS::glm.nb(), pscl::zeroinfl(dist = 'negbin'), and pscl::hurdle(dist = 'negbin'). Would you be open to a PR?

Move `master` branch to `main`

The master branch of this repository will soon be renamed to main, as part of a coordinated change across several GitHub organizations (including, but not limited to: tidyverse, r-lib, tidymodels, and sol-eng). We anticipate this will happen by the end of September 2021.

That will be preceded by a release of the usethis package, which will gain some functionality around detecting and adapting to a renamed default branch. There will also be a blog post at the time of this master --> main change.

The purpose of this issue is to:

  • Help us firm up the list of targetted repositories
  • Make sure all maintainers are aware of what's coming
  • Give us an issue to close when the job is done
  • Give us a place to put advice for collaborators re: how to adapt

message id: euphoric_snowdog

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.