Skip to contents

Fit an EXNEX model for count data with varying follow-up time with Stan

Usage

fit_exnex_varying_time(
  t,
  r,
  p_exch,
  mu_prior_mean = -1.73,
  mu_prior_sd = 2.616,
  tau_lower_bound = 0,
  tau_prior_mean = 0,
  tau_prior_sd = 1,
  nex_prior_mean = -1.73,
  nex_prior_sd = 2.801,
  seed = 123456789,
  chains = 4,
  parallel_chains = 4,
  iter_warmup = 3000,
  iter_sampling = 5000,
  adapt_delta = 0.9,
  ...
)

Arguments

t

A numeric vector with the follow-up time per strata

r

An integer vector with the number of events per strata

p_exch

A numeric vector specifying the prior probability of exchangeability for each strata

mu_prior_mean

Mean for the normal prior set on mu.

mu_prior_sd

Standard deviation for the normal prior set on mu.

tau_lower_bound

Lower bound for the tau parameter. Any probability mass below that will be reallocated.

tau_prior_mean

Mean for the normal prior set on tau. Tau has a lower bound of zero so any probability mass below zero will be reallocated. Setting tau_prior_mu = 0 and tau_prior_sd = 1 is equivalent to a standard half-normal distribution.

tau_prior_sd

Standard deviation for the normal prior set on tau. Tau has a lower bound of zero, so setting tau_prior_mu = 0 and tau_prior_sd = 1 is equivalent to a standard half-normal distribution.

nex_prior_mean

Mean for the normal prior set on the non-exchangeable distributions.

nex_prior_sd

Standard deviation for the normal prior set on the non-exchangeable distributions.

seed

Set seed for the random number generated

chains

Number of MCMC chains to run

parallel_chains

Number of cores to use for running chains in parallel

iter_warmup

Number of warmup iterations

iter_sampling

Number of sampling iterations

adapt_delta

Tuning parameter for MCMC sampling

...

Other parameters to be passed into the sample function of cmdstanr

Value

A fitted cmdstanr model

MCMC convergence issues

When p_exch is set close to 1, there can be convergence issues due to the funnel-like geometry that arises when \(\tau\) is close to zero. Setting the lower bound for tau to a small positive number can help with this.

Examples

if (FALSE) {
fit_exnex_varying_time(
  r = rep(5, 10) |> as.integer(),
  t = seq(5, 50, length.out=10),
  p_exch = rep(0.5, 10),
  adapt_delta = 0.99
)
}