# Strange error from Turing.jl?

**URL:** https://discourse.julialang.org/t/strange-error-from-turing-jl/68837
**Category:** Probabilistic Programming
**Tags:** turing
**Created:** [September 27, 2021, 9:20pm UTC](https://discourse.julialang.org/t/strange-error-from-turing-jl/68837 "2021-09-27T21:20:38Z")
**Posts on this page:** 1
**Showing post:** 6

<div class="post-metadata">

### Author: ![sethaxen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sethaxen/32/35604_2.png) [@sethaxen](https://discourse.julialang.org/u/sethaxen)
#### Post date: [September 28, 2021, 12:53am UTC](https://discourse.julialang.org/t/strange-error-from-turing-jl/68837/6 "2021-09-28T00:53:31Z")

</div>

In general, you want to do all of your data processing outside of the Turing model, since any done inside the model will need to be repeated every time the log density is evaluated. So try something like this:

```julia
@model function vaxxdecision(vaxxed, unvaxxed, vaxxedinf, unvaxxedinf)
    pv ~ Beta(1,100)
    punv ~ Beta(1,100)

    vaxxedinf ~ Binomial(vaxxed,pv)
    unvaxxedinf ~ Binomial(unvaxxed,punv)
end

vaxxed = sum(data.vaxxed==true)
unvaxxed = sum(data.vaxxed==false)

vaxxedinf = sum(data[data.vaxxed .==true,:infected])
unvaxxedinf = sum(data[data.vaxxed .==false,:infected])

chain = sample(
    vaxxdecision(vaxxed, unvaxxed, vaxxedinf, unvaxxedinf),
    NUTS(500, .85),
    1000,
)

```

As the provided example is not complete, I cannot verify that this works. But in this particular case, the posterior is [known to be a Beta distribution](https://en.wikipedia.org/wiki/Binomial_distribution#Beta_distribution).

Specifically, the posterior should be something like

```julia
pv ~ Beta(1 + vaxxedinf, 100 + vaxxed - vaxxedinf)
punv ~ Beta(1 + unvaxxedinf, 100 + unvaxxed - unvaxxedinf)

```

---

_[View the full topic](https://discourse.julialang.org/t/strange-error-from-turing-jl/68837)._
