Batchelder and Riefer's (1990) source-monitoring model

I am trying to write code for the Batchelder and Riefer’s (1990) source-monitoring model (reference: Batchelder, W. H., & Riefer, D. M. (1999). Theoretical and empirical review of multinomial process tree modeling. Psychonomic Bulletin & Review , 6 (1), 57-86.)

For reference code to it and in stan I was looking at: 19.2 Multinomial processing tree (MPT) models | An Introduction to Bayesian Data Analysis for Cognitive Science
But since the Batchelder and Riefer’s model have three trees with the same probabilities being used across the trees, and most of the examples just have one tree, I am confused about how to put things together in model block of stan. I have just been able to code till here:


data { 
  int<lower = 1> N_trials;
  int<lower = 0, upper = N_trials> ans[3];
}
parameters {
  real<lower = 0, upper = 1> D1;
  real<lower = 0, upper = 1> d1;
  real<lower = 0, upper = 1> D2;
  real<lower = 0, upper = 1> d2;
  real<lower = 0, upper = 1> a;
  real<lower = 0, upper = 1> b;
  real<lower = 0, upper = 1> g;

} 
transformed parameters {
  simplex[3] theta;
  theta[1] = (D1*d1) + D1*(1-d1)*a +(1-D1)*b*g + D2*(1-d2)*a + (1-D2)*b*g +  b*g; //P(A|A) + P(A|B) + P(A|N) = P(A)
  theta[2] = D1*(1-d1)*(1-a) + (1-D1)*b*(1-g) + D2*d2 + D2*(1-d2)*(1-a) + (1-D2)*b*(1-g) + b*(1-g); // P(B)
  theta[3] = (1-D1) * (1-b) + (1-D2) * (1-b) + 1-b;  //P(N)
  
}

I coded the model as in the attached file:
mpt_v1.stan (1.0 KB)
For model_input_data = {"N_trials": 936,"ans":[258,383,295]}

but I get the following error:

	Exception: mpt_v1_model_namespace::log_prob: theta is not a valid simplex. sum(theta) = 3, but should be 1 (in '~/mpt_v1.stan', line 16, column 2 to column 19)

For a simplex, you need to have sum(theta) = 1 for it to be well formed. It looks like there’s a bug somewhere in your definition of theta because it’s giving you a result where the sum of theta is 3. I don’t see anything in the definitions that would guarantee that theta forms a simplex. Given that the sum is 3, maybe it’s just forgetting to divide by 3 somewhere?

The point of these tree models, judging from @vasishth’s doc is that you have a probabilistic generative process. If you follow a tree as written, then the sum of all the leaf nodes should be 1 if the sum of all the possibilities at each node is 1.