-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
133 lines (92 loc) · 3.89 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include=FALSE}
options(width = 100, tibble.print_max = 50)
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
<img src="man/figures/flexcm_hex.png" align="right" height=160/ display="block">
# `flexcm`: Flexible Models for Dispersed Count Data #
[![Travis build status](https://travis-ci.org/jreduardo/flexcm.svg?branch=master)](https://travis-ci.org/jreduardo/flexcm)
> [Eduardo E. R. Junior](http://leg.ufpr.br/~eduardojr) -
> [jreduardo@usp.br](mailto: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`][mcglm] package]. The normalizing constant for double
Poisson and COM-Poisson are written in C++.
Joint work with [Walmes M. Zeviani](www.leg.ufpr.br/~walmes/) and
[Clarice G.B. Demétrio](http://ce.esalq.usp.br/equipe/clarice-garcia-borges-demetrio).
## Installation
You can install the development version of `flexcm` from
[GitHub](https://github.com/jreduardo/flexcm) with:
```r
# 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)`.
```{r example}
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
```{r methods}
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`.
- [`mcglm`][mcglm]: Routines for fitting the multivariate
covariance genelralized linear models. Currently, this package is used
to fit the Poisson-Tweedie models in `flexcm`.
- [`DWreg`][DWreg]: Fit Discrete weibull models (allows to model $q$ or
$\rho$ parameters).
- [`gamlss.dist`][gamlss.dist]: Implements (among other) double Poisson
and a restrictive generalized Poisson models.
- [`glmmTMB`][glmmTMB]: Fit (among other) COM-Poisson, under a different
mean-parametrization, and generalized Poisson models (includes
zero-inflation, dispersion modeling and random effects).
## License ##
The `flexcm` package is licensed under the [GNU General Public
License, version 3], see file `LICENSE.md`, © 2019 E. E., Ribeiro Jr.
<!------------------------------------------- -->
<!-- Links -->
[GNU General Public License, version 3]: https://www.gnu.org/licenses/gpl-3.0.ht
[mcglm]: https://github.com/wbonat/mcglm
[DWreg]: https://cran.r-project.org/package=DWreg
[glmmTMB]: https://github.com/glmmTMB/glmmTMB
[gamlss.dist]: https://cran.r-project.org/package=gamlss.dist