Hello Guys!

I am studying engineering in a France (maybe you will forgive my english!). I have a project where i had to use stan to implement a model called Kirmann Model. I can explain it if it is necessary. I made a code to do it but i don’t understand why it isn’t working. It would be great if someone has experienced this kind of result.

Thank you!!

(here is the code)

```
model_string <- "
functions{
int arrondi(real x){
int k;
while (k<x){
k=k+1;
}
k=k-1;
if (x-k>0.5){
k=k+1;
}
return k;
}
}
data{
int iteration;
real N;
real x[iteration + 2];
}
transformed data{
}
parameters{
real<lower=0,upper=1> alpha;
real<lower=0,upper=1> beta;
real v;
real gg;
}
transformed parameters{
real k[iteration];
real evolution[iteration-1];
real plus2[iteration -1];
real p1[iteration-1];
real p2[iteration-1];
real c[iteration-1];
vector[3] g[iteration-1];
for (i in 3:iteration){
k[i]=N*((1+gg)*x[i-1]-x[i]-gg*x[i-2])/((v+gg)*x[i-1]-gg*x[i-2]);
}
for (i in 1:(iteration-1)){
evolution[i]=k[i+1]-k[i];
plus2[i]=evolution[i]+2;
}
for (i in 1:(iteration-1)){
p2[i]=((k[i]/N)*((N-k[i]-1)/(N-1)))*alpha+((N-k[i])/N)*beta;
p1[i]=(k[i]/(N-1))*((N-k[i])/(N))*alpha+((k[i])/N)*beta;
c[i]=1-p1[i]-p2[i];
g[i][1]=p1[i];
g[i][2]=c[i];
g[i][3]=p2[i];
}
}
model{
alpha ~ uniform(0,0.8);
beta ~ uniform(0,0.19);
v ~ uniform(0.1,0.8);
gg ~ uniform (0.4,5);
for (i in 1:(iteration-1)){
target += categorical_lpmf(arrondi(plus2[i])|(g[i]));
}
}
"
data_list <- list(iteration=96, N=100, x=c(0.37249999999999994,0.21503749999999988,0.08304631249999986,-0.003710859375000125,-0.046161730468750085,-0.05584673339843754,-0.04672755151367189,-0.0306285186315918,-0.014914024796990968,-0.0032456968660817577,0.0033998913158932867,0.00578925723950827,0.005430946000571311,0.00384691064573303,0.0020863769075200674,0.0006988627172226278,-0.00014884840059802647,-0.000507827799815257,-0.0005358448175050636,-0.00040405454491600744,-0.00023503866239640912,-9.331595207714952e-05,-1.0269035838460515e-06,4.262107865772578e-05,5.184104446696721e-05,4.278795649399163e-05,2.719419667578533e-05,1.265866744214526e-05,2.4724218301659355e-06,-2.9703053924583196e-06,-4.810535057278799e-06,-4.443106181500141e-06,-3.1115327139363485e-06,-1.661137014988234e-06,-5.454479994252784e-07,1.066102574200033e-07,3.636650183543263e-07,3.7055403532510217e-07,2.679084125548817e-07,1.4741689718554556e-07,5.359172987885054e-08,-2.697028102173412e-09,-2.613254102489429e-08,-2.8397019555217715e-08,-2.1112964866940412e-08,-1.1963626363903152e-08,-4.651452547095586e-09,-2.3141830537868805e-10,1.7351506355925047e-09,2.086257349066254e-09,1.6287075374960145e-09,9.642114307626695e-10,4.073256549270107e-10,5.884141863092245e-11,-1.0139533674659585e-10,-1.3929012634864073e-10,-1.1588719986815743e-10,-7.279608951912474e-11,-3.352002655609014e-11,-7.07811191349957e-12,6.309173278161753e-12,1.0267591526300023e-11,9.043447788003972e-12,5.939683360955538e-12,2.9135941269180887e-12,8.13387273521899e-13,-2.8764678205949897e-13,-6.5421494414032e-13,-6.18451238413572e-13,-4.240796228684018e-13,-2.194604537075937e-13,-7.082576050792229e-14,1.1008063053780066e-14,4.218593066409883e-14,4.252400683842038e-14,3.0118036052558213e-14,1.6173297867254218e-14,5.684832340439588e-15,-2.924640659840883e-16,-2.65687869315249e-15,-2.805580936074104e-15,-2.0233875524205187e-15,-1.103493933232929e-15,-4.081697721137257e-16,-1.2501568782549998e-17,1.417278348058873e-16,1.5639937937966838e-16,1.1349075871000796e-16,6.200334765543451e-17,2.3217093681511895e-17,1.5527952014842835e-18,-6.952125724593481e-18,-7.909026863995309e-18,-5.7717368234154634e-18,-3.1628424090250505e-18,-1.201256116857707e-18,-9.707351194561253e-20,3.314957496453375e-19));
stan_samples <- stan(model_code = model_string, data=data_list)
print(stan_samples)
plot(stan_samples,show_density = TRUE,pars="alpha")
plot(stan_samples,show_density = TRUE,pars="beta")
```