# GLM model from statistical rethinking video series

**URL:** <https://discourse.julialang.org/t/glm-model-from-statistical-rethinking-video-series/96666>\
**Category:** Probabilistic Programming\
**Tags:** turing\
**Created:** [March 27, 2023, 4:59pm UTC](https://discourse.julialang.org/t/glm-model-from-statistical-rethinking-video-series/96666 "2023-03-27T16:59:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arthings](https://avatars.discourse-cdn.com/v4/letter/a/f0a364/32.png) [@arthings](https://discourse.julialang.org/u/arthings)\
**Post date:** [March 27, 2023, 4:59pm UTC](https://discourse.julialang.org/t/glm-model-from-statistical-rethinking-video-series/96666/1 "2023-03-27T16:59:45Z")

</div>

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).

```julia
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

```r
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](https://youtu.be/Zi6N3GLUJmw?list=PLDcUM9US4XdPz-KxHM4XHt7uUVGWWVSus&t=3759)

 ![good_output](https://global.discourse-cdn.com/julialang/original/3X/4/e/4e2e5c4c73b3d1766322a988dd9b2dafdb3d27f1.png)

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.
