Fit an EXNEX model with Stan
Usage
fit_exnex(
n,
r,
p_exch,
mu_prior_mean = -1.73,
mu_prior_sd = 2.616,
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
- n
An integer vector with the number of observations per strata
- r
An integer vector with the number of "successes" 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_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
andtau_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
andtau_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
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.
See the fit_exch()
function, which can fix convergence issue using
a non-centered parameterization of the model for the special case of p_exch = 1
.
Examples
if (FALSE) {
# Example data from Table 1 of Neuenschwander et al.
fit_exnex(r = c(2, 0, 1, 6, 7, 3, 5, 1, 0, 3) |> as.integer(),
n = c(15, 13, 12, 28, 29, 29, 26, 5, 2, 20) |> as.integer(),
p_exch = rep(0.5, 10),
adapt_delta = 0.99)
}