Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
fix: beta-binomial numerical instability
Browse files Browse the repository at this point in the history
  • Loading branch information
storopoli committed Dec 3, 2023
1 parent e23bf1b commit 188894e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion turing/07-robust_beta_binomial_regression-wells.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ X = standardize(ZScoreTransform, X; dims=1)
y = wells[:, :switch]

# define alternate parameterizations
BetaBinomial2(n, μ, ϕ) = BetaBinomial(n, μ * ϕ, (1 - μ) * ϕ)
function BetaBinomial2(n, μ, ϕ)
α = μ * ϕ
β = (1 - μ) * ϕ
α = α > 0 ? α : 1e-4 # numerical stability
β = β > 0 ? β : 1e-4 # numerical stability

return BetaBinomial(n, α, β)
end

# define the model
@model function beta_binomial_regression(X, y; predictors=size(X, 2))
Expand Down

0 comments on commit 188894e

Please sign in to comment.