run_stan.Rd
Loads, filters, and formats data, then compiles and runs a hierarchical Bayesian binomial model using Stan. The model estimates species-level proportions within species complexes, accounting for hierarchical structure and covariates such as region and year.
run_stan(data = data, iter = 2000, chains = 4, thinning = 1)
A named list containing:
An `rstan` `stanfit` object with the fitted model and posterior samples.
Data frame or vector linking species to complexes used in the model.
User-friendly variable name for labeling and plotting.
The original variable name input.
Number of iterations used in sampling.
Number of warmup (burn-in) iterations.
Thinning interval applied during sampling.
The function calls `creation_df()` to filter and preprocess the data, then prepares Stan-compatible data using `prepare_stan_data()`. The Stan model file `"Hierarchical_Model.stan"` is loaded from the package directory, compiled, and sampled with specified MCMC parameters. Recommended control parameters `adapt_delta = 0.99` and `max_treedepth = 15` improve convergence. Warmup is set to 20