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

Public API

EpiAware.EpiObsModels.AggregateType
struct Aggregate{M<:AbstractTuringObservationModel, I<:(AbstractVector{<:Int64}), J<:(AbstractVector{<:Bool})} <: AbstractTuringObservationModel

Aggregates 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 an Aggregate object and automatically sets the present field.
  • Aggregate(; model, aggregation): Constructs an Aggregate object and automatically sets the present field 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::AbstractTuringObservationModel

  • aggregation::AbstractVector{<:Int64}

  • present::AbstractVector{<:Bool}

source
EpiAware.EpiObsModels.AscertainmentType
struct Ascertainment{M<:AbstractTuringObservationModel, T<:AbstractTuringLatentModel, F<:Function, P<:String} <: AbstractTuringObservationModel

The 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, link::F, latent_prefix::P) where {M <: AbstractTuringObservationModel, T <: AbstractTuringLatentModel, F <: Function, P <: String}: Constructs an Ascertainment instance with the specified observation model, latent model, link function, and latent prefix.
  • Ascertainment(; model::M, latent_model::T, link::F, latent_prefix::P) where {M <: AbstractTuringObservationModel, T <: AbstractTuringLatentModel, F <: Function, P <: String}: Constructs an Ascertainment instance with the specified observation model, latent model, link function, and latent prefix.

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.

  • link::Function: The link function used to transform the latent model to the observed data.

  • latent_prefix::String

source
EpiAware.EpiObsModels.LatentDelayType
struct LatentDelay{M<:AbstractTuringObservationModel, T<:(AbstractVector{<:Real})} <: AbstractTuringObservationModel

The 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 a LatentDelay object with the given underlying observation model and continuous distribution. The D parameter specifies the right truncation of the distribution, with default D = nothing indicates that the distribution should be truncated at its 99th percentile rounded to nearest multiple of Δd. The Δd parameter specifies the width of each delay interval.

  • LatentDelay(model::M, pmf::T) where {M <: AbstractTuringObservationModel, T <: AbstractVector{<:Real}}: Constructs a LatentDelay object 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::AbstractTuringObservationModel

  • rev_pmf::AbstractVector{<:Real}

source
EpiAware.EpiObsModels.NegativeBinomialErrorType
struct NegativeBinomialError{S<:Distributions.Sampleable} <: AbstractTuringObservationErrorModel

The 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 a NegativeBinomialError object with default values for the cluster factor prior.
  • NegativeBinomialError(cluster_factor_prior::Distribution): Constructs a NegativeBinomialError object 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.
source
EpiAware.EpiObsModels.PoissonErrorType
struct PoissonError <: AbstractTuringObservationErrorModel

The PoissonError struct represents an observation model for Poisson errors. It is a subtype of AbstractTuringObservationErrorModel.

Constructors

  • PoissonError(): Constructs a PoissonError object.

Examples

using Distributions, Turing, EpiAware
poi = PoissonError()
poi_model = generate_observations(poi, missing, fill(10, 10))
rand(poi_model)

Fields

source
EpiAware.EpiObsModels.PrefixObservationModelType
struct PrefixObservationModel{M<:AbstractTuringObservationModel, P<:String} <: AbstractTuringObservationModel
Generate 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 model

  • prefix::String: The prefix for the observation model

source
EpiAware.EpiObsModels.RecordExpectedObsType
struct RecordExpectedObs{M<:AbstractTuringObservationModel} <: AbstractTuringObservationModel

Record 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
source
EpiAware.EpiObsModels.StackObservationModelsType
struct StackObservationModels{M<:(AbstractVector{<:AbstractTuringObservationModel}), N<:(AbstractVector{<:AbstractString})} <: AbstractTuringObservationModel

A 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 a StackObservationModels object with a vector of observation models and a vector of model names.
    • `StackObservationModels(; models::Vector{<:AbstractTuringObservationModel},
    model_names::Vector{<:AbstractString}): Construct aStackObservationModels` object with a vector of observation models and a vector of model names.
  • StackObservationModels(models::NamedTuple{names, T}): Construct a StackObservationModels object 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_t

Fields

  • models::AbstractVector{<:AbstractTuringObservationModel}: A vector of observation models.

  • model_names::AbstractVector{<:AbstractString}: A vector of observation model names

source
EpiAware.EpiObsModels.ascertainment_dayofweekMethod
ascertainment_dayofweek(
    model::AbstractTuringObservationModel;
    latent_model,
    link,
    latent_prefix
) -> Ascertainment{M, AbstractTuringLatentModel, EpiAware.EpiObsModels.var"#18#20", 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 is HierarchicalNormal() which is a hierarchical normal distribution.
  • link: The link function to be used. Default is the identity map x -> x.

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: The Ascertainment object 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)
source
EpiAware.EpiObsModels.generate_observation_error_priorsMethod
generate_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.

source
EpiAware.EpiObsModels.generate_observation_error_priorsMethod
generate_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.

source
EpiAware.EpiObsModels.observation_errorMethod
observation_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.

source
EpiAware.EpiObsModels.observation_errorMethod
observation_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.

source
EpiAware.EpiObsModels.observation_errorMethod
observation_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.

source