options(width = 100, tibble.print_max = 50)
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
  )

flexcm: Flexible Models for Dispersed Count Data

Travis build status

Eduardo E. R. Junior - jreduardo@usp.br, IME-USP

The flexcm package contains functions to fit flexible count models that can handle equi-, over-, and underdispersion, namely we consider COM-Poisson, Gamma-count, discrete Weibull, generalized Poisson, double Poisson and Poisson-Tweedie models^[Poisson-Tweedie models are fitted using mcglm package]. The normalizing constant for double Poisson and COM-Poisson are written in C++.

Joint work with Walmes M. Zeviani and Clarice G.B. Demétrio.

Installation

You can install the development version of flexcm from GitHub with:

# install.packages("devtools")
devtools::install_github("jreduardo/flexcm")

Usage and example

Basically, this package implements methods similar to those related to glm objects. The main function is flexcm(..., model).

library(flexcm)

# Fit models -----------------------------------------------------------

# Model families
families <- list("CMP" = "compoisson",
                 "GCT" = "gammacount",
                 "DWe" = "discreteweibull",
                 "GPo" = "generalizedpoisson",
                 "DPo" = "doublepoisson",
                 "PTw" = "poissontweedie")

# Fit models
models <- lapply(families, function(fam) {
  flexcm(ninsect ~ extract, model = fam, data = sitophilus)
})

# Methods --------------------------------------------------------------

vapply(models, coef, numeric(5))

vapply(models, logLik, numeric(1))

equitest(models[-3])

print(models[["PTw"]])

# Predict new data -----------------------------------------------------

newdf <- sitophilus[c(21, 31), -2, drop = FALSE]
purrr::map_dfr(models,
               .id = "model",
               .f = predict,
               newdata = newdf,
               type = "response",
               interval = "confidence",
               augment_data = TRUE)

Currently, the methods implemented for "flexcm" objects are

methods(class = "flexcm")

Related projects

There are other R packages to deal with COM-Poisson models that have somehow contributed to the writing of flexcm.

License

The flexcm package is licensed under the GNU General Public License, version 3, see file LICENSE.md, © 2019 E. E., Ribeiro Jr.



jreduardo/flexcm documentation built on May 8, 2019, 12:41 p.m.