I’d like some help with writing my first example in Turing.jl. I’m not even sure if this model is possible to be expressed in the Turing modeling framework. Below is the code I have so far and the current error:

```
# Import Turing and Distributions.
using Turing, Distributions
n = 1000
m = 10
k = 4
theta = randn(n)
b = zeros(k,m)
for i in 1:m
b[1,i] = randn()
for j in 2:k
dd = truncated(Normal(), b[j-1,i], Inf)
b[j,i] = rand(dd)
end
end
logit = x -> log(x / (1 - x))
invlogit = x -> exp(x)/(1 + exp(x))
y = zeros(m,n)
probs = zeros(k,m,n)
for p in 1:n
for i in 1:m
probs[1,i,p] = 1.0
for j in 1:(k-1)
Q = invlogit(theta[p] - b[j,i])
probs[j,i,p] -= Q
probs[j+1,i,p] = Q
end
y[i,p] = rand(Categorical(probs[:,i,p]))
end
end
# Graded Response Model
@model grm(y, n, m, k) = begin
b = Array{Float64,2}(undef, k, m)
for i in 1:m
b[1,i] ~ Normal(0,1)
for j in 2:k
b[j,i] ~ truncated(Normal(0,1), b[j-1,i], Inf)
end
end
probs = zeros(k, m, n)
theta = Vector{Float64}(undef, n)
for p in 1:n
theta[p] ~ Normal(0,1)
for i in 1:m
probs[1,i,p] = 1.0
for j in 1:(k-1)
Q = invlogit(theta[p] - b[j,i])
probs[j,i,p] -= Q
probs[j+1,i,p] = Q
end
y[i,p] ~ Categorical(probs[:,i,p])
end
end
return theta, b
end;
sample(grm(y, n, m, k), HMC(0.05, 10), 1500)
```

and the error:

```
ERROR: TypeError: in typeassert, expected Float64, got ForwardDiff.Dual{Nothing,Float64,10}
```