Description Usage Arguments Details Author(s) See Also Examples
This function take linear models and priors as inputs and defines a custom EWA dynamic learning model.
1 2 3 |
model |
A |
prior |
A quoted string of priors to insert into the model definition. See examples. |
data |
Optional. A |
file |
Optional model template. If missing, uses |
pars |
Optional character vector of parameter names to sample |
start |
Optional named |
link |
Character vector of link function names for each linear model in |
N_effects |
Optional number of linear models. Defaults to |
N_veffects |
Optional number of varying effects. Defaults to |
This function uses a model template, by default data(template_raw)
, to define a custom dynamic learning model to fit in Stan. The template contains fields for linear models for each learning parameter. The first four parameters are (1) s, (2) g, (3) lambda, and (4) y, as defined in the paper. The fifth is an alternative parameterization of the payoff bias, called px in the code.
The expressions in model
define these paramters as combinations of means and varying effects and any other effects desired. The distributions in prior
define priors for each parameter.
Richard McElreath
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # define full model from paper
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 , data=datx )
# display Stan model code
cat(mod1$stan_code)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.