Hello forum. I have a question about explicit implementation of MLE in Stan.
I have a simple detection task where subjects either detect or do not detect a change. Since there is no generic likelihood function that I use here, I calculate the probability of (detection | change) in every trial:
model {
for (t in 1:Tr) {
real p;
if (choice[t] == 1 && change[t] > 0) {
p = 1 - theta;
}
if (choice[t] == 0 && change[t] > 0) {
p = theta;
}
if (choice[t] == 1 && change[t] == 0) {
p = 1 - pow(theta,2);
}
if (choice[t] == 0 && change[t] == 0) {
p = pow(theta,2);
}
target += p;
}
}
Is this the right way of thinking about it in Stan? I get completely different theta from matlab and from Stan, so obviously something in my model is wrong.
Oops, I think I misread your post! I thought you’d also considered this as solution. Sorry about that. To be clear, I think Niko was pointing out the log (which is missing in log(p)) and not the += notation (which you used correctly), so I guess this is still the correct solution (please confirm if everything’s running as expected).