Model fitting (compilation) error in "wythamewa" model

This is an error we’ve seen before which is specific to this RStan version (2.21). You can workaround this by running the model through cmdstanR. It looks like the rethinking package has the option to specify using cmdstanR as the backend, but the wythamewa package is too old for that. As a workaround, you can run the model through cmdstanR and then read the results into the stanfit format that would be returned by ewa_fit.

First up, install cmdstanR and cmdstan by following the instructions here: https://mc-stan.org/cmdstanr/articles/cmdstanr.html. If you run into errors with the installation, have a look at the instructions over here as well: Error caused by missing stan header

Then, setup your priors & model as usual:

    model_name <- "Sva_Gva_Lva_Pva"

    lms <- list(
    "mu[1] + a_bird[bird[i],1] + b_age[1]*age[i]",
    "mu[2] + a_bird[bird[i],2] + b_age[2]*age[i]",
    "mu[3] + a_bird[bird[i],3] + b_age[3]*age[i]",
    "mu[4] + a_bird[bird[i],4] + b_age[4]*age[i]"
    )
    links <- c("logit", "logit", "log", "logit", "")

    prior <- "
    mu ~ normal(0,1);
    diff_hi ~ cauchy(0,1);
    b_age ~ normal(0,1);
    to_vector(z_bird) ~ normal(0,1);
    L_Rho_bird ~ lkj_corr_cholesky(3);
    sigma_bird ~ exponential(2);"

    mod1 <- ewa_def( model=lms , prior=prior , link=links )
    set.seed(1)

Then compile and run your model through cmdstanR:

cmd_mod = cmdstan_model(write_stan_tempfile(mod1$stan_code))
cmd_samp = cmd_mod$sample(
    data = your_data,
    num_samples = 500,
    num_warmup = 500,
    num_chains = 3,
    num_cores = 3,
    adapt_delta = 0.99,
    max_treedepth = 12,
    validate_csv = FALSE
)

Finally, read the results back in to the same type of object returned by ewa_fit:

m = rstan::read_stan_csv(cmd_samp$output_files())