Hi there! I got an error message: Stan model ‘anon_model’ does not contain samples.
Basically, the purpose of this model is to combine two reinforcement learning process (Learning from the validity of advice and learning from subject’s own experience )
Here is my model:
data {
int<lower=1> nSubjects;
int<lower=1> nTrials[nSubjects];
int<lower=1,upper=2> choice_green[nSubjects,max(nTrials)];
int<lower=1,upper=2> advice_follow[nSubjects,max(nTrials)];
int<lower=-1,upper=1> advice_acc[nSubjects,max(nTrials)];
int<lower=-1,upper=1> choice_acc[nSubjects,max(nTrials)];
}
transformed data {
vector[2] initv1;
initv1 = rep_vector(0.0,2);
vector[2] initv2;
initv2 = rep_vector(0.0,2);
}
parameters {
// group-Level parameters
// own experience
real lr1_mu_raw;
real tau1_mu_raw;
real<lower=0> lr1_sd_raw;
real<lower=0> tau1_sd_raw;
// advice following experience
real lr2_mu_raw;
real tau2_mu_raw;
real<lower=0> lr2_sd_raw;
real<lower=0> tau2_sd_raw;
// The weight of following advice
real omega_mu_raw;
real omega_sd_raw;
// subject-Level parameters
// own experience
vector[nSubjects] lr1_raw;
vector[nSubjects] tau1_raw;
// advice following experience
vector[nSubjects] lr2_raw;
vector[nSubjects] tau2_raw;
// The weight of following advice
vector[nSubjects] omega_raw;
}
transformed parameters{
vector<lower=0,upper=1>[nSubjects] lr1;
vector<lower=0,upper=3>[nSubjects] tau1;
vector<lower=0,upper=1>[nSubjects] lr2;
vector<lower=0,upper=3>[nSubjects] tau2;
vector<lower=0,upper=1>[nSubjects] omega;
for (s in 1:nSubjects){
lr1[s] = Phi_approx( lr1_mu_raw + lr1_sd_raw * lr1_raw[s] );
tau1[s] = Phi_approx( tau1_mu_raw + tau1_sd_raw * tau1_raw[s] )*3;
lr2[s] = Phi_approx( lr2_mu_raw + lr2_sd_raw * lr2_raw[s] );
tau2[s] = Phi_approx( tau2_mu_raw + tau2_sd_raw * tau2_raw[s] )*3;
omega[s] = Phi_approx( omega_mu_raw + omega_sd_raw * omega_raw[s] );
}
}
model {
lr1_mu_raw ~ normal(0,1);
tau1_mu_raw ~ normal(0,1);
lr1_sd_raw ~ cauchy(0,3);
tau1_sd_raw ~ cauchy(0,3);
lr1_raw ~ normal(0,1);
tau1_raw ~ normal(0,1);
lr2_mu_raw ~ normal(0,1);
tau2_mu_raw ~ normal(0,1);
lr2_sd_raw ~ cauchy(0,3);
tau2_sd_raw ~ cauchy(0,3);
lr2_raw ~ normal(0,1);
tau2_raw ~ normal(0,1);
omega_mu_raw ~ normal(0,1);
omega_sd_raw ~ cauchy(0,3);
omega_raw ~ normal(0,1);
for (s in 1:nSubjects){
vector[2] v1; // expectation of value for green card and blue card
real pe1; // prediction error
v1 = initv1;
vector[2] v2; // expectation of value for following advice and not following advice
real pe2; // prediction error
v2 = initv2;
for (t in 1:nTrials[s]){
// combine own experience and advice-following experience
choice_green[s,t] ~ categorical(omega[s]*softmax(tau2[s]*v2) + (1-omega[s])*softmax(tau1[s]*v1));
// own experience
pe1 = choice_acc[s,t] - v1[2-choice_green[s,t]];
v1[2-choice_green[s,t]] = v1[2-choice_green[s,t]] + lr1[s] * pe1;
// advice following experience
pe2 = advice_acc[s,t] - v2[2-advice_follow[s,t]];
v2[2-advice_follow[s,t]] = v2[2-advice_follow[s,t]]+ lr2[s] * pe2;
}
}
}
here is my data:
dataList <- list(nSubjects=nSubjects,
nTrials=nTrials,
choice_green=choice_green_matrix,
advice_follow=advice_follow_matrix,
cond=cond_matrix,
choice_acc=choice_acc_matrix,
advice_acc=advice_acc_matrix
)
and my fit:
fit_rl <- stan(modelFile1,
data = dataList,
chains = nChains,
iter = nIter,
warmup = nWarmup,
thin = nThin,
init = 'random',
seed = 145015634)
And I have tried running with chains = 1, but the error message is the same.