Public Documentation
Documentation for EpiObsModels.jl's public interface.
See the Internals section of the manual for internal package docs covering all submodules.
Contents
Index
EpiAware.EpiObsModelsEpiAware.EpiObsModels.AggregateEpiAware.EpiObsModels.AscertainmentEpiAware.EpiObsModels.LatentDelayEpiAware.EpiObsModels.NegativeBinomialErrorEpiAware.EpiObsModels.PoissonErrorEpiAware.EpiObsModels.PrefixObservationModelEpiAware.EpiObsModels.RecordExpectedObsEpiAware.EpiObsModels.StackObservationModelsEpiAware.EpiObsModels.TransformObservationModelEpiAware.EpiObsModels.ascertainment_dayofweekEpiAware.EpiObsModels.generate_observation_error_priorsEpiAware.EpiObsModels.generate_observation_error_priorsEpiAware.EpiObsModels.observation_errorEpiAware.EpiObsModels.observation_errorEpiAware.EpiObsModels.observation_error
Public API
EpiAware.EpiObsModels — ModuleModule for defining observation models.
EpiAware.EpiObsModels.Aggregate — Typestruct Aggregate{M<:AbstractTuringObservationModel, I<:(AbstractVector{<:Int64}), J<:(AbstractVector{<:Bool})} <: AbstractTuringObservationModelAggregates observations over a specified time period. For efficiency it also only passes the aggregated observations to the submodel. The aggregation vector is internally broadcasted to the length of the observations and the present vector is broadcasted to the length of the aggregation vector using broadcast_n.
Fields
model::AbstractTuringObservationModel: The submodel to use for the aggregated observations.aggregation::AbstractVector{<: Int}: The number of time periods to aggregate over.present::AbstractVector{<: Bool}: A vector of booleans indicating whether the observation is present or not.
Constructors
Aggregate(model, aggregation): Constructs anAggregateobject and automatically sets thepresentfield.Aggregate(; model, aggregation): Constructs anAggregateobject and automatically sets thepresentfield using named keyword arguments
Examples
using EpiAware
weekly_agg = Aggregate(PoissonError(), [0, 0, 0, 0, 7, 0, 0])
gen_obs = generate_observations(weekly_agg, missing, fill(1, 28))
gen_obs()Fields
model::AbstractTuringObservationModelaggregation::AbstractVector{<:Int64}present::AbstractVector{<:Bool}
EpiAware.EpiObsModels.Ascertainment — Typestruct Ascertainment{M<:AbstractTuringObservationModel, T<:AbstractTuringLatentModel, F<:Function, P<:String} <: AbstractTuringObservationModelThe Ascertainment struct represents an observation model that incorporates a ascertainment model. If a latent_prefixis supplied the latent_model is wrapped in a call to PrefixLatentModel.
Constructors
Ascertainment(model::M, latent_model::T, transform::F, latent_prefix::P) where {M <: AbstractTuringObservationModel, T <: AbstractTuringLatentModel, F <: Function, P <: String}: Constructs anAscertainmentinstance with the specified observation model, latent model, transform function, and latent prefix.Ascertainment(; model::M, latent_model::T, transform::F = (Y_t, x) -> xexpy.(Y_t, x), latent_prefix::P = "Ascertainment") where {M <: AbstractTuringObservationModel, T <: AbstractTuringLatentModel, F <: Function, P <: String}: Constructs anAscertainmentinstance with the specified observation model, latent model, optional transform function (default:(Y_t, x) -> xexpy.(Y_t, x)), and optional latent prefix (default: "Ascertainment").
Examples
using EpiAware, Turing
obs = Ascertainment(model = NegativeBinomialError(), latent_model = FixedIntercept(0.1))
gen_obs = generate_observations(obs, missing, fill(100, 10))
rand(gen_obs)Fields
model::AbstractTuringObservationModel: The underlying observation model.latent_model::AbstractTuringLatentModel: The latent model.transform::Function: The function used to transform Y_t and the latent model output.latent_prefix::String
EpiAware.EpiObsModels.LatentDelay — Typestruct LatentDelay{M<:AbstractTuringObservationModel, T<:(AbstractVector{<:Real})} <: AbstractTuringObservationModelThe LatentDelay struct represents an observation model that introduces a latent delay in the observations. It is a subtype of AbstractTuringObservationModel.
Note that the LatentDelay observation model shortens the expected observation vector by the length of the delay distribution and this is then passed to the underlying observation model. This is to prevent fitting to partially observed data.
Fields
model::M: The underlying observation model.rev_pmf::T: The probability mass function (PMF) representing the delay distribution reversed.
Constructors
LatentDelay(model::M, distribution::C; D = nothing, Δd = 1.0) where {M <: AbstractTuringObservationModel, C <: ContinuousDistribution}: Constructs aLatentDelayobject with the given underlying observation model and continuous distribution. TheDparameter specifies the right truncation of the distribution, with defaultD = nothingindicates that the distribution should be truncated at its 99th percentile rounded to nearest multiple ofΔd. TheΔdparameter specifies the width of each delay interval.LatentDelay(model::M, pmf::T) where {M <: AbstractTuringObservationModel, T <: AbstractVector{<:Real}}: Constructs aLatentDelayobject with the given underlying observation model and delay PMF.
Examples
using Distributions, Turing, EpiAware
obs = LatentDelay(NegativeBinomialError(), truncated(Normal(5.0, 2.0), 0.0, Inf))
obs_model = generate_observations(obs, missing, fill(10, 30))
obs_model()Fields
model::AbstractTuringObservationModelrev_pmf::AbstractVector{<:Real}
EpiAware.EpiObsModels.NegativeBinomialError — Typestruct NegativeBinomialError{S<:Distributions.Sampleable} <: AbstractTuringObservationErrorModelThe NegativeBinomialError struct represents an observation model for negative binomial errors. It is a subtype of AbstractTuringObservationModel.
Constructors
NegativeBinomialError(; cluster_factor_prior::Distribution = HalfNormal(0.1)): Constructs aNegativeBinomialErrorobject with default values for the cluster factor prior.NegativeBinomialError(cluster_factor_prior::Distribution): Constructs aNegativeBinomialErrorobject with a specified cluster factor prior.
Examples
using Distributions, Turing, EpiAware
nb = NegativeBinomialError()
nb_model = generate_observations(nb, missing, fill(10, 10))
rand(nb_model)Fields
cluster_factor_prior::Distributions.Sampleable: The prior distribution for the cluster factor.
EpiAware.EpiObsModels.PoissonError — Typestruct PoissonError <: AbstractTuringObservationErrorModelThe PoissonError struct represents an observation model for Poisson errors. It is a subtype of AbstractTuringObservationErrorModel.
Constructors
PoissonError(): Constructs aPoissonErrorobject.
Examples
using Distributions, Turing, EpiAware
poi = PoissonError()
poi_model = generate_observations(poi, missing, fill(10, 10))
rand(poi_model)Fields
EpiAware.EpiObsModels.PrefixObservationModel — Typestruct PrefixObservationModel{M<:AbstractTuringObservationModel, P<:String} <: AbstractTuringObservationModelGenerate an observation model with a prefix. A lightweight wrapper around `EpiAwareUtils.prefix_submodel`.
# Constructors
- `PrefixObservationModel(model::M, prefix::P)`: Create a `PrefixObservationModel` with the observation model `model` and the prefix `prefix`.
- `PrefixObservationModel(; model::M, prefix::P)`: Create a `PrefixObservationModel` with the observation model `model` and the prefix `prefix`.
# Examples
```julia
using EpiAware
observation_model = PrefixObservationModel(Poisson(), "Test")
obs = generate_observations(observation_model, 10)
rand(obs)
```Fields
model::AbstractTuringObservationModel: The observation modelprefix::String: The prefix for the observation model
EpiAware.EpiObsModels.RecordExpectedObs — Typestruct RecordExpectedObs{M<:AbstractTuringObservationModel} <: AbstractTuringObservationModelRecord a variable (using the Turing := syntax) in the observation model.
# Fields
- `model::AbstractTuringObservationModel`: The observation model to dispatch to.
# Constructors
- `RecordExpectedObs(model::AbstractTuringObservationModel)`: Record the expected observation from the model as `exp_y_t`.
# Examples
```julia
using EpiAware, Turing
mdl = RecordExpectedObs(NegativeBinomialError())
gen_obs = generate_observations(mdl, missing, fill(100, 10))
sample(gen_obs, Prior(), 10)
```Fields
model::AbstractTuringObservationModel
EpiAware.EpiObsModels.StackObservationModels — Typestruct StackObservationModels{M<:(AbstractVector{<:AbstractTuringObservationModel}), N<:(AbstractVector{<:AbstractString})} <: AbstractTuringObservationModelA stack of observation models that are looped over to generate observations for each model in the stack. Note that the model names are used to prefix the parameters in each model (so if I have a model named cases and a parameter y_t, the parameter in the model will be cases.y_t). Inside the constructor PrefixObservationModel is wrapped around each observation model.
Constructors
StackObservationModels(models::Vector{<:AbstractTuringObservationModel}, model_names::Vector{<:AbstractString}): Construct aStackObservationModelsobject with a vector of observation models and a vector of model names.- `StackObservationModels(; models::Vector{<:AbstractTuringObservationModel},
: Construct aStackObservationModels` object with a vector of observation models and a vector of model names.StackObservationModels(models::NamedTuple{names, T}): Construct aStackObservationModelsobject with a named tuple of observation models. The model names are automatically generated from the keys of the named tuple.
Example
using EpiAware, Turing
obs = StackObservationModels(
(cases = PoissonError(), deaths = NegativeBinomialError())
)
y_t = (cases = missing, deaths = missing)
obs_model = generate_observations(obs, y_t, fill(10, 10))
rand(obs_model)
samples = sample(obs_model, Prior(), 100; progress = false)
cases_y_t = group(samples, "cases.y_t")
cases_y_t
deaths_y_t = group(samples, "deaths.y_t")
deaths_y_tFields
models::AbstractVector{<:AbstractTuringObservationModel}: A vector of observation models.model_names::AbstractVector{<:AbstractString}: A vector of observation model names
EpiAware.EpiObsModels.TransformObservationModel — Typestruct TransformObservationModel{M<:AbstractTuringObservationModel, F<:Function} <: AbstractTuringObservationModelThe TransformObservationModel struct represents an observation model that applies a transformation function to the expected observations before passing them to the underlying observation model.
Fields
model::M: The underlying observation model.transform::F: The transformation function applied to the expected observations.
Constructors
TransformObservationModel(model::M, transform::F = x -> log1pexp.(x)) where {M <: AbstractTuringObservationModel, F <: Function}: Constructs aTransformObservationModelinstance with the specified observation model and a default transformation function.TransformObservationModel(; model::M, transform::F = x -> log1pexp.(x)) where {M <: AbstractTuringObservationModel, F <: Function}: Constructs aTransformObservationModelinstance using named arguments.TransformObservationModel(model::M; transform::F = x -> log1pexp.(x)) where {M <: AbstractTuringObservationModel, F <: Function}: Constructs aTransformObservationModelinstance with the specified observation model and a default transformation function.
Example
using EpiAware, Distributions, LogExpFunctions
trans_obs = TransformObservationModel(NegativeBinomialError())
gen_obs = generate_observations(trans_obs, missing, fill(10.0, 30))
gen_obs()Fields
model::AbstractTuringObservationModel: The underlying observation model.transform::Function: The transformation function. The default islog1pexpwhich is the softplus transformation
EpiAware.EpiObsModels.ascertainment_dayofweek — Methodascertainment_dayofweek(
model::AbstractTuringObservationModel;
latent_model,
transform,
latent_prefix
) -> Ascertainment{M, AbstractTuringLatentModel, EpiAware.EpiObsModels.var"#15#17", String} where M<:AbstractTuringObservationModel
Create an Ascertainment object that models the ascertainment process based on the day of the week.
Arguments
model::AbstractTuringObservationModel: The observation model to be used.latent_model::AbstractTuringLatentModel: The latent model to be used. Default isHierarchicalNormal()which is a hierarchical normal distribution.transform: The transform function to be used. Default is(x, y) -> x .* y.
This function is used to transform the latent model after broadcasting to periodic weekly has been applied.
latent_prefix: The prefix to be used for the latent model. Default is"DayofWeek".
Returns
Ascertainment: TheAscertainmentobject that models the ascertainment process based on the day of the week.
Examples
using EpiAware
obs = ascertainment_dayofweek(PoissonError())
gen_obs = generate_observations(obs, missing, fill(100, 14))
gen_obs()
rand(gen_obs)EpiAware.EpiObsModels.generate_observation_error_priors — Methodgenerate_observation_error_priors(
obs_model::AbstractTuringObservationErrorModel,
y_t,
Y_t
) -> Any
Generates priors for the observation error model. This should return a named tuple containing the priors required for generating the observation error distribution.
EpiAware.EpiObsModels.generate_observation_error_priors — Methodgenerate_observation_error_priors(
obs_model::NegativeBinomialError,
Y_t,
y_t
) -> Any
Generates observation error priors based on the NegativeBinomialError observation model. This function generates the cluster factor prior for the negative binomial error model.
EpiAware.EpiObsModels.observation_error — Methodobservation_error(
obs_model::AbstractTuringObservationErrorModel,
Y_t
) -> SafePoisson
The observation error distribution for the observation error model. This function should return the distribution for the observation error given the expected observation value Y_t and the priors generated by generate_observation_error_priors.
EpiAware.EpiObsModels.observation_error — Methodobservation_error(
obs_model::NegativeBinomialError,
Y_t,
sq_cluster_factor
) -> SafeNegativeBinomial
This function generates the observation error model based on the negative binomial error model with a positive shift. It dispatches to the NegativeBinomialMeanClust distribution.
EpiAware.EpiObsModels.observation_error — Methodobservation_error(
obs_model::PoissonError,
Y_t
) -> SafePoisson
The observation error model for Poisson errors. This function generates the observation error model based on the Poisson error model.