Hello, i have an issue with the Turing code related to this model in the Statistical Rethinking video series. This code is not in the book so i didn’t find the solution in the good ressourcesTuringModels.jl or SR2TuringPluto.jl.
To reproduce the error here is the code of the data (included in the StatisticalRethinking package).
using MLLabelUtils, Turing, Distributions, CSV, DataFrames, StatisticalRethinking
df = CSV.read(sr_datadir("UCBadmit.csv"), DataFrame)
df.gender = ifelse.(df.gender .== "female",1,2)
df.dept = convertlabel(LabelEnc.Indices{Int}, categorical(df.dept))
@model function direct_effet_binomial(x,n, a)
alphas ~ filldist(Normal(0, 1), length(levels(x[:,1])),length(levels(x[:,2])))
p = logistic.(alphas[x[:,1],x[:,2]])
@. a ~ Binomial(n,p)
end
mGD = direct_effet_binomial(df[:,[:dept, :gender]], df.applications, df.admit)
sample_mgd = sample(mGD, NUTS(), 3000)
precis((DataFrame(sample_mgd)))
Here is the model from the video
m2 <- ulam(
alist(
A ~ bernoulli(p),
logit(p) <- a[G,D],
matrix[G,D]:a ~ normal(0,1)
), data=dat_sim , chains=4 , cores=4
)
The model works and give me some results but they are not the ones that i’m supposed to fet grom the course
I must have made a mistake somewhere and i am still new to the field so i’m sorry if it is an obvious bug.