Hi,

I’m trying to convert a model I fitted in JAGS into STAN.

In both JAGS and STAN, the binomial or betabinomial functions need “integer” values for the population size.

However, in my case, the population size considered is provided by another part of the model as a “real” value (i.e. a population dynamic model … not shown here).

In JAGS I used the following code:

```
## JAGS
prop ~ dunif(0,1)
phi <- 100
for (sID in 1:NsID){
propWerr[sID] ~ dbeta(prop * phi, (1 - prop) * phi)
RpredN[sID] <- round(predN[year[sID], 1])
obsN[sID] ~ dbin(propWerr[sID], RpredN[sID])
}
```

However, in STAN I cannot use the round function to convert my population value provided as a “real” into an “integer” value before using it into the binomial function.

To make the conversion, I used an inefficient trick (see below), searching for the closest integer and providing the latter to the binomial function. In fact, as the formulation used in JAGS correspond to a betabinomial, I used the specific “betabinomial” function in STAN.

```
## STAN
prop ~ uniform(0,1);
int phi = 100;
for (sID in 1:NsID){
// ### search for the closest integer ###
real res = -1;
int RpredN = -1;
while(res<0){
RpredN = RpredN+1;
res = RpredN - round(predN[year[sID]]);
}
// ######################################
obsN[sID] ~ beta_binomial(RpredN, prop * phi, (1 - prop) * phi);
}
```

While my “rounding up” approach seems to do the trick, there’s a good chance it’s going to cause problems during the fitting and I am pretty sure there is a much better/cleaner way to achieve what I want.

Any help would be appreciated.