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)
}
```