Code Monkey home page Code Monkey logo

Comments (4)

goedman avatar goedman commented on May 24, 2024

You mean using the plotbounds() method? Did you try converting the MCMCChains.Chains object to a DataFrame, e.g. DataFrame(chns, append_chains=true)?

If not, can you send me a MWE and I'll take a look. Clearly we're just starting creating a Turing version of StatisticalRethinking.jl.

from statisticalrethinking.jl.

orangebacked avatar orangebacked commented on May 24, 2024

Dear Mr. Goedman,

I was referring indeed to the plotbounds() method. I managed to plot it with the help of the Julia of the Julia community in Slack (you can find the discussion here https://stackoverflow.com/questions/62028147/plotting-credible-intervals-in-julia-from-turing-model/62070008?noredirect=1#comment109792812_62070008). This is the code (I hope it is useful):

weight_s = (d.weight .-mean(d.weight))./std(d.weight)
height = d.height
@model heightmodel(height, weight) = begin
    #priors
    α ~ Normal(178, 20)´
    σ ~ Uniform(0, 50)
    β1 ~ LogNormal(0, 1)
    β2 ~ Normal(0, 1)
    #model
    μ = α .+ weight .* β1 + weight.^2 .* β2
    # or μ = fheight.(weight, α, β1, β2) if we are defining fheigth anyways
    height ~ MvNormal(μ, σ)
end
chns = sample(heightmodel(height, weight_s), NUTS(), 10000)
describe(chns) |> display
res = DataFrame(chns)
fheight(weight, α, β1, β2) = α + weight * β1 + weight^2 * β2
testweights = -2:0.01:2
arr = [fheight.(w, res.α, res.β1, res.β2) for w in testweights]
m = [mean(v) for v in arr]
quantiles = [quantile(v, [0.1, 0.9]) for v in arr]
lower = [q[1] - m for (q, m) in zip(quantiles, m)]
upper = [q[2] - m for (q, m) in zip(quantiles, m)]
plot(testweights, m, ribbon = [lower, upper])

I'm transcribing the book with julia and Turing.jl, albeit slowly; let me know if I can colaborate! I saw this message today (I'm sorry for the delay), I guess I have to activate the notifications in my email.

Kind Regards,
Emiliano Isaza V

from statisticalrethinking.jl.

goedman avatar goedman commented on May 24, 2024

Emiliano,

I apologize for not responding to your post. I don't understand how I missed your post 10 days ago, but somehow I must have deleted the notification.

I'll go over above code today and see where it differs from plotbounds() in SR and if it shows ways to improve plotbounds().

Best,
Rob

from statisticalrethinking.jl.

goedman avatar goedman commented on May 24, 2024

Yes, very nice. I have started to use ribbons in other contexts as well but should probably rework this into plotbounds(). The other part I would like to allow in plotbounds() is to pass in a user defined link function like fweight() in your code above.

Have you looked at @karajan9 's work on TuringModels and SR? Looks really neat!

from statisticalrethinking.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.