Here is my stan code below:
data {
int<lower=1> nSubjects;
int<lower=1> nTrials;
int<lower=1,upper=4> choice[nSubjects, nTrials];
real<lower=-1150, upper=100> reward[nSubjects, nTrials];
}
transformed data {
vector[4] initV; // initial values for V
vector[4] initu;
initV = rep_vector(0.0, 4);
initu = rep_vector(0.0, 4);
}
parameters {
real<lower=0,upper=1> lr[nSubjects];
real<lower=0,upper=5> c[nSubjects];
real<lower=0,upper=1> A[nSubjects];
real<lower=0,upper=5> loss_aversion[nSubjects];
}
model {
for (s in 1:nSubjects) {
vector[4] v;
vector[4] U;
real pe;
real theta;
v = initV;
U = initu;
for (t in 1:nTrials) {
// complete the foo-loop here
if (reward[s,t]>=0) {
U[choice[s,t]] = pow(reward[s,t],A[s]);}
else {
U[choice[s,t]] = -loss_aversion[s]*(pow(reward[s,t],A[s]));}
theta = pow(3,c[s])-1;
choice[s,t] ~ categorical_logit(theta*v);
pe = U[choice[s,t]]-v[choice[s,t]];
v[choice[s,t]]=v[choice[s,t]]+lr[s]*pe;
}
}
}
And the error reports like:
Chain 1: Rejecting initial value: Chain 1: Error evaluating the log probability at the initial value. Chain 1: Exception: categorical_logit_lpmf: log odds parameter[1] is nan, but must be finite! (in 'model313873be45dd_PVL_Delta_learning_Model' at line 53)
(Here line 53 is where choice[s,t] ~ categorical_logit(theta*v) is located.
The model is a specific model for fitting RL theory in a gambling task.But previously similar models can run perfectly and fit my data. I am confused why this one reports error.
Till now, I have tried following ways to debug the model fitting:
1.deleting theta; put the function directly in the categorical_logit();but sytactly wrong.
2.leaving ‘v’ alone in the function of categorical_logit, but report the same error;
3.changing constraint of c[0,5] to [1,5], reporting the same error.
Hope someone can help me with my problem, though I am not very adept at understanding stan code. Thank you guys in advance!