Fit an exchangeable hierarchical model using a non-centered parameterization
Source:R/fit_exch.R
fit_exch.Rd
When fitting an EXNEX model with p_exch
close to 1, there can be convergence issues
due to the funnel-like geometry that arises when \(\tau\) is close to zero.
For the special case of p_exch = 1
,
this function fits the model using a non-centered parameterization,
which can fix the convergence issues.
See the Stan user guide
for more information.
Usage
fit_exch(
n,
r,
mu_prior_mean = -1.73,
mu_prior_sd = 2.616,
tau_prior_mean = 0,
tau_prior_sd = 1,
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
- 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.- 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
Examples
if (FALSE) {
# Example data from Table 1 of Neuenschwander et al.
fit_exch(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(),
adapt_delta = 0.99)
}