| Title: | Zero-Inflated Mixed Poisson Regression for Multivariate Count Data |
|---|---|
| Description: | Fits and selects zero-inflated mixed Poisson models for multivariate count regression. Supports multiple mixing distributions and variance specifications for flexible marginal modeling, while allowing dependence in the structural-zero components and latent mixing intensities to be modeled separately through copulas. The methodology is described in Nguyen (2026) <doi:10.48550/arXiv.2608.12732>. |
| Authors: | Quang Huy Nguyen [aut, cre, cph] |
| Maintainer: | Quang Huy Nguyen <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-11-06 21:20:24 UTC |
| Source: | https://github.com/cran/mzimp |
Fits a bivariate Mixed Poisson (MP) or Zero-Inflated Mixed Poisson (ZIMP) regression model using inference functions for margins (IFM).
The two marginal models are first fitted separately using fit_zimp().
Dependence between their latent mixing variables is then modeled by a
specified bivariate copula. When both margins are zero-inflated,
dependence between the Bernoulli activation indicators may also be
modeled.
fit_bizimp( formula1 = NULL, formula2 = NULL, data = NULL, Y = NULL, X = NULL, Z = NULL, mixing.distribution.1 = "gamma", mixing.distribution.2 = "gamma", var.power = NULL, mixing.copula = 1L, zero.dependence = c("gaussian", "comonotone", "countermonotone"), d0 = 10L, n_gh = 20, gh = NULL, ini.par = NULL, progress = FALSE, trace = 0, eval.max = 100, rel.tol = 1e-05, x.tol = 1e-05, iter.max = 100, gaussian.sign.tol = 1e-06, t.df.grid = c(3, 5, 10, 30) )fit_bizimp( formula1 = NULL, formula2 = NULL, data = NULL, Y = NULL, X = NULL, Z = NULL, mixing.distribution.1 = "gamma", mixing.distribution.2 = "gamma", var.power = NULL, mixing.copula = 1L, zero.dependence = c("gaussian", "comonotone", "countermonotone"), d0 = 10L, n_gh = 20, gh = NULL, ini.par = NULL, progress = FALSE, trace = 0, eval.max = 100, rel.tol = 1e-05, x.tol = 1e-05, iter.max = 100, gaussian.sign.tol = 1e-06, t.df.grid = c(3, 5, 10, 30) )
formula1 |
Optional formula specifying the marginal model for the
first response. Use a one-part formula for an MP margin and a two-part
formula of the form |
formula2 |
Optional formula specifying the marginal model for the
second response. It follows the same syntax as |
data |
Data frame containing the variables referenced by |
Y |
Response for the direct matrix interface. Either an
|
X |
Count-component design for the direct interface. May be a numeric matrix/data frame shared by both margins or a list of exactly two margin-specific design matrices. Include intercept columns explicitly when required. |
Z |
Optional zero-component design for the direct interface. May be
|
mixing.distribution.1 |
Character string specifying the mixing
distribution for margin 1. One of |
mixing.distribution.2 |
Character string specifying the mixing
distribution for margin 2. One of |
var.power |
Optional variance-power specification for the two
marginal models. If |
mixing.copula |
Integer
Family codes follow the convention used by the |
zero.dependence |
Character string specifying dependence between
the Bernoulli activation indicators when both margins are
zero-inflated. One of |
d0 |
Positive integer specifying the checkerboard grid size used to
approximate the mixing copula. The default is |
n_gh |
Positive integer specifying the number of Gauss–Hermite
quadrature nodes used for lognormal marginal mixing. The default is
|
gh |
Optional precomputed Gauss–Hermite quadrature object. It is
passed to the lognormal marginal calculations. If |
ini.par |
Optional list of length two containing initial parameter
vectors for the two marginal |
progress |
Logical indicating whether fitting progress should be
displayed. The default is |
trace |
Numeric optimizer trace level. The default is |
eval.max |
Positive integer giving the maximum number of objective
function evaluations. The default is |
rel.tol |
Positive numeric value giving the relative convergence
tolerance used in marginal fitting. The default is |
x.tol |
Positive numeric value giving the parameter convergence
tolerance used in marginal fitting. The default is |
iter.max |
Positive integer giving the maximum number of optimizer
iterations. The default is |
gaussian.sign.tol |
Positive numeric tolerance used internally to
classify the sign of the Gaussian pilot dependence estimate. The
default is |
t.df.grid |
Integer vector of candidate degrees of freedom greater
than two used when |
fit_bizimp() fits one fully specified bivariate model. It does not
perform model selection over marginal distributions or dependence
structures.
Let the two observed counts be
where follows a Mixed Poisson model and is an
optional Bernoulli activation indicator. For an MP margin,
identically.
Conditional on the latent intensity,
with marginal mean
For a zero-inflated margin,
Thus, indicates that observation belongs to the
count-generating component of margin .
Dependence between and is represented by
the copula specified by mixing.copula. The copula is evaluated through
a checkerboard approximation with grid size d0.
When both margins are zero-inflated, dependence between
and is specified separately through
zero.dependence.
An object of class "bizimp_fit" containing the fitted marginal models,
dependence model, likelihood, and information criteria. Important
components include:
fit_margin_1, fit_margin_2
Fitted univariate marginal models returned by fit_zimp().
marginal_1, marginal_2
Internal representations of the fitted marginal models used in the dependence likelihood.
best_modelFitted dependence model. It contains the requested mixing-copula family and estimated copula parameter(s), the zero-dependence parameter when applicable, the maximized bivariate log-likelihood, convergence information, and the full-model AIC and BIC.
mixing.distribution.1, mixing.distribution.2
Mixing distributions used for margins 1 and 2.
var.powerUser-supplied marginal variance-power specification, or NULL when
native/default parameterizations were used.
mixing.copulaVineCopula family code used for latent mixing dependence.
zero.dependenceZero-dependence specification when both margins are zero-inflated;
otherwise NA.
zero.copula.rhoEstimated Gaussian zero-copula correlation when both margins are
zero-inflated and zero.dependence = "gaussian"; otherwise NA.
zero_inflationLogical vector of length two indicating whether each margin is zero-inflated.
nparTotal number of parameters used to calculate the full-model information criteria.
AIC, BIC
Akaike and Bayesian information criteria for the complete bivariate model.
interfaceCharacter string identifying whether the formula or direct matrix interface was used.
formula1, formula2
Marginal formulas when the formula interface was used.
callMatched call to fit_bizimp().
Estimation follows the IFM principle:
Fit margin 1 using fit_zimp().
Fit margin 2 independently using fit_zimp().
Conditional on the fitted marginal parameters, estimate the dependence parameter(s) from the bivariate likelihood.
Consequently, the marginal estimates returned in fit_margin_1 and
fit_margin_2 are the corresponding independent fit_zimp() estimates
and are not re-estimated during dependence fitting.
fit_bizimp() fits exactly one requested mixing-copula family. When the
requested family is not Gaussian, a Gaussian dependence model may be
fitted internally as a pilot for initialization and dependence-sign
information; it is not an additional candidate model.
Each margin may independently be an MP or ZIMP model. The four supported configurations are therefore:
MP–MP;
ZIMP–MP;
MP–ZIMP;
ZIMP–ZIMP.
For direct input, Z = NULL specifies MP–MP. A list such as
Z = list(Z1, NULL) specifies ZIMP–MP, while
Z = list(NULL, Z2) specifies MP–ZIMP. Supplying a shared matrix
Z applies the zero-component design to both margins.
Dependence between the Bernoulli activation indicators is estimated only for the ZIMP–ZIMP configuration.
Formula interface
Two formulas are supplied, one for each margin. For example,
formula1 = y1 ~ 1 + x1 + x2 formula2 = y2 ~ 1 + x1
specifies two MP margins. Zero-inflated margins are specified using two-part formulas:
formula1 = y1 ~ 1 + x1 + x2 | z1 + z2 formula2 = y2 ~ 1 + x1 | z1
The expression before | specifies the count component and the
expression after | specifies the zero-inflation component.
As in fit_zimp(), intercepts are included only when explicitly
requested with 1. This convention applies separately to the count and
zero-inflation components.
Matrix interface
Y may be an matrix/data frame or a list containing
two response vectors.
X may be a common design matrix for both margins or a list
list(X1, X2) containing margin-specific count designs. Similarly, Z
may be a common zero-component design or a list containing
margin-specific designs. Intercept columns must be included explicitly
when required.
The mixing distribution is specified separately for each margin through
mixing.distribution.1 and mixing.distribution.2. Supported
distributions are:
"gamma"Gamma mixing distribution.
"lnorm"Lognormal mixing distribution.
"ig"Inverse Gaussian mixing distribution.
"weibull"Weibull mixing distribution.
"loglogistic"Log-logistic mixing distribution.
"betaprime"Beta-prime mixing distribution.
The two margins may use different mixing distributions.
mixing.copula is a single integer family code supported by
VineCopula. It specifies the copula connecting the two latent mixing
variables. The default mixing.copula = 1 corresponds to the Gaussian
copula.
For mixing.copula = 2, corresponding to the Student-t copula, the
degrees of freedom are selected over the values supplied in t.df.grid.
When both margins are zero-inflated, zero.dependence specifies the
dependence structure between their Bernoulli activation indicators:
"gaussian"Gaussian copula dependence with an estimated correlation parameter.
"comonotone"Upper Fréchet-bound dependence.
"countermonotone"Lower Fréchet-bound dependence.
fit_zimp() for fitting a univariate marginal model and
select_bizimp() for selecting among multiple bivariate model
specifications.
## Generate a small bivariate Mixed Poisson data set set.seed(12345) n <- 50 x <- rnorm(n) X <- cbind(1, x) mu1 <- exp(X %*% c(0.4, 0.3)) mu2 <- exp(X %*% c(0.2, -0.2)) ## Gamma-mixed Poisson margins y1 <- rnbinom(n, size = 1 / 0.2, mu = mu1) y2 <- rnbinom(n, size = 1 / 0.3, mu = mu2) Y <- cbind(y1, y2) ## MP--MP model with a Gaussian mixing copula fit <- fit_bizimp( Y = Y, X = X, mixing.distribution.1 = "gamma", mixing.distribution.2 = "gamma", var.power = 2, mixing.copula = 1L, progress = FALSE ) fit$best_model fit$AIC fit$BIC ## Margin-specific designs and a ZIMP--MP configuration z1 <- rnorm(n) Z1 <- cbind(z1) fit_zm <- fit_bizimp( Y = Y, X = list(X, X), Z = list(Z1, NULL), mixing.distribution.1 = "gamma", mixing.distribution.2 = "gamma", var.power = c(2, 2), mixing.copula = 1L, progress = FALSE ) fit_zm$zero_inflation## Generate a small bivariate Mixed Poisson data set set.seed(12345) n <- 50 x <- rnorm(n) X <- cbind(1, x) mu1 <- exp(X %*% c(0.4, 0.3)) mu2 <- exp(X %*% c(0.2, -0.2)) ## Gamma-mixed Poisson margins y1 <- rnbinom(n, size = 1 / 0.2, mu = mu1) y2 <- rnbinom(n, size = 1 / 0.3, mu = mu2) Y <- cbind(y1, y2) ## MP--MP model with a Gaussian mixing copula fit <- fit_bizimp( Y = Y, X = X, mixing.distribution.1 = "gamma", mixing.distribution.2 = "gamma", var.power = 2, mixing.copula = 1L, progress = FALSE ) fit$best_model fit$AIC fit$BIC ## Margin-specific designs and a ZIMP--MP configuration z1 <- rnorm(n) Z1 <- cbind(z1) fit_zm <- fit_bizimp( Y = Y, X = list(X, X), Z = list(Z1, NULL), mixing.distribution.1 = "gamma", mixing.distribution.2 = "gamma", var.power = c(2, 2), mixing.copula = 1L, progress = FALSE ) fit_zm$zero_inflation
Fits a multivariate Mixed Poisson (MMP) or Zero-Inflated Mixed Poisson (MZIMP) model with factor-copula dependence.
Marginal models may either be fitted directly from Y, X, and
optionally Z, or supplied through an object returned by
select_multi_margin(). After the marginal models have been fitted or
supplied, fit_multizimp() estimates dependence among the latent
mixed-Poisson components and, when requested, dependence among
structural-zero indicators.
The marginal and dependence parameters are estimated using an inference-functions-for-margins (IFM) strategy.
fit_multizimp( Y = NULL, X = NULL, Z = NULL, margin = NULL, mixing.distribution = "gamma", var.power = NULL, margin.ini.par = NULL, parallel = NULL, margin.block_size = NULL, copula.block_size = 500L, d0 = 10, J = 1L, L = 0L, latent.dependence = c("gaussian", "biexp"), latent.factor.skewness = 0.5, latent.loglike = NULL, gh_order = 16L, approx.hermite.joint.order = 4L, hermite.polar.cycles = 6L, hermite.polar.v.iter = 8L, hermite.polar.r.iter = 4L, hermite.polar.tol = 1e-05, hermite.polar.r.max = 0.995, genz.conditional.Q = 256L, genz.conditional.antithetic = TRUE, qmc.n_rep = 4L, qmc.seed = 1L, zero.dependence = c("gaussian", "biexp"), zero.factor.skewness = 0.5, biexp.root_tol = 1e-10, psi0_start = NULL, rho0_start = NULL, gh.progressive = TRUE, use.gradient = TRUE, progress = TRUE, trace = 0, eval.max = 1000L, iter.max = 100L, tiny = 1e-300, big_penalty = 1e+12, rel.tol = 1e-04 )fit_multizimp( Y = NULL, X = NULL, Z = NULL, margin = NULL, mixing.distribution = "gamma", var.power = NULL, margin.ini.par = NULL, parallel = NULL, margin.block_size = NULL, copula.block_size = 500L, d0 = 10, J = 1L, L = 0L, latent.dependence = c("gaussian", "biexp"), latent.factor.skewness = 0.5, latent.loglike = NULL, gh_order = 16L, approx.hermite.joint.order = 4L, hermite.polar.cycles = 6L, hermite.polar.v.iter = 8L, hermite.polar.r.iter = 4L, hermite.polar.tol = 1e-05, hermite.polar.r.max = 0.995, genz.conditional.Q = 256L, genz.conditional.antithetic = TRUE, qmc.n_rep = 4L, qmc.seed = 1L, zero.dependence = c("gaussian", "biexp"), zero.factor.skewness = 0.5, biexp.root_tol = 1e-10, psi0_start = NULL, rho0_start = NULL, gh.progressive = TRUE, use.gradient = TRUE, progress = TRUE, trace = 0, eval.max = 1000L, iter.max = 100L, tiny = 1e-300, big_penalty = 1e+12, rel.tol = 1e-04 )
Y |
Optional |
X |
Count-component design used when |
Z |
Optional zero-component design used when |
margin |
Optional object returned by |
mixing.distribution |
Mixing distribution used for direct
marginal fitting when |
var.power |
Optional variance-power specification used for direct marginal fitting. |
margin.ini.par |
Optional initial parameter specification for direct marginal fitting. |
parallel |
|
margin.block_size |
Optional positive integer controlling the block size used during parallel marginal fitting. |
copula.block_size |
Positive integer giving the number of
observations processed in each dependence-likelihood block.
The default is |
d0 |
Integer greater than or equal to |
J |
Positive integer giving the number of factors in the
count/intensity dependence layer. It must satisfy |
L |
Integer specifying the number of factors in the
structural-zero dependence layer. The current implementation
supports |
latent.dependence |
Character string specifying the count-layer
factor family. Supported values are |
latent.factor.skewness |
Numeric parameter controlling skewness
of the standardized bilateral-exponential factor distribution when
|
latent.loglike |
Likelihood method for Gaussian count factors.
May be |
gh_order |
Integer greater than or equal to |
approx.hermite.joint.order |
Hermite approximation order used by
the joint count/zero likelihood calculation where applicable.
The default is |
hermite.polar.cycles |
Positive integer giving the maximum number of alternating direction/radius cycles used by the polar Hermite optimizer. |
hermite.polar.v.iter |
Positive integer giving the maximum number of optimizer iterations for the direction step of each polar cycle. |
hermite.polar.r.iter |
Positive integer giving the maximum number of optimizer iterations for the radius step of each polar cycle. |
hermite.polar.tol |
Positive numeric convergence tolerance for the polar Hermite optimizer. |
hermite.polar.r.max |
Numeric value in |
genz.conditional.Q |
Positive integer giving the number of conditional randomized quasi-Monte Carlo paths used for final Genz likelihood evaluation where applicable. |
genz.conditional.antithetic |
Logical indicating whether antithetic uniforms are used in the conditional RQMC evaluation. |
qmc.n_rep |
Positive integer giving the number of randomized QMC replicates used for final likelihood evaluation. |
qmc.seed |
Integer seed used for randomized QMC calculations and other reproducible stochastic computations within the fitting procedure. |
zero.dependence |
Character string specifying the factor family
for the structural-zero layer when |
zero.factor.skewness |
Numeric parameter controlling skewness of
the standardized bilateral-exponential factor distribution when
|
biexp.root_tol |
Positive numeric tolerance used in numerical root finding required by the bilateral-exponential factor backend. |
psi0_start |
Optional numeric vector of raw starting parameters for the count-layer factor-loading matrix. |
rho0_start |
Optional numeric vector of raw starting parameters for the structural-zero factor-loading matrix. |
gh.progressive |
Logical. If |
use.gradient |
Logical indicating whether available analytic gradients are used during dependence optimization. |
progress |
Deprecated and ignored. Retained for backward API compatibility; public fitting is currently silent. |
trace |
Deprecated and ignored. Retained for backward API compatibility. |
eval.max |
Positive integer giving the maximum number of objective-function evaluations for the main dependence optimizer. |
iter.max |
Positive integer giving the maximum number of iterations for the main dependence optimizer. |
tiny |
Positive numeric lower bound used to protect probabilities before logarithms are evaluated. |
big_penalty |
Positive numeric objective value returned for invalid parameter states during optimization. |
rel.tol |
Positive numeric relative convergence tolerance for the main dependence optimizer. |
For margin , the observed response is represented as
where follows a mixed Poisson model and is an
activation indicator when zero inflation is present. For an ordinary
mixed Poisson margin, with probability one.
The model separates two sources of cross-margin dependence:
dependence among the latent mixed-Poisson components
underlying ; and
dependence among the activation indicators for zero-inflated margins.
These two dependence structures are modeled separately through the count layer and the structural-zero layer.
An object of class "multi_zipm_fit" containing the fitted marginal
models and dependence structure. Important components include:
methodEstimation method. Currently "IFM".
n, k
Number of observations and response margins.
marginalList of length k containing the fitted marginal information.
Each element contains the margin index, mixing distribution,
variance power, zero-inflation status, count coefficients (be),
dispersion parameter (phi), zero-component coefficients (gam)
when present, and marginal log-likelihood.
marginal.distMixing distribution used for each response margin.
zero_inflationLogical vector indicating which margins contain a zero-inflation component.
count_layerFitted dependence structure for the mixed-Poisson count layer.
Important components include dependence, J, psi, A,
implied_correlation, and information on the likelihood method.
The loading matrix psi has dimension k by J.
zero_layerStructural-zero dependence information. When zero-layer dependence
is estimated, this includes the fitted loading matrix rho and its
implied correlation matrix. The component also records cases in
which no zero-layer dependence is estimated.
copula_fitDependence-fitting results, including the fitted log-likelihood, optimization objective, convergence information, elapsed time, optimizer output, and available final likelihood-evaluation diagnostics.
summaryOrdinary list containing the principal user-facing results, including dimensions, marginal-model summary, count- and zero-layer summaries, log-likelihood, convergence information, elapsed time, and final likelihood diagnostics.
callMatched function call.
Marginal models can be supplied in two ways.
Direct specification.
If margin = NULL, Y and X must be supplied. The function fits
exactly one marginal model for each response. No marginal model
selection is performed.
mixing.distribution specifies the mixing distribution and
var.power specifies its variance-power parameterization.
Z = NULL gives ordinary mixed Poisson margins. Supplying Z
gives zero-inflated mixed Poisson margins.
X and Z may be common matrices/data frames shared by all margins
or lists containing margin-specific designs. When lists are supplied,
their lengths must equal the number of response margins.
Previously selected margins.
Alternatively, margin may be an object returned by
select_multi_margin(). In this case the selected marginal
distributions, variance powers, regression coefficients, dispersion
parameters, and zero-inflation specifications are reused without
refitting or reselecting the marginal models.
If compatible checkerboard probability matrices were precomputed by
select_multi_margin(), they are reused when possible.
A margin object may contain a mixture of ordinary MP and ZIMP
margins.
Dependence among the latent mixed-Poisson components is represented
by a J-factor copula. The number of factors must satisfy
The factor family is controlled by latent.dependence:
"gaussian"Gaussian factor copula.
"biexp"Factor copula based on a standardized bilateral-exponential distribution.
The fitted count-layer loading matrix is denoted by and has
dimension . The parameterization guarantees
for every margin , leaving a positive idiosyncratic variance.
For Gaussian factors, latent.loglike controls likelihood evaluation.
"GH" uses Gauss–Hermite quadrature and "hermite" uses the
Hermite-based approximation implemented by the package. If
latent.loglike = NULL, the method is selected automatically.
Zero-inflated margins may additionally share a dependence structure through their activation indicators.
L = 0 specifies no factor dependence in the structural-zero layer.
L = 1 requests a one-factor zero-layer dependence model when at least
two zero-inflated margins are available.
The zero-layer factor family is specified by zero.dependence, with
supported values "gaussian" and "biexp".
If no margin is zero inflated, or if only one margin is zero inflated, no cross-margin zero-layer dependence can be estimated. Ordinary MP margins do not participate in the structural-zero dependence model.
Thus a multivariate model may contain any combination of MP and ZIMP margins.
Dependence estimation uses checkerboard interval probabilities derived
from the fitted marginal distributions. The checkerboard resolution is
controlled by d0.
These marginal quantities are computed before dependence optimization
and do not depend on the factor-loading parameters. When a compatible
cache is available in an object returned by select_multi_margin(),
it is reused where possible.
The model is fitted using an IFM strategy. Marginal parameters are
estimated first, or taken from margin, and are subsequently held
fixed while the dependence parameters are estimated.
For Gaussian count factors, gh.progressive = TRUE allows
lower-dimensional fitted factor models to be used as starting values
for higher-dimensional models.
parallel controls supported parallel computations. NULL or 1
requests serial computation; an integer greater than one requests the
corresponding level of parallelism where supported.
select_multi_margin() for selecting marginal models before
dependence fitting; fit_zimp() and select_zimp() for univariate
models; fit_bizimp() for the specialized bivariate model.
set.seed(12345) n <- 15 k <- 3 x <- rnorm(n) X <- cbind(Intercept = 1, x = x) beta <- c(0.5, 0.3) mu <- exp(X %*% beta) Y <- cbind( y1 = rpois(n, mu), y2 = rpois(n, mu), y3 = rpois(n, mu) ) ## Directly specified mixed-Poisson margins fit <- fit_multizimp( Y = Y, X = X, Z = NULL, mixing.distribution = "gamma", var.power = 2, J = 1, L = 0, d0 = 3, parallel = 1 ) fit$summary fit$count_layer$psi ## Alternatively, select the marginal models first margins <- select_multi_margin( Y = Y, X = X, Z = NULL, mixing.distribution = c("gamma", "lnorm"), var.power = 2, compute.I = TRUE, I.d0 = 3, parallel = 1 ) fit2 <- fit_multizimp( margin = margins, J = 1, L = 0, d0 = 3, parallel = 1 ) fit2$summaryset.seed(12345) n <- 15 k <- 3 x <- rnorm(n) X <- cbind(Intercept = 1, x = x) beta <- c(0.5, 0.3) mu <- exp(X %*% beta) Y <- cbind( y1 = rpois(n, mu), y2 = rpois(n, mu), y3 = rpois(n, mu) ) ## Directly specified mixed-Poisson margins fit <- fit_multizimp( Y = Y, X = X, Z = NULL, mixing.distribution = "gamma", var.power = 2, J = 1, L = 0, d0 = 3, parallel = 1 ) fit$summary fit$count_layer$psi ## Alternatively, select the marginal models first margins <- select_multi_margin( Y = Y, X = X, Z = NULL, mixing.distribution = c("gamma", "lnorm"), var.power = 2, compute.I = TRUE, I.d0 = 3, parallel = 1 ) fit2 <- fit_multizimp( margin = margins, J = 1, L = 0, d0 = 3, parallel = 1 ) fit2$summary
Fits a single univariate Mixed Poisson (MP) or Zero-Inflated Mixed Poisson (ZIMP) regression model for a specified mixing distribution and variance-power parameterization.
Both formula and matrix interfaces are supported. The count component models the mean of the Poisson mixing distribution, while an optional zero-inflation component models the probability that the count-generating component is active.
fit_zimp( formula = NULL, data = NULL, Y = NULL, X = NULL, Z = NULL, offset.count = NULL, mixing.distribution = "gamma", var.power = NULL, n_gh = 20, gh = NULL, ini.par = NULL, progress = TRUE, trace = 0, eval.max = 100, rel.tol = 1e-05, x.tol = 1e-05, iter.max = 100 )fit_zimp( formula = NULL, data = NULL, Y = NULL, X = NULL, Z = NULL, offset.count = NULL, mixing.distribution = "gamma", var.power = NULL, n_gh = 20, gh = NULL, ini.par = NULL, progress = TRUE, trace = 0, eval.max = 100, rel.tol = 1e-05, x.tol = 1e-05, iter.max = 100 )
formula |
Optional model formula. For an MP model, use a formula such
as |
data |
Optional data frame containing the variables referenced in
|
Y |
Numeric vector containing the count response for the matrix interface. Values must be finite, non-negative integers. |
X |
Numeric matrix or data frame containing the design variables for
the count component when using the matrix interface. It must have
|
Z |
Optional numeric matrix or data frame containing the design
variables for the zero-inflation component when using the matrix
interface. It must have |
offset.count |
Optional numeric offset for the count linear predictor.
For the matrix interface, it must be a finite numeric vector of length
|
mixing.distribution |
Character string specifying the mixing
distribution. One of |
var.power |
Optional variance-power specification. If |
n_gh |
Positive integer specifying the number of Gauss–Hermite
quadrature nodes when Gauss–Hermite integration is required. The default
is |
gh |
Optional precomputed Gauss–Hermite quadrature object. If |
ini.par |
Optional numeric vector of initial parameter values. Its
length must be |
progress |
Logical indicating whether fitting progress should be
displayed. The default is |
trace |
Numeric optimizer trace level. The default is |
eval.max |
Positive integer giving the maximum number of objective
function evaluations. The default is |
rel.tol |
Positive numeric value giving the relative convergence
tolerance. The default is |
x.tol |
Positive numeric value giving the parameter convergence
tolerance. The default is |
iter.max |
Positive integer giving the maximum number of optimizer
iterations. The default is |
fit_zimp() fits one specified model. It does not perform model selection
over mixing distributions or variance-power specifications. For model
selection, see select_zimp().
The conditional count model is
where the distribution of the latent intensity is determined
by mixing.distribution. The marginal mean is linked to the count
covariates through
where is an optional count offset.
For a zero-inflated model, let denote the indicator that the
count-generating component is active. The model uses
with
Thus, Z models the probability of belonging to the count-generating
component rather than the structural-zero component.
The dispersion parameter phi is constrained to be positive and is
optimized internally on the log scale.
An object of class "zimp_fit" containing the fitted model. Important
components include:
beEstimated regression coefficients for the
count component.
phiEstimated dispersion parameter on its natural scale.
gamEstimated zero-component coefficients for
a ZIMP model.
log_lik_valueMaximized log-likelihood.
neg_log_lik_valueNegative log-likelihood evaluated at the fitted parameters.
AICAkaike information criterion.
BICBayesian information criterion.
parEstimated parameter vector on the internal optimization scale.
convergenceOptimizer convergence code.
messageOptimizer convergence message, when available.
hessianEstimated Hessian matrix, when available.
vcovEstimated covariance matrix, when available.
coef_tableCoefficient and inference table produced by the fitting engine.
count_coef_tableCoefficient table for the count component.
zero_coef_tableCoefficient table for the zero component for a ZIMP model.
phi_seStandard error of the reported dispersion parameter, when available.
y, X, Z
Response and design matrices used for fitting.
offset.countCount offset used in the fitted model.
mixing.distributionMixing distribution used in the model.
var.powerVariance-power specification used in the model.
zero_inflationLogical indicating whether the fitted model contains a zero-inflation component.
nobsNumber of observations used in the fit.
nparNumber of estimated parameters.
callMatched function call.
summaryPrintable summary containing coefficient tables, dispersion, log-likelihood, AIC, BIC, and convergence information.
Additional components describing the formula, model frames, coefficient names, interface, and missing-data handling may be included when relevant.
Two input interfaces are available.
Formula interface
A Mixed Poisson model can be specified as
y ~ x1 + x2
and a Zero-Inflated Mixed Poisson model as
y ~ x1 + x2 | z1 + z2
The expression before | specifies the count component and the expression
after | specifies the zero-inflation component.
In the mzimp formula interface, intercepts are included only when
explicitly requested with 1. For example,
y ~ x1 + x2
specifies a count model without an intercept, whereas
y ~ 1 + x1 + x2
includes an intercept. The same convention applies independently to the zero-inflation component.
Matrix interface
The response and design matrices can instead be supplied directly through
Y, X, and optionally Z. If Z = NULL, an MP model is fitted. If Z
is supplied, a ZIMP model is fitted. Intercept columns, when required, must
be included explicitly in X and Z.
The following mixing distributions are supported:
"gamma"Gamma mixing distribution.
"lnorm"Lognormal mixing distribution.
"ig"Inverse Gaussian mixing distribution.
"weibull"Weibull mixing distribution.
"loglogistic"Log-logistic mixing distribution.
"betaprime"Beta-prime mixing distribution.
The optional var.power argument controls the variance-power
parameterization. If var.power = NULL, the native/default
parameterization of the selected mixing distribution is used. Otherwise,
var.power must be one of 1, 2, or 3.
Initial parameter values may be supplied through ini.par. Parameters are
ordered internally as
c(beta, log(phi), gamma)
where beta contains the count-component coefficients, log(phi) is the
log-dispersion parameter, and gamma contains the zero-component
coefficients. The gamma block is omitted for an MP model.
select_zimp() for selecting among multiple univariate MP or ZIMP model
specifications.
## Generate a small Mixed Poisson data set set.seed(12345) n <- 50 x1 <- rnorm(n) x2 <- rnorm(n) X <- cbind(1, x1, x2) mu <- exp(X %*% c(0.5, 0.3, 0.7)) ## Gamma-mixed Poisson data are Negative Binomial marginally. ## This provides a short reproducible example without relying on ## non-exported simulation functions. phi <- 0.2 y <- rnbinom(n, size = 1 / phi, mu = mu) dat <- data.frame(y = y, x1 = x1, x2 = x2) ## Formula interface fit_formula <- fit_zimp( y ~ 1 + x1 + x2, data = dat, mixing.distribution = "gamma", var.power = 2, progress = FALSE ) fit_formula ## Equivalent matrix interface fit_matrix <- fit_zimp( Y = y, X = X, mixing.distribution = "gamma", var.power = 2, progress = FALSE )## Generate a small Mixed Poisson data set set.seed(12345) n <- 50 x1 <- rnorm(n) x2 <- rnorm(n) X <- cbind(1, x1, x2) mu <- exp(X %*% c(0.5, 0.3, 0.7)) ## Gamma-mixed Poisson data are Negative Binomial marginally. ## This provides a short reproducible example without relying on ## non-exported simulation functions. phi <- 0.2 y <- rnbinom(n, size = 1 / phi, mu = mu) dat <- data.frame(y = y, x1 = x1, x2 = x2) ## Formula interface fit_formula <- fit_zimp( y ~ 1 + x1 + x2, data = dat, mixing.distribution = "gamma", var.power = 2, progress = FALSE ) fit_formula ## Equivalent matrix interface fit_matrix <- fit_zimp( Y = y, X = X, mixing.distribution = "gamma", var.power = 2, progress = FALSE )
Print a select_bizimp summary
## S3 method for class 'bizimp_selection_summary' print(x, ...)## S3 method for class 'bizimp_selection_summary' print(x, ...)
x |
An object of class |
... |
Additional arguments (currently unused). |
The summary object, invisibly.
Print a select_zimp summary
## S3 method for class 'zimp_selection_summary' print(x, ...)## S3 method for class 'zimp_selection_summary' print(x, ...)
x |
An object of class |
... |
Additional arguments (currently unused). |
The summary object, invisibly.
Performs model selection for bivariate Mixed Poisson (MP) and Zero-Inflated Mixed Poisson (ZIMP) regression models.
Marginal models are first selected independently using select_zimp().
The best margin.top models from each margin are retained, and dependence
structures are then evaluated for every retained marginal-model pair.
The final bivariate model is selected by the largest maximized
observed-data log-likelihood.
select_bizimp( formula1 = NULL, formula2 = NULL, data = NULL, Y = NULL, X = NULL, Z = NULL, mixing.distribution = c("gamma", "lnorm", "ig", "weibull", "loglogistic", "betaprime"), var.power = NULL, margin.top = 1L, mixing.copula = c(1L), d0 = 10L, n_gh = 20, gh = NULL, ini.par = NULL, parallel = NULL, progress = FALSE, show.result = FALSE, trace = 0, eval.max = 100, rel.tol = 1e-05, x.tol = 1e-05, iter.max = 100, gaussian.sign.tol = 1e-06, t.df.grid = c(3, 5, 10, 30) )select_bizimp( formula1 = NULL, formula2 = NULL, data = NULL, Y = NULL, X = NULL, Z = NULL, mixing.distribution = c("gamma", "lnorm", "ig", "weibull", "loglogistic", "betaprime"), var.power = NULL, margin.top = 1L, mixing.copula = c(1L), d0 = 10L, n_gh = 20, gh = NULL, ini.par = NULL, parallel = NULL, progress = FALSE, show.result = FALSE, trace = 0, eval.max = 100, rel.tol = 1e-05, x.tol = 1e-05, iter.max = 100, gaussian.sign.tol = 1e-06, t.df.grid = c(3, 5, 10, 30) )
formula1 |
Optional formula specifying the first marginal model.
The syntax follows |
formula2 |
Optional formula specifying the second marginal model.
The syntax follows |
data |
Optional data frame containing the variables referenced by
|
Y |
Response for the direct matrix interface. Either an
|
X |
Count-component design for the direct matrix interface. May be one numeric matrix/data frame shared by both margins or a list containing two margin-specific design matrices. Include intercept columns explicitly when required. |
Z |
Optional zero-component design for the direct matrix interface.
May be |
mixing.distribution |
Character vector specifying candidate marginal
mixing distributions passed to |
var.power |
Optional numeric vector specifying candidate
variance-power parameterizations passed to |
margin.top |
Positive integer specifying the maximum number of
independently ranked marginal models retained from each margin.
The default is |
mixing.copula |
Integer vector containing one or more candidate
|
d0 |
Positive integer specifying the checkerboard grid size used
to discretize the mixing copulas. The default is |
n_gh |
Positive integer specifying the number of Gauss–Hermite
quadrature nodes used when required by the marginal calculations.
The default is |
gh |
Optional precomputed Gauss–Hermite quadrature object passed
to the marginal-selection and dependence calculations. If |
ini.par |
|
parallel |
|
progress |
Logical compatibility argument retained for the public
interface. |
show.result |
Logical compatibility argument retained for the public interface. Results are stored in the returned object rather than printed during fitting. |
trace |
Numeric optimizer trace argument retained for compatibility. The current selection interface performs fitting silently. |
eval.max |
Positive integer giving the maximum number of
objective-function evaluations used by the marginal and dependence
optimizers. The default is |
rel.tol |
Positive numeric value giving the relative convergence
tolerance passed to the marginal model-selection routines. The default
is |
x.tol |
Positive numeric value giving the parameter convergence
tolerance passed to the marginal model-selection routines. The default
is |
iter.max |
Positive integer giving the maximum number of optimization
iterations. The default is |
gaussian.sign.tol |
Non-negative numeric tolerance used to determine
whether the Gaussian prescreen provides an informative dependence
direction. The default is |
t.df.grid |
Integer vector containing candidate degrees of freedom
greater than two for Student-t mixing copulas. The default is
|
select_bizimp() extends select_zimp() from univariate marginal
selection to bivariate model selection. In contrast to fit_bizimp(),
which fits one specified bivariate model, select_bizimp() searches over
marginal specifications and mixing-copula families.
The selection procedure consists of three stages:
Select candidate models independently for each margin using
select_zimp().
Retain the best margin.top models from each margin and perform
a Gaussian dependence prescreen for every retained marginal pair.
Fit the compatible user-requested mixing copulas, together with the admissible zero-dependence structures, and select the candidate with the largest maximized bivariate log-likelihood.
An object of class "bizimp_selection". Important components include:
margin_selection_1, margin_selection_2
Results from the independent select_zimp() selections for margins
1 and 2.
margin_topRequested maximum number of marginal models retained from each margin.
retained_margin_1, retained_margin_2
Lists of fitted marginal models retained for the dependence search.
pair_resultsDetailed dependence-search results for every retained marginal pair, including the Gaussian prescreen, compatible mixing-copula families, zero-dependence candidates, and fitted dependence models.
candidate_tableData frame containing all fitted bivariate candidates, with columns describing margin 1, margin 2, zero dependence, mixing dependence, maximized log-likelihood, AIC, and BIC. Rows are ordered by decreasing log-likelihood.
pair_summaryData frame containing the best dependence model obtained for each retained marginal pair, ordered by decreasing bivariate log-likelihood.
best_pairDetailed result for the retained marginal pair containing the globally selected bivariate model.
best_modelSelected dependence model. It contains the selected mixing-copula family and parameter estimates, zero-dependence parameter when applicable, maximized bivariate log-likelihood, convergence information, total parameter count, AIC, and BIC.
best_dependenceComplete dependence-engine result associated with best_model.
best_margin_1, best_margin_2
Fitted marginal models belonging to the globally selected bivariate model.
interfaceCharacter string identifying whether the formula or direct matrix interface was used.
formula1, formula2
Marginal formulas when the formula interface was used.
mixing.copula.candidatesUser-requested candidate mixing-copula family codes.
summaryObject of class "bizimp_selection_summary" containing the candidate
table, selected candidate, pair summary, and matched call for formatted
display.
callMatched call to select_bizimp().
Two input interfaces are supported.
Formula interface
Supply formula1, formula2, and data. Each formula follows the
syntax used by select_zimp(). For example,
formula1 = y1 ~ 1 + x1 + x2 | z1 + z2 formula2 = y2 ~ 1 + x1 + x2
specifies a ZIMP first margin and an MP second margin.
The expression before | specifies the count component and the
expression after | specifies the zero-inflation component.
Intercepts are included only when explicitly requested with 1.
Both formulas must refer to the same observations. If missing values cause different observations to be retained for the two margins, bivariate model selection is stopped.
Matrix interface
Alternatively, supply Y, X, and optionally Z.
Y may be an matrix/data frame or a list containing
two count vectors. X may be a design matrix shared by both margins or
a list containing two margin-specific design matrices.
Z = NULL specifies two MP margins. A shared matrix/data frame Z
specifies two ZIMP margins. A list may be used for mixed configurations;
for example, Z = list(Z1, NULL) specifies ZIMP–MP and
Z = list(NULL, Z2) specifies MP–ZIMP.
Each margin is selected independently using select_zimp() with the
candidate mixing distributions supplied in mixing.distribution and
the variance-power specifications supplied in var.power.
Supported mixing distributions are:
"gamma"Gamma mixing distribution.
"lnorm"Lognormal mixing distribution.
"ig"Inverse Gaussian mixing distribution.
"weibull"Weibull mixing distribution.
"loglogistic"Log-logistic mixing distribution.
"betaprime"Beta-prime mixing distribution.
If var.power = NULL, each distribution uses its native/default
variance-power specification. Otherwise, every requested mixing
distribution is crossed with the requested variance powers, following
the candidate construction used by select_zimp().
Marginal candidates are ranked by decreasing maximized univariate
log-likelihood. At most margin.top models are retained from each margin.
If and models are retained from margins 1 and 2,
respectively, dependence selection is performed for
marginal-model pairs.
Thus, margin.top = 1 restricts the dependence search to the independently
best marginal model from each margin.
Dependence between the two latent mixing variables is specified using
bivariate VineCopula family codes. mixing.copula may contain one or
more candidate families.
Supported family codes are:
0LIndependence copula.
1LGaussian copula.
2LStudent-t copula.
3LClayton copula.
4LGumbel copula.
5LFrank copula.
6LJoe copula.
7LBB1 copula.
8LBB6 copula.
9LBB7 copula.
10LBB8 copula.
13L, 14L, 16L–20L
180-degree rotations of the corresponding Archimedean and BB families.
23L, 24L, 26L–30L
90-degree rotations of the corresponding Archimedean and BB families.
33L, 34L, 36L–40L
270-degree rotations of the corresponding Archimedean and BB families.
104L, 114L, 124L, 134L,
204L, 214L, 224L, 234L
Supported Tawn families and their rotations.
The default is mixing.copula = 1L, corresponding to the Gaussian
copula.
For example,
mixing.copula = 1L # Gaussian only mixing.copula = c(1L, 3L, 5L) # Gaussian, Clayton, and Frank
For the Student-t copula (2L), the correlation parameter is optimized
for each degrees-of-freedom value supplied in t.df.grid, and the
likelihood-maximizing specification is retained.
For every retained marginal pair, a Gaussian checkerboard copula is fitted first to the latent mixing variables. This fit is used only as a prescreen for the sign of the mixing dependence.
If the absolute fitted Gaussian correlation exceeds
gaussian.sign.tol, user-requested copula families incompatible with
that dependence direction are removed before the full dependence search.
If the fitted correlation is not finite or does not exceed the tolerance,
no sign restriction is imposed.
If sign filtering would remove all user-requested families, all requested families are restored. Consequently, the prescreen never introduces a mixing-copula family that was not requested by the user.
The Gaussian family is fitted internally for this prescreen even when
1L is not included in mixing.copula, but it is eligible for final
selection only when explicitly requested.
When both retained margins are ZIMP models, dependence between their Bernoulli activation indicators is also selected. For every compatible mixing copula, the following three zero-dependence specifications are evaluated:
Gaussian copula dependence with an estimated correlation parameter.
Comonotone dependence at the upper Frechet bound.
Countermonotone dependence at the lower Frechet bound.
Thus, for a ZIMP–ZIMP marginal pair, the full dependence search crosses each compatible mixing-copula family with all three zero-dependence specifications.
If either margin is an MP model, the zero-dependence layer is inactive.
The complete candidate set consists of the fitted combinations of
Candidates are evaluated using the full bivariate observed-data
likelihood. candidate_table is sorted by decreasing maximized
log-likelihood, and its first row corresponds to the selected model.
AIC and BIC are also calculated for each candidate. Their parameter counts include both marginal models, the mixing-copula parameters, and the Gaussian zero-copula correlation parameter when applicable. AIC and BIC are reported for comparison but are not used for model selection.
parallel is passed to select_zimp() and controls parallel fitting of
candidate marginal models within each margin.
The two marginal selections themselves are performed sequentially.
Dependence searches across retained marginal pairs, mixing copulas, and
zero-dependence specifications are also performed sequentially by
select_bizimp().
fit_bizimp() for fitting one specified bivariate model,
select_zimp() for univariate marginal model selection, and
fit_zimp() for fitting one specified univariate marginal model.
## Generate a small bivariate Mixed Poisson data set set.seed(12345) n <- 30 x1 <- rnorm(n) x2 <- rnorm(n) X <- cbind(1, x1, x2) mu1 <- exp(X %*% c(0.5, 0.3, 0.7)) mu2 <- exp(X %*% c(0.3, 0.5, 0.4)) ## Gamma-mixed Poisson margins can be generated from negative-binomial ## distributions for this short reproducible example. y1 <- rnbinom(n, size = 1 / 0.2, mu = mu1) y2 <- rnbinom(n, size = 1 / 0.3, mu = mu2) Y <- cbind(y1, y2) ## Compare several mixing-copula families while retaining only the ## independently best marginal model from each margin. sel <- select_bizimp( Y = Y, X = X, Z = NULL, mixing.distribution = "gamma", var.power = 2, margin.top = 1L, mixing.copula = c(1L, 3L, 5L) ) ## Candidate models are ordered by decreasing log-likelihood sel$candidate_table ## Selected marginal and dependence models sel$best_margin_1 sel$best_margin_2 sel$best_model## Generate a small bivariate Mixed Poisson data set set.seed(12345) n <- 30 x1 <- rnorm(n) x2 <- rnorm(n) X <- cbind(1, x1, x2) mu1 <- exp(X %*% c(0.5, 0.3, 0.7)) mu2 <- exp(X %*% c(0.3, 0.5, 0.4)) ## Gamma-mixed Poisson margins can be generated from negative-binomial ## distributions for this short reproducible example. y1 <- rnbinom(n, size = 1 / 0.2, mu = mu1) y2 <- rnbinom(n, size = 1 / 0.3, mu = mu2) Y <- cbind(y1, y2) ## Compare several mixing-copula families while retaining only the ## independently best marginal model from each margin. sel <- select_bizimp( Y = Y, X = X, Z = NULL, mixing.distribution = "gamma", var.power = 2, margin.top = 1L, mixing.copula = c(1L, 3L, 5L) ) ## Candidate models are ordered by decreasing log-likelihood sel$candidate_table ## Selected marginal and dependence models sel$best_margin_1 sel$best_margin_2 sel$best_model
Fits and selects a univariate Mixed Poisson (MP) or Zero-Inflated Mixed Poisson (ZIMP) model independently for each margin of a multivariate count response.
Candidate models may differ in mixing distribution, variance-power specification, and, when requested, the presence or absence of zero inflation. The best model for each margin is selected using AIC or BIC.
select_multi_margin() is designed primarily as the marginal-selection
stage preceding fit_multizimp(). It supports common or
margin-specific count and zero-component designs, serial or parallel
computation, and optional precomputation of the checkerboard
interval-probability matrices required by the multivariate dependence
model.
select_multi_margin( Y, X, Z = NULL, X.columns = NULL, Z.columns = NULL, check.zero = FALSE, selection.criterion = c("BIC", "AIC"), mixing.distribution = c("gamma", "lnorm", "ig", "weibull", "loglogistic", "betaprime"), var.power = NULL, benchmark.distribution = "lnorm", ini.par = NULL, parallel = NULL, block_size = NULL, compute.I = FALSE, I.d0 = 10L, progress = FALSE, show.result = FALSE, trace = 0, eval.max = 100, iter.max = 100, rel.tol = 1e-05, x.tol = 1e-05, n_gh = 20, gh = NULL, seed = NULL )select_multi_margin( Y, X, Z = NULL, X.columns = NULL, Z.columns = NULL, check.zero = FALSE, selection.criterion = c("BIC", "AIC"), mixing.distribution = c("gamma", "lnorm", "ig", "weibull", "loglogistic", "betaprime"), var.power = NULL, benchmark.distribution = "lnorm", ini.par = NULL, parallel = NULL, block_size = NULL, compute.I = FALSE, I.d0 = 10L, progress = FALSE, show.result = FALSE, trace = 0, eval.max = 100, iter.max = 100, rel.tol = 1e-05, x.tol = 1e-05, n_gh = 20, gh = NULL, seed = NULL )
Y |
An |
X |
Count-component design. Either a numeric matrix/data frame
shared by all margins or a list of length |
Z |
Optional zero-component design. May be |
X.columns |
Optional list of length |
Z.columns |
Optional list of length |
check.zero |
Logical. If |
selection.criterion |
Character string specifying the information
criterion used to select the best model independently for each margin.
Either |
mixing.distribution |
Character vector specifying candidate mixing
distributions. Supported values are |
var.power |
|
benchmark.distribution |
Character string specifying the benchmark
marginal distribution used for reporting. Supported values are
|
ini.par |
Optional initial parameter specification. It may be a
list of length |
parallel |
|
block_size |
|
compute.I |
Logical. If |
I.d0 |
Integer greater than or equal to |
progress |
Deprecated and ignored. Retained for API compatibility.
|
show.result |
Deprecated and ignored. Retained for API compatibility. Selection results are stored in the returned object. |
trace |
Deprecated and ignored. Retained for API compatibility.
|
eval.max |
Positive integer giving the maximum number of objective-function evaluations for each marginal fit. |
iter.max |
Positive integer giving the maximum number of optimizer iterations for each marginal fit. |
rel.tol |
Positive numeric value giving the relative convergence tolerance for marginal fitting. |
x.tol |
Positive numeric value giving the parameter convergence tolerance for marginal fitting. |
n_gh |
Positive integer giving the number of Gauss–Hermite
quadrature nodes used when required by marginal calculations.
The default is |
gh |
Optional precomputed Gauss–Hermite quadrature object. If
|
seed |
Optional integer seed used to initialize reproducible random-number streams in parallel execution. |
Let
denote an multivariate count response. The function
fits a collection of candidate univariate models separately to each
margin and selects the best marginal model according to
selection.criterion.
Marginal selection does not estimate dependence between response
margins. Dependence estimation is performed subsequently by
fit_multizimp().
An object of class "multi_margin_fit" containing the marginal-selection
results and the information required by fit_multizimp(). The public
components are:
YValidated response matrix.
X, Z
Count- and zero-component designs after internal conversion.
X_is_list, Z_is_list
Logical indicators identifying whether the corresponding designs are stored as margin-specific lists.
X_columns, Z_columns
Margin-specific column selections when common designs were supplied.
selected_marginsList of length k containing the selected marginal models. Each
element has class "mzimp_margin_fit" and contains, among other
quantities, the selected mixing distribution, variance power,
zero-inflation status, count coefficients (be), dispersion
parameter (phi), zero-component coefficients (gam) when
applicable, and maximized marginal log-likelihood.
benchmark.distributionMixing distribution used as the benchmark.
benchmark_by_marginBenchmark-fit information for individual response margins.
benchmarkSummary of the comparison between the selected models and the benchmark, including marginal and aggregate log-likelihood gains.
selected_summaryData frame with one row per response margin describing the selected distribution, variance power, zero-inflation status, log-likelihood, AIC, BIC, benchmark log-likelihood, and gain relative to the benchmark.
I_precomputedLogical indicating whether the checkerboard probability cache was computed.
I_d0Checkerboard grid size used for the cache, or NULL when
compute.I = FALSE.
I_y_list, I_0_list
Lists of checkerboard interval-probability matrices evaluated at
observed counts and at zero, respectively, when compute.I = TRUE;
otherwise NULL.
pb_listList of Bernoulli activation-probability vectors when
compute.I = TRUE; otherwise NULL.
y0_listList of observed-zero indicators for ZIMP margins when
compute.I = TRUE. Elements corresponding to MP margins are NULL.
mixing.distribution, var.power
Candidate marginal specifications requested by the user.
candidate_gridData frame describing the candidate marginal specifications participating in model selection.
check.zeroLogical indicating whether MP versus intercept-only ZIMP comparison
was requested when Z = NULL.
selection.criterionInformation criterion used for marginal model selection.
n, k
Number of observations and response margins.
response_namesNames of the response margins.
parallel, n_workers
Requested parallel setting and the actual number of workers used.
performanceTiming and, when available, memory-use information for marginal fitting and optional checkerboard-cache computation.
summaryA regular list containing selected_summary, benchmark information,
selection criterion, response dimensions and names, and performance
information.
Y must be an numeric matrix or data frame containing
finite, non-negative integer counts. Each column represents one response
margin.
The count-component design X can be supplied either as:
one matrix or data frame shared by all margins; or
a list of length k containing a separate design for each margin.
When a common X is supplied, X.columns may be used to specify a
different subset of columns for each margin.
The zero-component design Z follows the same convention. It may be
NULL, a common matrix/data frame, or a list of length k.
No intercept is added automatically to either X or Z. Include an
intercept column explicitly when required.
Data-frame designs may contain numeric, integer, logical, factor, and character variables. Character variables are converted to factors and categorical variables are expanded internally into numeric design columns.
The interpretation of Z determines whether a margin is fitted as an
ordinary MP model or as a ZIMP model.
Z = NULL, check.zero = FALSE
All margins are fitted as ordinary MP models.
Z
All margins are fitted as ZIMP models using the supplied zero-component design.
Z supplied as a listEach margin is specified independently. Z[[j]] = NULL gives an MP
margin, whereas a non-NULL Z[[j]] gives a ZIMP margin.
Z = NULL, check.zero = TRUE
For every marginal distribution and variance-power specification, both an MP model and an intercept-only ZIMP model are considered. The presence or absence of zero inflation is therefore selected independently for each margin.
If Z is explicitly supplied, check.zero is ignored.
For a ZIMP margin, the zero-component regression models the Bernoulli
activation probability. If denotes the activation indicator,
Thus, corresponds to the count-generating component and
to a structural zero.
The following mixing distributions are supported:
"gamma"Gamma mixing distribution.
"lnorm"Lognormal mixing distribution.
"ig"Inverse-Gaussian mixing distribution.
"weibull"Weibull mixing distribution.
"loglogistic"Log-logistic mixing distribution.
"betaprime"Beta-prime mixing distribution.
If var.power is supplied, every requested mixing distribution is
crossed with every requested variance power. For example,
mixing.distribution = c("gamma", "lnorm")
var.power = c(1, 2, 3)
defines six distribution–variance-power specifications before any MP/ZIMP expansion.
If var.power = NULL, each distribution uses its native/default
variance-power parameterization:
2
2
3
2
2
2
The complete candidate specifications used for marginal selection are
returned in candidate_grid.
Candidate models are fitted independently for each response margin.
The selected model minimizes the information criterion specified by
selection.criterion.
For selection.criterion = "BIC",
whereas for selection.criterion = "AIC",
where is the maximized marginal log-likelihood and
is the number of estimated marginal parameters.
Selection is performed separately for every margin. Consequently,
different response margins may select different mixing distributions,
variance powers, and, when check.zero = TRUE, different MP/ZIMP
specifications.
Candidate fitting uses the same initialization strategy as
select_zimp(). Gamma, lognormal, and inverse-Gaussian models use
distribution-specific initialization. Weibull, log-logistic, and
beta-prime models use fitted Gamma models with the same effective
variance power to initialize their regression coefficients, while
retaining distribution-specific initialization for dispersion.
Gamma models required only for initialization are internal fits and do not participate in final model selection unless the corresponding Gamma specification was explicitly requested.
benchmark.distribution specifies a reference marginal distribution
used to compare the selected marginal models. Supported benchmark
distributions are "lnorm", "gamma", and "ig".
The benchmark is fitted using its native/default variance-power parameterization under the corresponding zero-inflation specification. It is used only for reporting and does not affect marginal model selection.
The returned object contains the benchmark log-likelihood for each margin and the log-likelihood gain of the selected model relative to the benchmark.
Candidate marginal models can be fitted in parallel.
If parallel = NULL or parallel = 1, fitting is serial. If
parallel is an integer greater than one, a PSOCK cluster is created
and marginal-model fitting jobs are distributed across workers.
Parallelization is across independent margin–candidate fitting jobs. The number of workers actually used is bounded by the number of available fitting tasks.
block_size optionally controls how fitting jobs are grouped for
load-balanced parallel execution. If block_size = NULL, an
appropriate block size is selected automatically.
Serial and parallel execution use the same model-selection procedure and return the same public result structure.
If compute.I = TRUE, checkerboard interval probabilities are
precomputed for each selected marginal model for subsequent use by
fit_multizimp().
For each margin , the cache contains:
I_y_list[[j]]An matrix of interval probabilities evaluated at
the observed counts, where is I.d0.
I_0_list[[j]]An matrix of interval probabilities evaluated at
zero.
pb_list[[j]]Bernoulli activation probabilities. For an MP margin this is a
vector of ones. For a ZIMP margin it is
.
y0_list[[j]]Logical indicator of observed zeros for a ZIMP margin. It is NULL
for an MP margin.
The checkerboard resolution is controlled by I.d0.
If compute.I = FALSE, no cache is created and I_d0, I_y_list,
I_0_list, pb_list, and y0_list are returned as NULL.
fit_multizimp() for fitting the multivariate dependence model after
marginal selection, select_zimp() for selecting a univariate marginal
model, and fit_zimp() for fitting one specified univariate model.
set.seed(12345) n <- 30 k <- 3 x1 <- rnorm(n) x2 <- rnorm(n) X <- cbind(Intercept = 1, x1 = x1, x2 = x2) Y <- cbind( y1 = rpois(n, exp(0.5 + 0.3 * x1 + 0.2 * x2)), y2 = rpois(n, exp(0.3 - 0.2 * x1 + 0.3 * x2)), y3 = rpois(n, exp(0.4 + 0.1 * x1 - 0.2 * x2)) ) ## Select among Gamma and lognormal marginal models fit <- select_multi_margin( Y = Y, X = X, Z = NULL, mixing.distribution = c("gamma", "lnorm"), var.power = 2, selection.criterion = "BIC", parallel = 1 ) ## One selected model per response margin fit$selected_summary ## Selected marginal model objects fit$selected_marginsset.seed(12345) n <- 30 k <- 3 x1 <- rnorm(n) x2 <- rnorm(n) X <- cbind(Intercept = 1, x1 = x1, x2 = x2) Y <- cbind( y1 = rpois(n, exp(0.5 + 0.3 * x1 + 0.2 * x2)), y2 = rpois(n, exp(0.3 - 0.2 * x1 + 0.3 * x2)), y3 = rpois(n, exp(0.4 + 0.1 * x1 - 0.2 * x2)) ) ## Select among Gamma and lognormal marginal models fit <- select_multi_margin( Y = Y, X = X, Z = NULL, mixing.distribution = c("gamma", "lnorm"), var.power = 2, selection.criterion = "BIC", parallel = 1 ) ## One selected model per response margin fit$selected_summary ## Selected marginal model objects fit$selected_margins
Fits and compares multiple univariate Mixed Poisson (MP) or Zero-Inflated Mixed Poisson (ZIMP) regression models across candidate mixing distributions and variance-power specifications. Candidate models are ranked by maximized log-likelihood, and the model with the largest log-likelihood is selected.
select_zimp( formula = NULL, data = NULL, Y = NULL, X = NULL, Z = NULL, offset.count = NULL, mixing.distribution = c("gamma", "lnorm", "ig", "weibull", "loglogistic", "betaprime"), var.power = NULL, n_gh = 20, gh = NULL, ini.par = NULL, parallel = NULL, progress = TRUE, show.result = TRUE, trace = 0, eval.max = 100, rel.tol = 1e-05, x.tol = 1e-05, iter.max = 100, .return.all = FALSE )select_zimp( formula = NULL, data = NULL, Y = NULL, X = NULL, Z = NULL, offset.count = NULL, mixing.distribution = c("gamma", "lnorm", "ig", "weibull", "loglogistic", "betaprime"), var.power = NULL, n_gh = 20, gh = NULL, ini.par = NULL, parallel = NULL, progress = TRUE, show.result = TRUE, trace = 0, eval.max = 100, rel.tol = 1e-05, x.tol = 1e-05, iter.max = 100, .return.all = FALSE )
formula |
Optional model formula. For an MP model, use a formula such
as |
data |
Optional data frame containing the variables referenced in
|
Y |
Numeric vector containing the count response for the matrix interface. Values must be finite, non-negative integers. |
X |
Numeric matrix or data frame containing the design variables for
the count component when using the matrix interface. It must have
|
Z |
Optional numeric matrix or data frame containing the design
variables for the zero-inflation component when using the matrix
interface. It must have |
offset.count |
Optional numeric offset for the count linear predictor.
For the matrix interface, it must be a finite numeric vector of length
|
mixing.distribution |
Character vector specifying one or more
candidate mixing distributions. Supported values are |
var.power |
Optional numeric vector specifying one or more
variance-power parameterizations. Values must be selected from |
n_gh |
Positive integer specifying the number of Gauss–Hermite
quadrature nodes when Gauss–Hermite integration is required. The default
is |
gh |
Optional precomputed Gauss–Hermite quadrature object. If |
ini.par |
Optional numeric vector of initial parameter values. Its
length must be |
parallel |
|
progress |
Logical indicating whether fitting progress should be
displayed. The default is |
show.result |
Logical compatibility argument. Selection is performed
silently and results are stored in the returned object. The selection
report can be displayed by evaluating or printing the |
trace |
Numeric optimizer trace level. The default is |
eval.max |
Positive integer giving the maximum number of objective
function evaluations. The default is |
rel.tol |
Positive numeric value giving the relative convergence
tolerance. The default is |
x.tol |
Positive numeric value giving the parameter convergence
tolerance. The default is |
iter.max |
Positive integer giving the maximum number of optimizer
iterations. The default is |
.return.all |
Logical. Internal-use option. If |
select_zimp() is the model-selection counterpart of fit_zimp().
While fit_zimp() fits one fully specified model, select_zimp() fits a
collection of candidate models and returns the best-fitting specification.
The function supports the same formula and matrix interfaces as
fit_zimp().
An object of class "zimp_selection". By default, the object contains:
summary_tableA data frame containing one row for each requested candidate model,
ordered by decreasing maximized log-likelihood. Columns include
distribution, var.power, log_lik, neg_log_lik, and phi.
best_modelThe selected model, returned as an object of class "zimp_fit".
It corresponds to the first row of summary_table and contains full
post-estimation inference.
summaryAn object of class "zimp_selection_summary" containing the candidate
table and selected model for formatted display.
callThe matched call to select_zimp().
If .return.all = TRUE, an additional internal component all_results
containing the candidate fit objects is returned.
Formula interface
A Mixed Poisson model can be specified as
y ~ x1 + x2
and a Zero-Inflated Mixed Poisson model as
y ~ x1 + x2 | z1 + z2
The expression before | specifies the count component and the expression
after | specifies the zero-inflation component.
In the mzimp formula interface, intercepts are included only when
explicitly requested with 1. Thus,
y ~ x1 + x2
specifies a model without an intercept, whereas
y ~ 1 + x1 + x2
includes an intercept. The same convention applies independently to the zero-inflation component.
Matrix interface
The response and design matrices may instead be supplied through Y, X,
and optionally Z. If Z = NULL, MP candidate models are fitted. If Z
is supplied, ZIMP candidate models are fitted. Intercept columns, when
required, must be included explicitly in X and Z.
Candidate models are generated from the requested mixing.distribution
and var.power values.
The supported mixing distributions are "gamma", "lnorm", "ig",
"weibull", "loglogistic", and "betaprime".
If var.power = NULL, one model is fitted for each requested mixing
distribution using its native/default variance-power specification:
"gamma"var.power = 2
"lnorm"var.power = 2
"ig"var.power = 3
"weibull"var.power = 2
"loglogistic"var.power = 2
"betaprime"var.power = 2
If one or more values are supplied to var.power, every requested mixing
distribution is fitted for each requested variance power. For example,
mixing.distribution = c("gamma", "lnorm")
var.power = c(1, 2, 3)
defines six candidate models.
Duplicate distribution and variance-power specifications are removed before fitting.
Candidate models are fitted by maximum likelihood using the same
distribution-specific likelihood and gradient routines as fit_zimp().
Gamma, lognormal, and inverse-Gaussian candidates are fitted directly. Weibull, log-logistic, and beta-prime candidates use matched Gamma models as initialization anchors. For these candidates, the count coefficients and, for ZIMP models, the zero-component coefficients are initialized from a Gamma model with the same effective variance power. The dispersion parameter is initialized using the target distribution's own initialization procedure.
When a required Gamma anchor is not among the requested candidate models, it is fitted internally for initialization only and is not included in the returned candidate table.
Candidate models are initially fitted without post-estimation inference.
They are then ordered by decreasing maximized log-likelihood. The first row
of summary_table therefore corresponds to the selected model.
Full post-estimation inference is subsequently computed only for the
selected model, at its already optimized parameter estimates; the selected
model is not re-optimized. The resulting best_model is an object of class
"zimp_fit".
Selection is based exclusively on maximized log-likelihood. AIC and BIC
are available for the selected model through best_model, but are not
used to rank candidate models.
Candidate models within the same fitting stage may be evaluated in
parallel by setting parallel to an integer greater than one.
Parallelization is performed across candidate models; optimization of an
individual candidate is not itself parallelized by select_zimp().
Dependencies between fitting stages, including construction of Gamma
initialization anchors, are preserved.
On Unix-like systems, fork-based parallel processing may be used. On Windows, PSOCK workers are used.
fit_zimp() for fitting one specified univariate MP or ZIMP model.
## Generate a small Mixed Poisson data set set.seed(12345) n <- 50 x1 <- rnorm(n) x2 <- rnorm(n) X <- cbind(1, x1, x2) mu <- exp(X %*% c(0.5, 0.3, 0.7)) ## Gamma-mixed Poisson data phi <- 0.2 y <- rnbinom(n, size = 1 / phi, mu = mu) dat <- data.frame(y = y, x1 = x1, x2 = x2) ## Compare candidate mixing distributions sel <- select_zimp( y ~ 1 + x1 + x2, data = dat, mixing.distribution = c("gamma", "lnorm", "ig"), progress = FALSE ) ## Ranked candidate models sel$summary_table ## Selected model sel$best_model ## Compare variance-power specifications sel_power <- select_zimp( Y = y, X = X, mixing.distribution = c("gamma", "lnorm"), var.power = c(1, 2, 3), progress = FALSE ) sel_power$summary_table## Generate a small Mixed Poisson data set set.seed(12345) n <- 50 x1 <- rnorm(n) x2 <- rnorm(n) X <- cbind(1, x1, x2) mu <- exp(X %*% c(0.5, 0.3, 0.7)) ## Gamma-mixed Poisson data phi <- 0.2 y <- rnbinom(n, size = 1 / phi, mu = mu) dat <- data.frame(y = y, x1 = x1, x2 = x2) ## Compare candidate mixing distributions sel <- select_zimp( y ~ 1 + x1 + x2, data = dat, mixing.distribution = c("gamma", "lnorm", "ig"), progress = FALSE ) ## Ranked candidate models sel$summary_table ## Selected model sel$best_model ## Compare variance-power specifications sel_power <- select_zimp( Y = y, X = X, mixing.distribution = c("gamma", "lnorm"), var.power = c(1, 2, 3), progress = FALSE ) sel_power$summary_table