I am trying to convert the following example from the book Statistical Rethinking book to a Turing model:

```
m8.3 <- quap(
alist(
log_gdp_std ~ dnorm( mu , sigma ) ,
mu <- a[cid] + b[cid]*( rugged_std - 0.215 ) ,
a[cid] ~ dnorm( 1 , 0.1 ) ,
b[cid] ~ dnorm( 0 , 0.3 ) ,
sigma ~ dexp( 1 )
) , data=dd )
```

My attempt is as follows:

```
@model function m8_3(log_gdp, cid, rugged_st)
for i = 1 : length(log_gdp)
a1 ~ Normal(1.0, 0.1)
b1 ~ Normal(0.0, 0.3)
a2 ~ Normal(1.0, 0.1)
b2 ~ Normal(0.0, 0.3)
σ ~ Exponential(1.0)
if cid[i] == 1
μ = a1 + b1 * (rugged_st[i] - 0.215)
else
μ = a2 + b2 * (rugged_st[i] - 0.215)
end
log_gdp[i] ~ Normal(μ, σ)
end
end
chain = sample( m8_3(
dd.log_gdp_std,
dd.cont_africa,
dd.rugged_std),
NUTS(),10000)
```

The expected output in the book is

```
mean sd 5.5% 94.5%
a[1] 0.89 0.02 0.86 0.91
a[2] 1.05 0.01 1.03 1.07
b[1] 0.13 0.07 0.01 0.25
b[2] -0.14 0.05 -0.23 -0.06
sigma 0.11 0.01 0.10 0.12
```

However my output are somewhat different

```
Param a1 a2 b1 b2 sigma
Mean 0.9954 1.0041 -0.0113 0.0064 0.2646
```

Is my conversion correct?

Is there a better way to do it?

My original version was using an vector for a and b, but it ran in the following error. And I do not know how to solve it.