How to reparameterize this model, geting low E-BFMI error

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

Based on this:

mu_1 ~ normal(0,sqrt(1/tau));
mu_2 ~ normal(0,sqrt(1/tau));

I think your best bet is to start with some non-centerings. Check this for the how and why.

Also you can surround your code on both sides by three backticks (put ``` before and then another three after) and Discourse does a pre-formatted code block that makes it much easier to read (there’s also a button in the toolbar to the right of the quote button and to the left of upload).

1 Like

Thank you, tried running again with your non-centering approach. Also Im new here cant seem to find the edit button to put ‘’’ quotation marks

Actually I lied – the code button does indents not ticks to get preformated code, but it works either way.

Here’s a screenshot:


And this is what it renders to:

code goes here

Those are just three backticks (you can copy paste them from here ```).

You can also use tildes

code goes here

So when teaching someone to use code formatting you can write

stan code goes here

and it shows up as

stan code goes here

no need for screenshots.