# Best practices for dealing with NaNs in multiple data set using Turing

**URL:** <https://discourse.julialang.org/t/best-practices-for-dealing-with-nans-in-multiple-data-set-using-turing/70423>\
**Category:** Probabilistic Programming\
**Tags:** data, turing, nan\
**Created:** [October 26, 2021, 6:10pm UTC](https://discourse.julialang.org/t/best-practices-for-dealing-with-nans-in-multiple-data-set-using-turing/70423 "2021-10-26T18:10:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![99dB](https://avatars.discourse-cdn.com/v4/letter/9/838e76/32.png) [@99dB](https://discourse.julialang.org/u/99dB)\
**Post date:** [October 26, 2021, 6:10pm UTC](https://discourse.julialang.org/t/best-practices-for-dealing-with-nans-in-multiple-data-set-using-turing/70423/1 "2021-10-26T18:10:28Z")

</div>

What is the best way to deal with NaNs in multiple data treatments when using Turing?

For example, for this example tutorial from [https://github.com/TuringLang/TuringTutorials/blob/master/tutorials/10-bayesian-differential-equations/10\_bayesian-differential-equations.jmd:](https://github.com/TuringLang/TuringTutorials/blob/master/tutorials/10-bayesian-differential-equations/10_bayesian-differential-equations.jmd:)

```julia
@model function fitlv(data, prob)
    σ ~ InverseGamma(2,3)
    α ~ truncated(Normal(1.3,0.5),0.5,2.5)
    β ~ truncated(Normal(1.2,0.25),0.5,2)
    γ ~ truncated(Normal(3.2,0.25),2.2,4.0)
    δ ~ truncated(Normal(1.2,0.25),0.5,2.0)
    ϕ1 ~ truncated(Normal(0.12,0.3),0.05,0.25)
    ϕ2 ~ truncated(Normal(0.12,0.3),0.05,0.25)
    p = [α,β,γ,δ,ϕ1,ϕ2]
    prob = remake(prob, p=p)
    predicted = solve(prob,SOSRI(),saveat=0.1)

    if predicted.retcode != :Success
        Turing.acclogp!(_varinfo, -Inf)
    end
    for j in 1:length(data)
        for i = 1:length(predicted)
            data[i,j] ~ MvNormal(predicted[i],σ)
        end
    end
end;

```

Here, how Turing is going to deal with NaN in `data[i,j]`? Assuming the number of treatments `[j]` is high, do you have any recommendations on how to keep it simple and deal with the nans?  
Thanks!

---

<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:** [February 9, 2022, 4:48pm UTC](https://discourse.julialang.org/t/best-practices-for-dealing-with-nans-in-multiple-data-set-using-turing/70423/2 "2022-02-09T16:48:57Z")

</div>

I believe here Turing will error, because it doesn’t know what the `NaN`s mean. So, what _do_ the `NaN`s mean?

---

<div class="post-metadata">

**Author:** ![99dB](https://avatars.discourse-cdn.com/v4/letter/9/838e76/32.png) [@99dB](https://discourse.julialang.org/u/99dB)\
**Post date:** [February 23, 2022, 3:44pm UTC](https://discourse.julialang.org/t/best-practices-for-dealing-with-nans-in-multiple-data-set-using-turing/70423/3 "2022-02-23T15:44:01Z")

</div>

In my case the NaNs mean `missing`. I didn’t tried using `missing`. How does turing is dealing with this?  
I found another way to solve this problem by estimate the likelihood individually for each set of data and not using the MvNormal. But I imagine that is slowing down the process.
