# Custom likelihood with Turing.jl

**URL:** <https://discourse.julialang.org/t/custom-likelihood-with-turing-jl/31471>\
**Category:** Probabilistic Programming\
**Tags:** question, turing\
**Created:** [November 25, 2019, 4:42am UTC](https://discourse.julialang.org/t/custom-likelihood-with-turing-jl/31471 "2019-11-25T04:42:37Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [November 25, 2019, 8:34am UTC](https://discourse.julialang.org/t/custom-likelihood-with-turing-jl/31471/3 "2019-11-25T08:34:08Z")

</div>

What you need to do is specify the lower and upper bounds of your parameters with your priors. I think you can simply use `Uniform(lb, ub)` in your use case. Here is a fairly straightforward [example](https://github.com/itsdfish/Miscellaneous/blob/master/examples/LNR/LNR.jl) of specifying a custom likelihood distribution in Turing. Here is example code for running the linked model.

```julia
using Distributions, Turing, Random, Parameters
ProjDir = @ __DIR__
cd(ProjDir)
include("LNR.jl")

@model model(data, Nr) = begin
    μ = Array{Real,1}(undef,Nr)
    μ ~ [Normal(0,3)]
    s ~ Uniform(0, pi/2)
    σ = tan(s)
    #σ ~ Truncated(Cauchy(0, 1), 0, Inf)
    for i in 1:length(data)
        data[i] ~ LNR(μ, σ, 0.0)
    end
end

Random.seed!(343)
Nreps = 50
error_count = fill(0.0, Nreps)
Nr = 3
Nobs = 10

μ = rand(Normal(0, 3), Nr)
σ = rand(Uniform(.2, 1))
dist = LNR(μ=μ, σ=σ, ϕ=0.0)
data = rand(dist, Nobs)
chain = sample(model(data, Nr), NUTS(1000, .8), 2000)

```

---

_[View the full topic](https://discourse.julialang.org/t/custom-likelihood-with-turing-jl/31471)._
