Solved it. R has somewhat different functional parameters. In R function dbetabinom
function is parameterized as
p(x) = \frac{C(N,x) \mbox{Beta}(x+\theta p,N-x+\theta(1-p))}% {\mbox{Beta}(\theta p,\theta(1-p))}%
where \theta is given explicitly as “dispersion parameter” and is multiplied to p implicitly. In PyMC3 and Turing, \alpha and \beta are required as shape parameters.
Therefore my implementation should be:
@model function m121(admit, applications, gid)
a = Vector{Real}(undef, 2)
ϕ ~ Exponential(1)
θ = ϕ + 2.0
a[1] ~ Normal(0,1.5)
a[2] ~ Normal(0,1.5)
for i = 1 : length(gid)
p̄ = logistic(a[gid[i]])
admit[i] ~ BetaBinomial(applications[i], p̄ * θ, (1-p̄) * θ)
end
end
which does agree with the book example.