knitr::opts_chunk$set(
  collapse = TRUE,
  warning = FALSE,
  comment = "#>"
)

This vignette develops the workflow for fitting the EPP-ASM model and generating outputs to provide as Spectrum inputs.

## eppasm version >= 0.5.2
## devtool::install_github("mrc-ide/eppasm@new-master")
## library(eppasm)
devtools::load_all()

Preparing EPP-ASM inputs

pjnz <- system.file("extdata/testpjnz", "Botswana2018.PJNZ", package="eppasm")
bw <- prepare_spec_fit(pjnz, proj.end=2021.5)

Simulate model with direct incidence input (a la Spectrum

fp <- prepare_directincid(pjnz)
mod <- simmod(fp)

prev(mod)
incid(mod)

EPP model with single set of parameter inputs

Prepare model parameters from parameter vector input

theta_ur <- c(-0.63758, -2.76655, -1.26204, 1996.65945, 0.00778, 0.05195,
              0.05103, 0.032, 0.01765, 0.01154, -0.00028, 0.01627, -0.00051,
              0.01439, -0.00937, -0.01135, 0.03692, 0.14959, 0.00803, 0.02424,
              -0.03548, 3.65223, -0.02515, -4.74563, 0.26259, -6.90124, 0.01583)

fp <- attr(bw$Urban, "specfp")
fp <- prepare_rhybrid(fp, rw_start = 2005, rw_dk = 1)

## Set some flags that are set in fitmod(), (later improve this code...)
fp$ancsitedata <- TRUE
fp$ancrt <- "both"
fp$logitiota <- TRUE
fp$rw_start <- 2005
fp$incidmod <- "eppspectrum"

param <- fnCreateParam(theta_ur, fp)
fp_par <- stats::update(fp, list = param)

Simulate the model once.

mod <- simmod(fp_par)

prev(mod)
incid(mod)

## R version of the model
modR <- simmod(fp_par, VERSION = "R")

prev(modR)
incid(modR)

Add survey ART coverage data.

```{r, add_artcov_dat attr(bw$Urban, "eppd")$hhsartcov <- data.frame(year = 2012, sex = "both", agegr = "15-49", n = 764, artcov = 0.397, se = 0.024, used = TRUE)

attr(bw$Urban, "eppd")$hhsartcov <- data.frame(year = 2012, sex = "both", agegr = "15-49", n = 484, artcov = 0.397, se = 0.034, used = TRUE)

Prepare likelihood and calculate the likelihood once

```r
## Prior 
lprior(theta_ur, fp)

## Prepare likelihood data
likdat <- prepare_likdat(attr(bw$Urban, "eppd"), fp)

## Calculate likelihood
ll(theta_ur, fp, likdat)

## Components of likelihood calculation
ll_hhsage(mod, likdat$hhs.dat)

ll_ancsite(mod, fp_par,
           coef = c(fp_par$ancbias, fp_par$ancrtsite.beta),
           vinfl = fp_par$v.infl,
           dat = likdat$ancsite.dat)

ll_ancrtcens(mod, likdat$ancrtcens.dat, fp_par)

Fitting the EPP-ASM model

bwfit <- list()

bwfit$Urban <- fitmod(bw$Urban, eppmod = "rhybrid", rw_start = 2005,
                      B0=1e3, B=1e2, opt_iter = 1, number_k=50)
bwfit$Rural <- fitmod(bw$Rural, eppmod = "rhybrid", rw_start = 2005,
                      B0=1e3, B=1e2, opt_iter = 1, number_k=50)

When fitting, the random-walk based models only simulate through the end of the data period. The extend_projection() function extends the random walk for $r(t)$ through the end of the projection period.

bwfit <- lapply(bwfit, extend_projection, proj_years = 52)

Simulating model outptus

bwout <- Map(tidy_output, bwfit, "r-hybrid", "Botswana", names(bwfit))

Pooling EPP subpopulation results

The function aggr_specfit() This involves simulating the model for all resamples in each subregion and summing the following pop, hivpop, and artpop arrays for each of the 3000 resamples to generate 3000 national outputs.

bwaggr <- aggr_specfit(bwfit)


mrc-ide/eppasm documentation built on Dec. 10, 2024, 8:19 a.m.