The design choice of this package, is that each sample is wrapped in a type that represents its likelihood. This works well, since in the empirical Bayes problem, we typically impose (simple) assumptions on the distribution of \(Z_i \mid \mu_i\) and complexity emerges from making compound or nonparametric assumptions on the \(\mu_i\) and sharing information across \(i\). The main advantage is that it then makes it easy to add new likelihoods and have it automatically integrate with the rest of the package (say the nonparametric maximum likelihood estimator) through Julia’s multiple dispatch.
The abstract type is
EBayesSample
EBayesSample{T}
Abstract type representing empirical Bayes samples with realizations of type T.
Example: StandardNormalSample
We explain the interface in the most well-studied empirical Bayes setting, namely the Gaussian compound decision problem wherein \(Z_i \mid \mu_i \sim \mathcal{N}(\mu_i,1)\). Such a sample is represented through the StandardNormalSample type:
StandardNormalSample
StandardNormalSample(Z)
An observed sample \(Z\) drawn from a Normal distribution with known variance \(\sigma^2 =1\).
\[
Z \sim \mathcal{N}(\mu, 1)
\]
\(\mu\) is assumed unknown. The type above is used when the sample \(Z\) is to be used for estimation or inference of \(\mu\).
The type can be used in three ways. First, say we observe \(Z_i=1.0\), then we reprent that as Z = StandardNormalSample(1.0). A more advanced functionality consists of StandardNormalSample(missing), which represents the random variable \(Z_i\) without having observed its realization yet.
Return the folded Normal distribution fold(Normal(μ, σ)) for a given mean μ.
response
response(model::RegressionModel)
Return the model response (a.k.a. the dependent variable).
response(Z::EBayesSample{T})
Returns the concrete realization of Z as type T, thus dropping the information about the likelihood.
Examples
julia> response(StandardNormalSample(1.0))
1.0
marginalize
marginalize(Z::EBayesSample, prior::Distribution)
Given a prior distribution \(G\) and EBayesSample\(Z\), return that marginal distribution of \(Z\). Works for `EBayesSample{Missing}``, i.e., no realization is needed.
Compute the marginal distribution for a folded normal observation under a uniform prior.
Arguments
Z::FoldedNormalSample: A folded normal observation.
prior::Uniform: Uniform prior distribution.
Returns
Folded{UniformNormal}: Folded UniformNormal distribution representing the marginal distribution.
pdf
pdf(d::Distribution{ArrayLikeVariate{N}}, x::AbstractArray{<:Real,N}) where {N}
Evaluate the probability density function of d at x.
This function checks if the size of x is compatible with distribution d. This check can be disabled by using @inbounds.
Implementation
Instead of pdf one should implement _pdf(d, x) which does not have to check the size of x. However, since the default definition of pdf(d, x) falls back to logpdf(d, x) usually it is sufficient to implement logpdf.
Convert a FoldedNormalSample back to a NormalSample by assigning a sign (default: positive).
BinomialSample
BinomialSample(Z, n)
An observed sample \(Z\) drawn from a Binomial distribution with n trials.
\[
Z \sim \text{Binomial}(n, p)
\]
\(p\) is assumed unknown. The type above is used when the sample \(Z\) is to be used for estimation or inference of \(p\).
julia> BinomialSample(2, 10) # 2 out of 10 trials successful
ℬ𝒾𝓃(2; p, n=10)
PoissonSample
PoissonSample(Z, E)
An observed sample \(Z\) drawn from a Poisson distribution,
\[
Z \sim \text{Poisson}(\mu \cdot E).
\]
The multiplying intensity \(E\) is assumed to be known (and equal to 1.0 by default), while \(\mu\) is assumed unknown. The type above is used when the sample \(Z\) is to be used for estimation or inference of \(\mu\).