This is the stan code, its for modeling a cricket simulation as described in this paper:

Modelling and simulation for one-day cricket

functions {

real D(int number,real delta_1,real delta_2){

```
if(number>0 && number <= 3 )
return 0.0;
else if(number >3 && number <=6)
return delta_1;
else if(number >6)
return delta_1 + delta_2;
else return 0;
```

}

vector mean_mat(matrix X){

```
vector[7] means;
```

for(i in 1:7){

means[i] = mean(X[i,]);

}

return means;

}

}

data {

```
int<lower=1> N;
int<lower =1> BatNum;
int<lower =1> BowlNum;
int BatIndex[N];
int BowlIndex[N];
int<lower=1,upper=9> l[N];
int<lower=1,upper=7> F[N];
int<lower=1> index[N];
int matchballs;
```

}

parameters {

```
ordered[7] alk[9];
real<lower=0> sigma;
real<lower=0> tau;
real mu_1[BatNum];
real mu_2[BowlNum];
```

real<lower=0,upper=1> delta_1;

real<lower=0,upper=1> delta_2;

}

transformed parameters{

real delta[9];

for(n in 1:9){

delta[n] = D(l[n],delta_1,delta_2);

}

}

model {

//

matrix[N,7] s;

```
delta_1 ~uniform(0,1);
delta_2 ~uniform(0,1);
sigma ~ gamma(1,1);
tau ~ gamma(1,1);
mu_1 ~ normal(0,sqrt(1/tau));
mu_2 ~ normal(0,sqrt(1/tau));
//delta_1 = uniform_rng(0,1);
//delta_2 = uniform_rng(0,1);
for(t in 1:9){
alk[t] ~ normal(0,sqrt(1/sigma));
}
```

for(i in 1:N){

for(t in 1:7){

s[i,t] = alk[l[i],t] - mu_1[BatIndex[i]] - delta[l[i]] + mu_2[BowlIndex[i]];

}

}

F~ categorical_logit(mean_mat(s’));

}

please ask any questions you may have or if you need more information