diff --git a/turing/11-hierarchical_varying_intercept-cheese.jl b/turing/11-hierarchical_varying_intercept-cheese.jl index 22c11ab..7c4b572 100644 --- a/turing/11-hierarchical_varying_intercept-cheese.jl +++ b/turing/11-hierarchical_varying_intercept-cheese.jl @@ -44,8 +44,8 @@ idx = cheese[:, :background_int] # prior for variance of random intercepts # usually requires thoughtful specification - τ ~ truncated(Cauchy(0, 2), 0, Inf) # group-level SDs intercepts - αⱼ ~ filldist(Normal(0, τ), n_gr) # group-level intercepts + τ ~ truncated(Cauchy(0, 2); lower=0) # group-level SDs intercepts + αⱼ ~ filldist(Normal(0, τ), n_gr) # group-level intercepts # likelihood y ~ MvNormal(α .+ αⱼ[idx] .+ X * β, σ^2 * I) diff --git a/turing/11-hierarchical_varying_intercept-non_centered-cheese.jl b/turing/11-hierarchical_varying_intercept-non_centered-cheese.jl index 833b8ff..5a8f8af 100644 --- a/turing/11-hierarchical_varying_intercept-non_centered-cheese.jl +++ b/turing/11-hierarchical_varying_intercept-non_centered-cheese.jl @@ -44,9 +44,9 @@ idx = cheese[:, :background_int] # prior for variance of random intercepts # usually requires thoughtful specification - τ ~ truncated(Cauchy(0, 2), 0, Inf) # group-level SDs intercepts - zⱼ ~ filldist(Normal(0, 1), n_gr) # group-level non-centered intercepts - αⱼ = zⱼ .* τ # group-level intercepts + τ ~ truncated(Cauchy(0, 2); lower=0) # group-level SDs intercepts + zⱼ ~ filldist(Normal(0, 1), n_gr) # group-level non-centered intercepts + αⱼ = zⱼ .* τ # group-level intercepts # likelihood y ~ MvNormal(α .+ αⱼ[idx] .+ X * β, σ^2 * I) diff --git a/turing/12-hierarchical_varying_slope-cheese.jl b/turing/12-hierarchical_varying_slope-cheese.jl index 83cd0ee..3736d9d 100644 --- a/turing/12-hierarchical_varying_slope-cheese.jl +++ b/turing/12-hierarchical_varying_slope-cheese.jl @@ -45,8 +45,8 @@ idx = cheese[:, :background_int] # prior for variance of random slopes # usually requires thoughtful specification - τ ~ filldist(truncated(Cauchy(0, 2), 0, Inf), n_gr) # group-level SDs slopes - βⱼ ~ arraydist([MvNormal(Diagonal(fill(τ[j], predictors).^2)) for j in 1:n_gr]) # group-level slopes + τ ~ filldist(truncated(Cauchy(0, 2); lower=0), n_gr) # group-level SDs slopes + βⱼ ~ arraydist([MvNormal(Diagonal(fill(τ[j], predictors).^2)) for j in 1:n_gr]) # group-level slopes # likelihood for i in 1:N diff --git a/turing/12-hierarchical_varying_slope-non_centered-cheese.jl b/turing/12-hierarchical_varying_slope-non_centered-cheese.jl index 78f3b93..2e12a85 100644 --- a/turing/12-hierarchical_varying_slope-non_centered-cheese.jl +++ b/turing/12-hierarchical_varying_slope-non_centered-cheese.jl @@ -44,9 +44,9 @@ idx = cheese[:, :background_int] # prior for variance of random slopes # usually requires thoughtful specification - τ ~ filldist(truncated(Cauchy(0, 2), 0, Inf), n_gr) # group-level SDs slopes - Zⱼ ~ filldist(Normal(0, 1), predictors, n_gr) # group-level non-centered slopes - βⱼ = Zⱼ * τ # group-level slopes + τ ~ filldist(truncated(Cauchy(0, 2); lower=0), n_gr) # group-level SDs slopes + Zⱼ ~ filldist(Normal(0, 1), predictors, n_gr) # group-level non-centered slopes + βⱼ = Zⱼ * τ # group-level slopes # likelihood y ~ MvNormal(α .+ X * β .+ X * βⱼ, σ^2 * I) diff --git a/turing/13-hierarchical_varying_intercept_slope-cheese.jl b/turing/13-hierarchical_varying_intercept_slope-cheese.jl index a668222..d69311f 100644 --- a/turing/13-hierarchical_varying_intercept_slope-cheese.jl +++ b/turing/13-hierarchical_varying_intercept_slope-cheese.jl @@ -45,8 +45,8 @@ idx = cheese[:, :background_int] # prior for variance of random intercepts and slopes # usually requires thoughtful specification - τₐ ~ truncated(Cauchy(0, 2), 0, Inf) # group-level SDs intercepts - τᵦ ~ filldist(truncated(Cauchy(0, 2), 0, Inf), n_gr) # group-level SDs slopes + τₐ ~ truncated(Cauchy(0, 2); lower=0) # group-level SDs intercepts + τᵦ ~ filldist(truncated(Cauchy(0, 2); lower=0), n_gr) # group-level SDs slopes αⱼ ~ filldist(Normal(0, τₐ), n_gr) # group-level intercepts βⱼ ~ arraydist([MvNormal(Diagonal(fill(τᵦ[j], predictors).^2)) for j in 1:n_gr]) # group-level slopes diff --git a/turing/13-hierarchical_varying_intercept_slope-non_centered-cheese.jl b/turing/13-hierarchical_varying_intercept_slope-non_centered-cheese.jl index 86562ec..438944f 100644 --- a/turing/13-hierarchical_varying_intercept_slope-non_centered-cheese.jl +++ b/turing/13-hierarchical_varying_intercept_slope-non_centered-cheese.jl @@ -44,12 +44,12 @@ idx = cheese[:, :background_int] # prior for variance of random intercepts and slopes # usually requires thoughtful specification - τₐ ~ truncated(Cauchy(0, 2), 0, Inf) # group-level SDs intercepts - τᵦ ~ filldist(truncated(Cauchy(0, 2), 0, Inf), n_gr) # group-level SDs slopes - zⱼ ~ filldist(Normal(0, 1), n_gr) # group-level non-centered intercepts - Zⱼ ~ filldist(Normal(0, 1), predictors, n_gr) # group-level non-centered slopes - αⱼ = zⱼ .* τₐ # group-level intercepts - βⱼ = Zⱼ * τᵦ # group-level slopes + τₐ ~ truncated(Cauchy(0, 2); lower=0) # group-level SDs intercepts + τᵦ ~ filldist(truncated(Cauchy(0, 2); lower=0), n_gr) # group-level SDs slopes + zⱼ ~ filldist(Normal(0, 1), n_gr) # group-level non-centered intercepts + Zⱼ ~ filldist(Normal(0, 1), predictors, n_gr) # group-level non-centered slopes + αⱼ = zⱼ .* τₐ # group-level intercepts + βⱼ = Zⱼ * τᵦ # group-level slopes # likelihood y ~ MvNormal(α .+ αⱼ[idx] .+ X * β .+ X * βⱼ, σ^2 * I) diff --git a/turing/14-hierarchical_correlated_varying_intercept_slope-cheese.jl b/turing/14-hierarchical_correlated_varying_intercept_slope-cheese.jl index 8cd9170..fb065be 100644 --- a/turing/14-hierarchical_correlated_varying_intercept_slope-cheese.jl +++ b/turing/14-hierarchical_correlated_varying_intercept_slope-cheese.jl @@ -52,9 +52,9 @@ idx = cheese[:, :background_int] # # prior for variance of random intercepts and slopes # # usually requires thoughtful specification -# τ ~ filldist(truncated(Cauchy(0, 2), 0, Inf), predictors) # group-level SDs -# γ ~ filldist(Normal(0, 5), predictors, n_gr) # matrix of group coefficients -# Z ~ filldist(Normal(0, 1), predictors, n_gr) # matrix of non-centered group coefficients +# τ ~ filldist(truncated(Cauchy(0, 2); lower=0), predictors) # group-level SDs +# γ ~ filldist(Normal(0, 5), predictors, n_gr) # matrix of group coefficients +# Z ~ filldist(Normal(0, 1), predictors, n_gr) # matrix of non-centered group coefficients # # reconstruct β from Ω and τ # β = γ + τ .* Ω.L * Z @@ -85,12 +85,12 @@ using PDMats # prior for variance of random intercepts and slopes # usually requires thoughtful specification - τ ~ filldist(truncated(Cauchy(0, 2), 0, Inf), predictors) # group-level SDs - γ ~ filldist(Normal(0, 5), predictors, n_gr) # matrix of group coefficients - Z ~ filldist(Normal(0, 1), predictors, n_gr) # matrix of non-centered group coefficients + τ ~ filldist(truncated(Cauchy(0, 2); lower=0), predictors) # group-level SDs + γ ~ filldist(Normal(0, 5), predictors, n_gr) # matrix of group coefficients + Z ~ filldist(Normal(0, 1), predictors, n_gr) # matrix of non-centered group coefficients # reconstruct β from Ω and τ - Ω_L = LowerTriangular(collect(τ .* L_U')) # collect is necessary for ReverseDiff for some reason + Ω_L = LowerTriangular(collect(τ .* L_U')) # collect is necessary for ReverseDiff for some reason Ω = PDMat(Cholesky(Ω_L)) β = γ + Ω * Z