SEZINB | R Documentation |
Fits a Self exciting zero-inflated negative binomial (SE-ZINB) model using JAGS, with an optional design matrix of covariates and full inprod for mean structure, and can generate posterior predictive counts for new covariate data.
SEZINB(
cases,
pop = NULL,
casesoldold = 0,
covariates_count = NULL,
covariates_zero = NULL,
covariatespred_count = NULL,
covariatespred_zero = NULL,
poppred = NULL,
casesoldpred = 0,
casespred = NULL,
beta_init = NULL,
delta_init = NULL,
r_init = NULL,
beta_prior_mean = 0,
beta_prior_sd = 10,
delta_prior_mean = 0,
delta_prior_sd = 10,
r_prior_shape = 1,
r_prior_rate = 1,
n_iter = 1e+05,
n_burnin = 10000,
n_chains = 3,
n_thin = 1,
save_params = c("beta", "delta", "r", "eta")
)
cases |
Vector of observed counts (length N) |
pop |
Optional vector of population offsets (length N) |
casesoldold |
Optional parameter of the cases of 1 timepoint previous than the start of timepoints fit. |
covariates_count |
Optional numeric matrix (N x P) of covariates for the count component. |
covariates_zero |
Optional numeric matrix (N x Q) of covariates for the zero-inflation component. |
covariatespred_count |
Optional numeric matrix (M x P) of new covariates for count prediction. |
covariatespred_zero |
Optional numeric matrix (M x Q) of new covariates for zero-inflation prediction. |
poppred |
Optional vector of population offsets (length M) for prediction. |
casesoldpred |
Optional parameter of the cases of 1 timepoint previous than the start of the prediction. |
casespred |
Optional vector of true counts (length M) for prediction performance. |
beta_init |
Optional list of length n_chains for beta, count coefficients initial values. |
delta_init |
Optional list of length n_chains for delta, zero-inflation coefficients. |
r_init |
Optional numeric vector of length n_chains for dispersion parameter. |
beta_prior_mean |
Mean for beta prior (default: 0) |
beta_prior_sd |
SD for beta prior (default: 10) |
delta_prior_mean |
Mean for delta prior (default: 0) |
delta_prior_sd |
SD for delta prior (default: 10) |
r_prior_shape |
Shape for r ~ dgamma (default: 1) |
r_prior_rate |
Rate for r ~ dgamma (default: 1) |
n_iter |
Total MCMC iterations (default: 100000) |
n_burnin |
Burn-in iterations (default: 10000) |
n_chains |
Number of chains (default: 3) |
n_thin |
Thinning interval (default: 1) |
save_params |
Character vector of parameters to save (default c("beta","delta","r")) |
A list with MCMC summary, samples, DIC, and if prediction data provided: pred_matrix, pred_mean, mae, rmse
# ---- tiny example for users & CRAN (< 5s) ----
set.seed(6)
n <- 100
base <- rnbinom(n, size = 5, mu = 6)
zeros <- rbinom(n, 1, 0.30) # extra zeros to mimic zero-inflation
cases <- ifelse(zeros == 1, 0L, base)
# ---- actually fit the model, but only when JAGS is available ----
fit <- SEZINB(
cases = cases,
# keep priors at defaults; add them here only if your API requires
n_iter = 100, # keep fast for examples
n_burnin = 10,
n_chains = 1,
n_thin = 1
)
print(fit)
# ---- longer user-facing demo (skipped on checks) ----
if (nzchar(Sys.which("jags")) && requireNamespace("R2jags", quietly = TRUE)) {
x <- sin(2*pi*seq_len(n)/12) # simple seasonal regressor
fit2 <- SEZINB(
cases = cases,
covariates_count = cbind(x),
covariates_zero = cbind(x),
n_iter = 10000,
n_burnin = 500,
n_chains = 2,
n_thin = 2
)
print(fit2)
# if a plot method exists: # plot(fit2)
}
## Not run:
# ---- time-consuming / full demo ----
if (nzchar(Sys.which("jags")) && requireNamespace("R2jags", quietly = TRUE)) {
fit_full <- SEZINB(
cases = cases,
n_iter = 10000,
n_burnin = 5000,
n_chains = 4,
n_thin = 5
)
print(fit_full)
}
## End(Not run)
if (interactive()) {
# e.g., plot(fit)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.