We’re going to demonstrate what happens when we attempt to compute the likelihood for the Consett measles outbreak data by direct simulation from the full latent state distribution.

First, let’s reconstruct the toy SIR model we were working with.

source("https://kingaa.github.io/sbied/pfilter/model.R")

Let’s generate a large number of simulated trajectories at some particular point in parameter space.

measSIR |>
  simulate(nsim=5000,format="arrays") -> x
measSIR |>
  emeasure(x=x$states) -> sims
matplot(time(measSIR),t(sims[1,1:50,]),type='l',lty=1,
  xlab="time",ylab=expression(rho*H),bty='l',col='blue')
lines(time(measSIR),obs(measSIR,"reports"),lwd=2,col='black')

We can use the function dmeasure to evaluate the log likelihood of the data given the states, the model, and the parameters:

ell <- dmeasure(measSIR,y=obs(measSIR),x=x$states,times=time(measSIR),log=TRUE,
  params=coef(measSIR))
dim(ell)
[1] 5000   42

According to the general equation for likelihood by direct simulation, we should sum up the log likelihoods across time:

ell <- apply(ell,1,sum)
summary(ell)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   -Inf    -Inf    -Inf    -Inf    -Inf  -125.1 
summary(exp(ell))
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
0.000e+00 0.000e+00 0.000e+00 1.775e-58 0.000e+00 4.901e-55 

Produced in R version 4.3.2.


Top of this document
Previous page
Back to the lesson
Course homepage
Acknowledgments
CC-BY_NC

Licensed under the Creative Commons Attribution-NonCommercial license. Please share and remix noncommercially, mentioning its origin.