Skip to content

Error with MvNormal in Julia code for Bayesian GLM #1968

Answered by torfjelde
XinyueJia asked this question in Q&A
Discussion options

You must be logged in to vote

MvNormal is provided by Distributions.jl and it was decided to disallow MvNormal(..., ::Real) because some users expected the 2nd argument (the sigma) to represent the standard deviation while others expected variance. Instead you can use sigma^2 * I where I, representing a uniform scale matrix, becomes available after doing using LinearAlgebra.

So, all in all

using LinearAlgebra

@model function bayesian_glm(y, G, P, L, A)
    # Priors for the coefficients
    β0 ~ Normal(0, 10)
    β1 ~ filldist(Normal(0, 1), 4)
    β2 ~ filldist(Normal(0, 1), 2, 2)
    β4 ~ Normal(0, 10)
    sigma ~ Exponential(1)

    μ = β0 .+ β1[G] .+ β2[L, P] .+ β4 .* A

    y ~ MvNormal(μ, sigma * I) # though if `…

Replies: 2 comments 10 replies

Comment options

You must be logged in to vote
9 replies
@torfjelde
Comment options

@XinyueJia
Comment options

@torfjelde
Comment options

@devmotion
Comment options

@XinyueJia
Comment options

Answer selected by XinyueJia

This comment was marked as spam.

@XinyueJia
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants