Code
# Setting up
using Distributions, Plots, Measures
include("../src/loadData.jl")
# Setting up
using Distributions, Plots, Measures
include("../src/loadData.jl")
We suggested in section ?sec-smc-data that separating imported from local cases may be critical when modelling the example data (the first 100 days of the COVID-19 pandemic in New Zealand). Separating the graph of reported cases into local and imported cases demonstrates why:
= loadData("NZCOVID")
Y bar(Y.date, Y.border + Y.local, label="Local", color=:darkorange)
bar!(Y.date, Y.border, label="Imported", color=:darkblue)
plot!(xlabel="Date", ylabel="Reported cases", size=(800,300), margins=3mm)
The problem of modelling imported cases has previously been covered by Thompson et al. (2019), …, and …
This chapter demonstrates one way in which local and imported cases can be distinguished in the sequential hidden-state framework.
We retain the hidden-state model from Chapter 8:
\[ \log R_t \sim \text{Normal}(\log R_{t-1}, \sigma) \tag{11.1}\]
and now assume that only local cases \(L_t\) are infected by past local and imported \(M_t\) cases:
\[ L_t | R_t \sim \text{Poisson}\left(R_t \Lambda_t^{(m)}\right) \tag{11.2}\]
where
\[ \Lambda_t^{(m)} = \sum_{u=1}^{u_{max}} \omega_u \left(L_{t-u} + M_{t-u}\right) \tag{11.3}\]
The bootstrap filter for this model is nearly identical to the simple model, we simply change one line (#TODO: install highlight extension and highlight):
function importedModel(σ, Y::DataFrame, opts::Dict)
# Extract frequently used options
= opts["T"]
T = opts["N"]
N = opts["L"]
L
# Initialise output matrices
= zeros(N, T) # Using R instead of X to highlight we're estimating Rt
R = zeros(N, T)
W
# Sample from initial distribution
:,1] = rand.(opts["pR0"], N)
R[
# Run the filter
for tt = 2:T
# Project according to the state-space model
:,tt] = exp.(rand.(Normal.(log.(R[:,tt-1]), σ)))
R[
# Weight according to the observation model
= sum(Y.Ct[tt-1:-1:1] .* ω[1:tt-1])
Λ :,tt] = pdf.(Poisson.(R[:,tt] .* Λ), Y.local[tt]) # <- This line is the only line that has changed!
W[
# Resample
= wsample(1:N, W[:,tt], N; replace=true)
inds :, max(tt - L, 1):tt] = R[inds, max(tt - L, 1):tt]
R[
end
return(R, W)
end
Fitting the model and plotting \(R_t\) against our original estmiates reveals substantial differences:
[Single figure to go here]
The model above assumed that imported cases are just as infectious as local cases. In