Package {ZIHINAR1}


Type: Package
Title: Zero-Inflated and Hurdle INAR(1) Models
Version: 0.3.1
Maintainer: Fusheng Yang <fusheng.yang@uconn.edu>
Description: Provides tools for estimating Zero-Inflated INAR(1) (ZI-INAR(1)) and Hurdle INAR(1) (H-INAR(1)) models using 'Stan'. It allows users to simulate time series data for these models, estimate parameters, and evaluate model fit using various criteria. Functions include model estimation, simulation, and likelihood-based metrics. The zero-inflated and hurdle INAR(1) methods are described by Yang et al. (2025) <doi:10.1214/25-BJPS646>. Zero-inflated models also support Conway-Maxwell-Poisson innovations.
License: GPL-3
Encoding: UTF-8
Imports: rstan, VGAM, actuar, matrixStats, coda, ggplot2, gridExtra, stats, knitr, utils, HMMpa, COMPoissonReg
Suggests: testthat (≥ 3.0.0), rmarkdown
Depends: R (≥ 4.0.0)
Config/roxygen2/version: 8.1.1
NeedsCompilation: no
Packaged: 2026-11-10 20:20:04 UTC; ivyyang
Author: Fusheng Yang [aut, cre], Victor Hugo Lachos Davila [aut], Alokesh Manna [aut], Dipak K. Dey [aut]
Repository: CRAN
Date/Publication: 2026-11-10 22:10:02 UTC

Simulate Time Series Data for ZI-INAR(1) or H-INAR(1) Models

Description

This function simulates time series data for Zero-Inflated INAR(1) (ZI-INAR(1)) or Hurdle INAR(1) (H-INAR(1)) models, using Poisson, Negative Binomial, Generalized Poisson, or Conway-Maxwell-Poisson (CMP) innovations.

Usage

data_simu(n, alpha, rho, lambda, disp = NULL, mod_type, distri)

Arguments

n

Integer specifying the number of observations to simulate.

alpha

Numeric value between 0 and 1 representing the autoregressive parameter (strictly between 0 and 1).

rho

Numeric value between 0 and 1 representing the zero-inflation or hurdle parameter.

lambda

Numeric value (> 0) representing the location parameter (mean) for Poisson, or the location parameter for NB, GP, and CMP distributions. For CMP this is the rate parameter, not generally the mean.

disp

Numeric value representing the dispersion parameter.

  • For "nb": Must be positive (> 0).

  • For "gp": Must be strictly between 0 and 1 (0 < disp < 1).

  • For "cmp": The CMP parameter nu; must be positive (> 0). Values below 1 give overdispersed CMP innovations; 1 gives Poisson; values above 1 give underdispersed CMP innovations before zero inflation.

  • For "poi": Ignored.

mod_type

Character string indicating the model type ("zi" or "h").

distri

Character string specifying the distribution. Options are:

  • "poi" for Poisson

  • "nb" for Negative Binomial

  • "gp" for Generalized Poisson (Only mod_type="zi" supported)

  • "cmp" for Conway-Maxwell-Poisson (Only mod_type="zi" supported)

Details

The first 100 observations are discarded as burn-in. Zero inflation applies to the innovations, not directly to the series. For an ordinary CMP-INAR(1) process use rho = 0. This simulates CMP innovations, not a CMP stationary marginal distribution.

Value

A numeric vector containing the simulated time series data.

References

Part of the implementation of this function was adapted from the ZINAR1 package. The ZINAR1 package simulates first-order integer-valued autoregressive processes with zero-inflated innovations (ZINAR(1)) and estimates its parameters under a frequentist approach.

For more information about the ZINAR1 package, please refer to:

Aldo M. Garay, João Vitor Ribeiro (2022). ZINAR1: Simulates ZINAR(1) Model and Estimates Its Parameters Under Frequentist Approach. R package version 0.1.0. Available at: https://CRAN.R-project.org/package=ZINAR1.

Garay, A. M., Ribeiro, J. V. (2021). First-Order Integer Valued AR Processes with Zero-Inflated Innovations. In: Nonstationary Systems: Theory and Applications, Springer. DOI: doi:10.1007/978-3-030-82110-4_2.

We acknowledge the original authors, Aldo M. Garay and João Vitor Ribeiro, for their contributions.

Examples

# Simulate 50 observations from a Zero-Inflated Poisson INAR(1) model
y_data <- data_simu(n = 50, alpha = 0.5, rho = 0.3, lambda = 5,
                    mod_type = "zi", distri = "poi")
head(y_data)

# Simulate a zero-inflated CMP-INAR(1) series (disp is nu)
y_cmp <- data_simu(n = 50, alpha = 0.5, rho = 0.3, lambda = 2.5,
                   disp = 1.2, mod_type = "zi", distri = "cmp")


Get Parameter Estimates from Stan Model Fit

Description

Extracts parameter estimates from a Stan model fit, including mean, median, standard deviation, and HPD intervals.

Usage

get_est(distri, stan_fit)

Arguments

distri

Character string specifying the distribution. Options are "poi", "nb", "gp", or "cmp".

stan_fit

A stanfit object returned by get_stanfit.

Value

A summary of the parameter estimates.

Examples


  # Generate toy data
  y_data <- data_simu(n = 60, alpha = 0.5, rho = 0.3, lambda = 5,
                      mod_type = "zi", distri = "poi")

  # Fit a small Stan model (may take > 5s on first compile)
  stan_fit <- get_stanfit(mod_type = "zi", distri = "poi", y = y_data)

  # Get parameter estimates from the Stan model fit
  get_est(distri = "poi", stan_fit = stan_fit)



Get Model Selection Criteria

Description

Calculates model selection criteria such as AIC, BIC, DIC, and WAIC from a Stan model fit.

Usage

get_mod_sel(y, mod_type, distri, stan_fit, M = NULL)

Arguments

y

A numeric vector representing the observed data.

mod_type

Character string indicating the model type ("zi" or "h").

distri

Character string specifying the distribution ("poi", "nb", "gp", or "cmp").

stan_fit

A stanfit object returned by get_stanfit.

M

CMP cutoff used in fitting. Retrieved from the fit returned by get_stanfit, or supplied explicitly for a fit made directly with Stan.

Value

A summary table of model selection criteria, including:

EAIC

Expected Akaike Information Criterion (AIC).

EBIC

Expected Bayesian Information Criterion (BIC).

DIC

Deviance Information Criterion (DIC).

WAIC1

First version of Watanabe-Akaike Information Criterion (WAIC).

WAIC2

Second version of Watanabe-Akaike Information Criterion (WAIC).

The criteria are returned in a one-row data frame.

Examples


  # Generate toy data
  y_data <- data_simu(n = 60, alpha = 0.5, rho = 0.3, lambda = 5,
                      mod_type = "zi", distri = "poi")

  # Fit a small Stan model (may take > 5s on first compile)
  stan_fit <- get_stanfit(mod_type = "zi", distri = "poi", y = y_data)

  # Get model selection criteria
  get_mod_sel(y = y_data, mod_type = "zi", distri = "poi",
              stan_fit = stan_fit)



Get Predictions from Stan Model Fit

Description

Extracts predicted values from a Stan model fit.

Usage

get_pred(stan_fit)

Arguments

stan_fit

A stanfit object returned by get_stanfit.

Value

A summary of the predictions and bar charts of each prediction. If no forecasts were requested, the summary has zero rows and the plot list is empty.

Examples


  # Generate toy data
  y_data <- data_simu(n = 60, alpha = 0.5, rho = 0.3, lambda = 5,
                      mod_type = "zi", distri = "poi")

  # Fit a small Stan model (may take > 5s on first compile)
  stan_fit <- get_stanfit(mod_type = "zi", distri = "poi", y = y_data)

  # Get predicted values from the Stan model fit
  get_pred(stan_fit = stan_fit)



Fit ZI-INAR(1) or H-INAR(1) Model using Stan

Description

This function fits a Zero-Inflated INAR(1) (ZI-INAR(1)) or Hurdle INAR(1) (H-INAR(1)) model using Stan and returns the model fit.

Usage

get_stanfit(
  mod_type,
  distri,
  y,
  n_pred = 4,
  thin = 2,
  chains = 1,
  iter = 2000,
  warmup = iter/2,
  seed = NA,
  M = NULL,
  cmp_version = c("fast", "reference"),
  cmp_tail_tol = 1e-06,
  tail_action = c("warn", "error"),
  ...
)

Arguments

mod_type

Character string indicating the model type. Use "zi" for zero-inflated models and "h" for hurdle models.

distri

Character string specifying the distribution. Options are "poi" for Poisson, "nb" for Negative Binomial, "gp" for Generalized Poisson, or "cmp" for Conway-Maxwell-Poisson. GP and CMP innovations are supported only for zero-inflated models.

y

A numeric vector of integers representing the observed data.

n_pred

Integer specifying the number of time points for future predictions (default is 4).

thin

Integer indicating the thinning interval for Stan sampling (default is 2).

chains

Integer specifying the number of Markov chains to run (default is 1).

iter

Integer specifying the total number of iterations per chain (default is 2000).

warmup

Integer specifying the number of warmup iterations per chain (default is iter/2).

seed

Numeric seed for reproducibility (default is NA).

M

CMP innovation cutoff. Defaults to the larger of 300 and max(y).

cmp_version

CMP Stan implementation, either "fast" or "reference". Both use the same likelihood and priors. Defaults to "fast".

cmp_tail_tol

Tolerance for the CMP omitted probability mass bound. Defaults to 1e-6.

tail_action

Action when the CMP tail bound exceeds the tolerance. Use "warn" (default) or "error". Increase M and refit if flagged.

...

Additional arguments passed to rstan::stan.

Value

A stanfit object containing the Stan model fit.

Examples


  # Generate toy data
  y_data <- data_simu(n = 60, alpha = 0.5, rho = 0.3, lambda = 5,
                      mod_type = "zi", distri = "poi")

  # Fit the model using Stan (small config)
  stan_fit <- get_stanfit(mod_type = "zi", distri = "poi", y = y_data)
  print(stan_fit)



  # Simulate and fit a zero-inflated CMP-INAR(1) series
  y_cmp <- data_simu(n = 60, alpha = 0.5, rho = 0.3, lambda = 2.5,
                     disp = 1.2, mod_type = "zi", distri = "cmp")
  fit_cmp <- get_stanfit(mod_type = "zi", distri = "cmp", y = y_cmp,
                         M = 300, cmp_version = "fast")
  print(fit_cmp)