Oh, yes. I got the error. I fixed it.
Now I need to know, what is the type of theta_1 and theta_2. Earlier, I used them as arrays in my user-defined function. Is this still correct?
// Create user define function
functions{
real tenismodel_lpdf(matrix dat, vector[] theta, vector[] alpha, int[] ServerID, int[] ReceiverID, int[] t1, int[] t2, int[] t3){
vector[rows(dat)] prob;
real t;
real x;
int s;
int re;
real out;
real a;
real f;
real ws;
real rs;
real ms;
real wr;
real rr;
real mr;
real pr;
for (i in 1:rows(dat)){
t <- dat[i, 1];
x <- dat[i, 2];
s <- ServerID[i];
re <- ReceiverID[i];
a <- theta[s, 1];
f <- theta[s, 2];
if(x == -1){
prob[i] <- f;
}else if(t == 1){
prob[i] <- a^x * f^(1 - x);
}else if(fmod(t, 2) == 0){
vector [t1[i]] p1 ;
for(j in 1:t1[i]) {
rs <- alpha[s, 2*j];
rr <- alpha[re, (2*j + 1)];
p1[j] <- (rr) * (rs);
}
pr <- prod(p1);
ws <- alpha[s, 1];
ms <- alpha[s, 3];
wr <- alpha[re, 1];
mr <- alpha[re, 3];
prob[i] <- ((1- a - f) * pr * (mr)^x * (wr)^(1-x));
}else {
vector [t2[i]] p1;
for(j in 1:t2[i]) {
rs <- alpha[s, 2*j];
rr <- alpha[re, 2*j];
p1[j] <- (rr);
}
vector [t3[i]] p2;
for(j in 1:t3[i]) {
rs <- alpha[s, (2*j + 1)];
rr <- alpha[re, (2*j + 1)];
p2[j] <- (rs);
}
pr <- prod(p1) * prod(p2);
ws <- alpha[s, 1];
ms <- alpha[s, 3];
wr <- alpha[re, 1];
mr <- alpha[re, 3];
prob[i] <- ((1- a - f) * pr * (ms)^(1 - x) * (ws)^x);
}
}
out <- sum(log(prob));
return out;
}
}
// The input data is a vector 'y' of length 'N'.
data {
int N; // number of observations (rally lengths)
int M; // number of players
int t1 [N]; // number of touches
int t2 [N]; // number of touches
int t3 [N]; // number of touches
int K;
matrix [N, 2] dat; // touches, indicator, servereID and receiverID
int ServerID [N];
int ReceiverID [N];
int <lower = 2> m;
row_vector [3] beta1;
row_vector [3] beta2;
}
parameters {
simplex [m] theta_1 [M];
simplex [m] theta_2 [M, K];
}
// The model to be estimated.
model {
// Define priors
theta_1 ~ dirichlet(beta1);
for(i in 1:M){
for(j in 1:K){
theta_2[i,j] ~ dirichlet(beta2);
}
}
dat ~ tenismodel(theta_1, theta_2, ServerID, ReceiverID, t1, t2, t3);
}