using Distributions
using Plots
using StatsPlots
= 1:5
lambdas
= []
plots for λ in lambdas
= rand(Poisson(λ), 1_000)
d = plot(histogram(d), title="λ = $λ")
p push!(plots, p)
end
plot!(plots..., legend=false)
xlims!(0, 10)
3 The Gamma-Poisson Model
Another foundational Bayesian model is the Gamma-Poisson model. Imagine we have a count outcome (e.g. the number of phone calls you receive in a day). The Poisson distribution is useful for modeling count data, and it depends on \(\lambda\), the rate parameter, such that:
\(Y|\lambda \sim Pois(\lambda)\)
Let’s plot what this distribution looks like with different rate parameters:
3.1 Gamma Distribution
The Gamma Distribution will serve as our prior for \(\lambda\). We can notate this via:
\(\lambda \sim Gamme(s, r)\)
The Gamma Distribution is parameterized by a shape parameter (s) and a rate parameter (r). These have the constraint that s, r > 0.
Note that the Exponential Distribution is a special case of the Gamma Distribution where s = 1.
In general, these distributions are positive and right-skewed (see this figure, for example).
To set an informative prior, we need to choose reasonable values of s and r. If we assume that we receive 5 phone calls in a day, we can estimate s and r using the equation \(E(\lambda) = \frac{s}{r} \approx 5\), so we know that \(s = 5r\). We can then plot some distributions that satisfy this and choose some values.
Note that the Distributions.jl package parameterizes the Gamma distribution with shape (s, \(\alpha\)) and a scale parameter (\(\theta\)), which is the inverse of the rate (r, \(\beta\)) parameter (i.e. \(\beta = 1 / \theta\))
= 1:4
r = 1 ./ r
θ = 5 .* r
s
= Gamma.(s, θ)
gammas
= []
plots for Γ in gammas
= Γ.α
α = round(Γ.θ, digits=2)
θ = rand(Γ, 10_000)
y = density(y, label="α = $α; θ = $θ")
p push!(plots, p)
end
plot!(plots...)
3.2 The Gamma-Poisson Model
Given the above, the Gamma-Poisson model is described as:
\(Y_i|\lambda \sim Pois(\lambda)\) \(\lambda \sim Gamma(s, r)\)