Hi, I’m not sure what’s wrong with this stan model, and would appreciate some pointers. I’m trying to modify the activation-based lognormal race model implemented by Nicenboim et al. (2017) (@bnicenboim) , and detailed here. I can tell there’s something off with the types / dimensions, but I haven’t been able to figure out exactly where to change things to make them match up.
I’d like to add a predictor to the item-specific evidence accumulation parameter, alpha, and so I followed (as best I could) the way alpha was modified to add by-subject and by-item offsets in the hierarchical version detailed in the link above. However, the error I’m getting is:
SYNTAX ERROR, MESSAGE(S) FROM PARSER:
Dimension mismatch in assignment; variable name = alpha, type = vector; right-hand side type = real.
Illegal statement beginning with non-void expression parsed as
alpha
Not a legal assignment, sampling, or function statement. Note that
* Assignment statements only allow variables (with optional indexes) on the left;
* Sampling statements allow arbitrary value-denoting expressions on the left.
* Functions used as statements must be declared to have void returns
error in 'model6d5c72471037_EnrichedBasicRace' at line 44, column 4
-------------------------------------------------
42: for (n in 1:N_obs) {
43: vector[N_choices] alpha;
44: alpha = b_intercept + b_target_syll_heavy * TargetSyllHeavy[n];
^
45: log_lik[n] = race(winner[n], RT[n], alpha, b, sigma, psi);
-------------------------------------------------
PARSER EXPECTED: "}"
Error in stanc(filename, allow_undefined = TRUE) :
failed to parse Stan model 'EnrichedBasicRace' due to the above error.
>
The model code is here:
functions {
real race(int winner, real RT, vector alpha, real b, real sigma, real psi){
real log_lik;
int N_choices;
N_choices = num_elements(alpha);
log_lik = 0;
for(c in 1:N_choices)
if(c == winner)
log_lik = log_lik + lognormal_lpdf(RT - psi|b - alpha[c], sigma);
else
log_lik = log_lik + lognormal_lccdf(RT - psi|b - alpha[c], sigma);
return(log_lik);
}
}
data {
int<lower = 0> N_obs;
int<lower = 1> N_choices;
int<lower = 1, upper = N_choices> winner[N_obs];
vector<lower = 0>[N_obs] RT;
vector[N_obs] TargetSyllHeavy;
}
transformed data {
real b; //arbitrary threshold
real min_RT;
b = 10;
min_RT = min(RT);
}
parameters{
real<lower=0> sigma;
real<lower=0,upper=min_RT> psi;
real b_intercept;
real b_target_syll_heavy;
}
model {
vector[N_obs] loglik;
//alpha ~ normal(0,10);
b_intercept ~ normal(0,50);
b_target_syll_heavy ~ normal(0,10);
sigma ~ normal(0,2);
psi ~ normal(0,300);
for (n in 1:N_obs) {
vector[N_choices] alpha;
alpha = b_intercept + b_target_syll_heavy * TargetSyllHeavy[n];
log_lik[n] = race(winner[n], RT[n], alpha, b, sigma, psi);
}
target += loglik;
}
The regression parameter I’m trying to add is b_target_syll_heavy; the relevant data can be found forums_out_data.csv (50.1 KB) .
Thanks very much for your assistance with this, I appreciate it a lot!