ewa_def: Define a custom EWA dynamic learning model

Description Usage Arguments Details Author(s) See Also Examples

Description

This function take linear models and priors as inputs and defines a custom EWA dynamic learning model.

Usage

1
2
3
ewa_def(model,prior,data,file,pars,start,
  link=c("logit","logit","log","logit","logit"),
  N_effects,N_veffects,...)

Arguments

model

A list of linear models for each learning parameter. See examples.

prior

A quoted string of priors to insert into the model definition. See examples.

data

Optional. A list of data. If missing, uses data(WythamUnequal).

file

Optional model template. If missing, uses data(template_raw)

pars

Optional character vector of parameter names to sample

start

Optional named list of starting values for parameters

link

Character vector of link function names for each linear model in model

N_effects

Optional number of linear models. Defaults to length(model).

N_veffects

Optional number of varying effects. Defaults to N_effects.

Details

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.

Author(s)

Richard McElreath

See Also

ewa_fit

Examples

 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)

rmcelreath/wythamewa documentation built on May 14, 2019, 2:56 p.m.