| Title: | Zero-Inflated and Hurdle INAR(1) Models |
|---|---|
| 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. |
| Authors: | Fusheng Yang [aut, cre], Victor Hugo Lachos Davila [aut] |
| Maintainer: | Fusheng Yang <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.0 |
| Built: | 2026-05-19 07:45:36 UTC |
| Source: | https://github.com/fushengyy/zihinar1 |
This function simulates time series data for Zero-Inflated INAR(1) (ZI-INAR(1)) or Hurdle INAR(1) (H-INAR(1)) models, using either Poisson or Negative Binomial distributions.
data_simu(n, alpha, rho, theta, mod_type, distri)data_simu(n, alpha, rho, theta, mod_type, distri)
n |
Integer specifying the number of observations to simulate. |
alpha |
Numeric value between 0 and 1 representing the autoregressive parameter. |
rho |
Numeric value between 0 and 1 representing the zero-inflation or hurdle parameter. |
theta |
Numeric vector of model parameters. For Poisson, it should be
|
mod_type |
Character string indicating the model type. Use |
distri |
Character string specifying the distribution. Options are
|
A numeric vector containing the simulated time series data.
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.
# Simulate 50 observations from a Zero-Inflated Poisson INAR(1) model y_data <- data_simu(n = 50, alpha = 0.5, rho = 0.3, theta = c(5), mod_type = "zi", distri = "poi") head(y_data)# Simulate 50 observations from a Zero-Inflated Poisson INAR(1) model y_data <- data_simu(n = 50, alpha = 0.5, rho = 0.3, theta = c(5), mod_type = "zi", distri = "poi") head(y_data)
Extracts parameter estimates from a Stan model fit, including mean, median, standard deviation, and HPD intervals.
get_est(distri, stan_fit)get_est(distri, stan_fit)
distri |
Character string specifying the distribution. Options are "poi" or "nb". |
stan_fit |
A |
A summary of the parameter estimates.
# Generate toy data y_data <- data_simu(n = 60, alpha = 0.5, rho = 0.3, theta = c(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)# Generate toy data y_data <- data_simu(n = 60, alpha = 0.5, rho = 0.3, theta = c(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)
Calculates model selection criteria such as AIC, BIC, DIC, and WAIC from a Stan model fit.
get_mod_sel(y, mod_type, distri, stan_fit)get_mod_sel(y, mod_type, distri, stan_fit)
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" or "nb"). |
stan_fit |
A |
A summary table of model selection criteria, including:
Expected Akaike Information Criterion (AIC).
Expected Bayesian Information Criterion (BIC).
Deviance Information Criterion (DIC).
First version of Watanabe-Akaike Information Criterion (WAIC).
Second version of Watanabe-Akaike Information Criterion (WAIC).
The summary is printed in a table format for easy interpretation.
# Generate toy data y_data <- data_simu(n = 60, alpha = 0.5, rho = 0.3, theta = c(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)# Generate toy data y_data <- data_simu(n = 60, alpha = 0.5, rho = 0.3, theta = c(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)
Extracts predicted values from a Stan model fit.
get_pred(stan_fit)get_pred(stan_fit)
stan_fit |
A |
A summary of the predictions and bar charts of each prediction.
# Generate toy data y_data <- data_simu(n = 60, alpha = 0.5, rho = 0.3, theta = c(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)# Generate toy data y_data <- data_simu(n = 60, alpha = 0.5, rho = 0.3, theta = c(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)
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.
get_stanfit( mod_type, distri, y, n_pred = 4, thin = 2, chains = 1, iter = 2000, warmup = iter/2, seed = NA )get_stanfit( mod_type, distri, y, n_pred = 4, thin = 2, chains = 1, iter = 2000, warmup = iter/2, seed = NA )
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 or "nb" for Negative Binomial. |
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 |
seed |
Numeric seed for reproducibility (default is NA). |
A stanfit object containing the Stan model fit.
# Generate toy data y_data <- data_simu(n = 60, alpha = 0.5, rho = 0.3, theta = c(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)# Generate toy data y_data <- data_simu(n = 60, alpha = 0.5, rho = 0.3, theta = c(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)