Certainly! Below is an example of an SEIR model in Turing.jl using the Reed-Frost formulation. This model includes two observation sources: prevalence and deaths. Deaths are generated daily based on a negative binomial distribution with a delay distribution convolved with the number of new infections each day.
using Turing, Distributions, Random
# Define the SEIR model using the Reed-Frost formulation
@model function seir_reed_frost(S, E, I, R, prev_obs, death_obs, days, β, γ, σ, μ, delay_dist)
# Parameters
N = S + E + I + R
β ~ truncated(Normal(β, 0.1), 0, Inf) # Infection rate
γ ~ truncated(Normal(γ, 0.1), 0, Inf) # Recovery rate
σ ~ truncated(Normal(σ, 0.1), 0, Inf) # Incubation rate
μ ~ truncated(Normal(μ, 0.1), 0, Inf) # Death rate
r = rand(delay_dist, days) # Delay distribution
# Initialize arrays to store the states and observations
S_t = zeros(days)
E_t = zeros(days)
I_t = zeros(days)
R_t = zeros(days)
new_infections = zeros(days)
deaths = zeros(days)
# Initial conditions
S_t[1], E_t[1], I_t[1], R_t[1] = S, E, I, R
# Simulate the SEIR model
for t in 2:days
new_infections[t-1] = β * S_t[t-1] * I_t[t-1] / N
new_exposed = new_infections[t-1]
new_infectious = σ * E_t[t-1]
new_recovered = γ * I_t[t-1]
new_deaths = μ * new_infectious
S_t[t] = S_t[t-1] - new_exposed
E_t[t] = E_t[t-1] + new_exposed - new_infectious
I_t[t] = I_t[t-1] + new_infectious - new_recovered - new_deaths
R_t[t] = R_t[t-1] + new_recovered
deaths[t] = new_deaths
end
# Convolve new infections with delay distribution
delayed_deaths = conv(new_infections, r)[1:days]
# Observations
for t in 1:days
prev_obs[t] ~ Normal(I_t[t] / N, 0.05) # Prevalence observation
death_obs[t] ~ NegativeBinomial(delayed_deaths[t], 0.1) # Death observation
end
return S_t, E_t, I_t, R_t, new_infections, deaths
end
# Example usage
days = 100
S = 990
E = 10
I = 0
R = 0
β = 0.3
γ = 0.1
σ = 0.2
μ = 0.01
delay_dist = Poisson(5) # Example delay distribution
# Generate some fake observation data
prev_obs = rand(Normal(0.01, 0.001), days)
death_obs = rand(NegativeBinomial(5, 0.1), days)
# Sample from the model
chain = sample(seir_reed_frost(S, E, I, R, prev_obs, death_obs, days, β, γ, σ, μ, delay_dist), NUTS(), 1000)
# Display the chain
chain
Explanation:
-
Parameters:
β: Infection rate.
γ: Recovery rate.
σ: Incubation rate.
μ: Death rate.
delay_dist: Delay distribution for deaths.
-
Initial Conditions:
S, E, I, R: Initial susceptible, exposed, infectious, and recovered populations.
-
Observations:
prev_obs: Prevalence observations.
death_obs: Death observations.
-
Model Simulation:
- The SEIR model is simulated for
days days.
- New infections, exposures, infectious, and recovered individuals are updated daily.
- Deaths are calculated based on the death rate
μ and the number of new infectious individuals.
-
Convolution:
- The new infections are convolved with the delay distribution to account for the delay in reporting deaths.
-
Observations:
- Prevalence is observed with some noise.
- Deaths are observed using a negative binomial distribution.
This model can be further refined and calibrated with real data.