Abstract
Background A vignette for the Naomi model is uploaded to the package website.
Task We run through the vignette manually to (1) develop a better understanding of the model, (2) get experience working with the Malawi data, which we will likely use for our case-study as it is publicly available.
knitr::opts_chunk$set(error = TRUE)
library(naomi)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.1 ──
## ✔ tibble 3.1.8
## ── Conflicts ────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ purrr::accumulate() masks foreach::accumulate()
## ✖ tidyr::expand() masks Matrix::expand()
## ✖ rstan::extract() masks tidyr::extract()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ✖ tidyr::pack() masks Matrix::pack()
## ✖ tidyr::unpack() masks Matrix::unpack()
## ✖ purrr::when() masks foreach::when()
library(sf)
Following vignette here.
Area hierarchy and boundaries, and plot to check we’ve got the right thing:
area_merged <- read_sf(system.file("extdata/demo_areas.geojson", package = "naomi"))
area_merged %>%
filter(area_level == max(area_level)) %>%
ggplot() +
geom_sf(aes(geometry = geometry)) +
theme_minimal()
The population data is as follows, with columns:
area_id
: contains the ISO, area level, and area
identifier.source
: where did this information come from?calendar_quarter
: contains the type of year (such as CY
for calendar year), the year, and the quartersex
: either female or male.age_group
: in the format Ylower_upper
where e.g. for 15-49 lower = 15
and
upper = 49
.population
: the population, which might not be an
integer I guess due to survey weighting.area_name
: the plain text version of the area
name.asfr
: age-sex fertility rate.pop_agesex <- read_csv(system.file("extdata/demo_population_agesex.csv", package = "naomi"))
## Rows: 19584 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────────────────────────────────────────────
## Delimiter: ","
## chr (6): area_id, source, calendar_quarter, sex, age_group, area_name
## dbl (2): population, asfr
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(pop_agesex)
The survey data is as follows, with columns:
indicator
: which survey indicator is it? Takes values
"prevalence"
, "art_coverage"
,
"viral_suppression_plhiv"
and
"recent_infected"
.survey_id
: the name of the survey, containing the
country, year and type.survey_mid_calendar_quarter
: which calendar quarter did
the survey occur during?area_id
: as before.area_name
: as before.res_type
: unknown.sex
: as before.age_group
: as before.n_clusters
: the number of survey clusters in this
area.n_observations
: the number of individuals
surveyed.n_eff_kish
: the Kish effective sample size.estimate
: a survey weighted estimate of the
indicator.std_error
: standard error of
estimate
.ci_lower
: 95% lower confidence interval for
estimate
.ci_upper
: 95% upper confidence interval for
estimate
.survey_hiv_indicators <- read_csv(system.file("extdata/demo_survey_hiv_indicators.csv", package = "naomi"))
## Rows: 21638 Columns: 15
## ── Column specification ────────────────────────────────────────────────────────────────────────────────────────────────
## Delimiter: ","
## chr (8): indicator, survey_id, survey_mid_calendar_quarter, area_id, area_name, res_type, sex, age_group
## dbl (7): n_clusters, n_observations, n_eff_kish, estimate, std_error, ci_lower, ci_upper
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(survey_hiv_indicators)
The ART programmatic data is as follows, with columns:
area_id
: as before.area_name
: as before.sex
: as before.age_group
: as before.year
: the year.calendar_quarter
: the calendar quarter.art_current
: unknown.art_new
: unknown.vl_tested_12mos
: viral load tested past 12 months.vl_suppressed_12mos
: viral load suppressed past 12
months.art_number <- read_csv(system.file("extdata/demo_art_number.csv", package = "naomi"))
## Rows: 510 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): area_id, area_name, sex, age_group, calendar_quarter
## dbl (5): year, art_current, art_new, vl_tested_12mos, vl_suppressed_12mos
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(art_number)
The ANC programmatic data is as follows, with columns:
anc_testing <- read_csv(system.file("extdata/demo_anc_testing.csv", package = "naomi"))
## Rows: 256 Columns: 11
## ── Column specification ────────────────────────────────────────────────────────────────────────────────────────────────
## Delimiter: ","
## chr (3): area_id, area_name, age_group
## dbl (8): year, anc_clients, anc_known_pos, anc_already_art, anc_tested, anc_tested_pos, anc_known_neg, births_facility
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(anc_testing)
pjnz <- system.file("extdata/demo_mwi2019.PJNZ", package = "naomi")
spec <- extract_pjnz_naomi(pjnz)
head(spec)
scope
: A collection of area_id
s defining
the set of areas to be modelled. Usually this is simply national level,
so the level 0 area_id
.level
: Area level at which to fit the model.quarter_id_t1
: The first time point for the model –
approximately the midpoint of the household survey data used.quarter_id_t2
: The second time point for the model –
the current time for which estimates are needed.quarter_id_t3
: The third time point for the model – the
future projection for HIV estimates.scope <- "MWI"
level <- 4
calendar_quarter_t1 <- "CY2016Q1"
calendar_quarter_t2 <- "CY2018Q3"
calendar_quarter_t3 <- "CY2019Q4"
prev_survey_ids <- c("DEMO2016PHIA", "DEMO2015DHS")
artcov_survey_ids <- "DEMO2016PHIA"
vls_survey_ids <- NULL
recent_survey_ids <- "DEMO2016PHIA"
artnum_calendar_quarter_t1 <- "CY2016Q1"
artnum_calendar_quarter_t2 <- "CY2018Q3"
anc_clients_year2 <- 2018
anc_clients_year2_num_months <- 9
anc_prevalence_year1 <- 2016
anc_prevalence_year2 <- 2018
anc_art_coverage_year1 <- 2016
anc_art_coverage_year2 <- 2018
This section is missing from the vignette!
Setup the model:
naomi_mf <- naomi_model_frame(
area_merged,
pop_agesex,
spec,
scope = scope,
level = level,
calendar_quarter_t1,
calendar_quarter_t2,
calendar_quarter_t3
)
Prepare data inputs
naomi_data <- select_naomi_data(
naomi_mf,
survey_hiv_indicators,
anc_testing,
art_number,
prev_survey_ids,
artcov_survey_ids,
recent_survey_ids,
vls_survey_ids,
artnum_calendar_quarter_t1,
artnum_calendar_quarter_t2,
anc_prevalence_year1,
anc_prevalence_year2,
anc_art_coverage_year1,
anc_art_coverage_year2
)
tmb_inputs <- prepare_tmb_inputs(naomi_data)
fit <- fit_tmb(tmb_inputs)
## 0: 5049.7382: 0.00000 0.916291 0.00000 0.916291 0.00000 0.916291 2.58200 0.916291 -0.693147 0.00000 0.916291 0.00000 0.916291 0.00000 0.916291 2.58200 0.916291 0.916291 0.916291 0.916291 0.916291 0.00000 0.00000 0.00000 -0.693147 0.916291 0.916291 0.916291 0.916291 0.916291 0.916291
## 1: 4715.5375: 0.101885 -0.274638 0.103366 -0.316395 0.0435735 0.623930 2.71607 0.576587 -0.693147 0.0857751 -0.119275 0.0760211 -0.0480341 0.0439968 0.497555 2.66551 0.682971 -0.124553 -0.233116 -0.180209 0.916291 0.0155373 0.000614590 -0.287618 -1.72214 -0.331936 -0.194986 -0.351451 -0.0713825 0.251498 0.916291
## 2: 4532.2139: 0.180116 -0.979662 0.205731 -1.59924 0.132692 0.320715 2.88078 0.188389 -0.693147 0.175072 -1.20114 0.151557 -0.977378 0.137338 0.0277932 2.75582 0.440834 -1.22962 -1.39984 -1.32779 0.916291 0.0303413 0.00110209 -0.763338 -1.21242 -1.73252 -1.29038 -1.96171 -1.03897 -0.126074 0.916291
## 3: 4514.6127: 0.159549 -0.430249 0.198112 -1.66613 0.188520 0.252571 2.92947 0.0789661 -0.693147 0.187794 -1.34185 0.171921 -1.23149 0.202537 -0.0980527 2.78438 0.366826 -1.40638 -1.54546 -1.60455 0.916291 0.0289349 0.00111922 -0.855896 -1.58938 -1.73865 -1.43677 -2.11695 -1.15931 -0.00778317 0.916291
## 4: 4506.9839: 0.221809 -0.893757 0.181669 -1.80087 0.309346 0.147029 3.00849 -0.0966450 -0.693147 0.204268 -1.51793 0.194928 -1.55978 0.352174 -0.296761 2.83408 0.238159 -1.60665 -1.63971 -1.97729 0.916291 0.0215497 0.00109782 -0.953115 -1.59331 -1.67950 -1.63160 -2.19115 -1.31329 -0.0815171 0.916291
## 5: 4501.8047: 0.252227 -0.484613 0.123426 -1.83523 0.564329 0.0241463 3.09927 -0.295038 -0.693147 0.212860 -1.53069 0.200307 -1.72520 0.694739 -0.517654 2.90731 0.0462359 -1.63428 -1.49433 -2.32927 0.916291 -0.00617443 0.000935585 -0.816707 -1.47481 -1.69711 -1.75056 -1.94885 -1.37834 -0.0532189 0.916291
## 6: 4497.5792: 0.340230 -0.588622 0.0378543 -1.86439 0.968459 -0.0426859 3.12538 -0.337027 -0.693147 0.207057 -1.40817 0.187118 -1.62689 1.25528 -0.599200 2.96186 -0.107625 -1.81047 -1.48761 -2.48773 0.916291 -0.0487001 0.000657026 -0.719558 -1.71568 -1.69658 -1.63906 -2.20538 -1.34362 0.0872618 0.916291
## 7: 4495.1497: 0.426239 -0.715540 -0.0489067 -1.90084 1.38381 -0.0870928 3.10327 -0.270709 -0.693147 0.210795 -1.39472 0.185766 -1.66196 1.77933 -0.624540 2.97460 -0.167537 -1.90301 -1.69698 -2.55044 0.916291 -0.0806898 0.000675868 -0.774687 -1.42756 -1.70197 -1.62459 -2.12930 -1.57284 -0.228694 0.916291
## 8: 4492.8561: 0.504661 -0.667258 -0.173724 -1.88417 1.89671 -0.0754288 3.06496 -0.160281 -0.693147 0.225654 -1.36112 0.188275 -1.82714 2.27696 -0.540110 2.94070 -0.128219 -2.04578 -1.62459 -2.52299 0.916291 -0.106693 0.000937120 -0.812360 -1.59185 -1.79514 -1.66733 -1.92815 -1.71172 0.0558827 0.916291
## 9: 4491.1097: 0.512947 -0.579700 -0.199306 -1.87938 1.95924 -0.0379427 3.09246 -0.217767 -0.693147 0.225614 -1.31443 0.186275 -1.81821 2.31364 -0.506119 2.94750 -0.149719 -2.00146 -1.55007 -2.54855 0.916291 -0.115202 0.000851440 -0.666282 -1.58929 -1.68390 -1.62193 -2.12913 -1.55589 -0.123402 0.916291
## 10: 4490.5100: 0.574265 -0.657015 -0.287714 -1.91940 2.20403 0.0416719 3.14301 -0.314776 -0.693147 0.240048 -1.30478 0.188330 -1.89308 2.46483 -0.418492 2.94852 -0.176536 -2.01195 -1.59060 -2.59632 0.916291 -0.126004 0.00104152 -0.681135 -1.60508 -1.72291 -1.54260 -2.08908 -1.52204 -0.00435696 0.916291
## 11: 4490.0229: 0.626296 -0.597250 -0.397611 -1.89060 2.47340 0.0864089 3.14481 -0.295556 -0.693147 0.256525 -1.26319 0.185098 -1.93494 2.65030 -0.376428 2.93856 -0.182539 -2.04384 -1.50316 -2.62049 0.916291 -0.135220 0.00123734 -0.763421 -1.63840 -1.71204 -1.55313 -2.10598 -1.61325 -0.0649226 0.916291
## 12: 4489.8491: 0.680672 -0.559716 -0.522729 -1.88924 2.69006 0.169268 3.11754 -0.203634 -0.693147 0.278997 -1.24113 0.182756 -1.97892 2.80588 -0.366624 2.92670 -0.188798 -2.07950 -1.61794 -2.64816 0.916291 -0.143851 0.00133120 -0.627976 -1.51704 -1.67905 -1.58375 -2.11075 -1.56687 -0.0951767 0.916291
## 13: 4489.4852: 0.712715 -0.618207 -0.584391 -1.89625 2.75553 0.220408 3.12971 -0.214895 -0.693147 0.296194 -1.29176 0.180081 -1.97334 2.85111 -0.328782 2.92564 -0.202789 -2.08817 -1.57686 -2.66290 0.916291 -0.144190 0.00139162 -0.629092 -1.62377 -1.71257 -1.52651 -2.08582 -1.57303 -0.102114 0.916291
## 14: 4489.3543: 0.733115 -0.607449 -0.651293 -1.91338 2.79853 0.248943 3.16434 -0.275309 -0.693147 0.306594 -1.21735 0.175848 -1.95594 2.85882 -0.262380 2.92211 -0.213616 -2.07723 -1.54501 -2.66809 0.916291 -0.140526 0.00146670 -0.712398 -1.57081 -1.69379 -1.52691 -2.12950 -1.59069 -0.0416389 0.916291
## 15: 4489.2034: 0.760691 -0.570760 -0.748225 -1.92445 2.90963 0.237089 3.18717 -0.299020 -0.693147 0.329178 -1.20970 0.171499 -1.95447 2.94272 -0.260680 2.90807 -0.209134 -2.07561 -1.59439 -2.66050 0.916291 -0.138750 0.00153640 -0.706541 -1.59831 -1.70899 -1.51141 -2.10124 -1.56283 -0.0879930 0.916291
## 16: 4489.0901: 0.794817 -0.612348 -0.842518 -1.91114 2.99135 0.293586 3.18648 -0.270760 -0.693147 0.357902 -1.27360 0.167286 -1.96983 3.02070 -0.256752 2.89659 -0.210158 -2.08287 -1.55287 -2.66256 0.916291 -0.137187 0.00158524 -0.649914 -1.57574 -1.70576 -1.50355 -2.10606 -1.59285 -0.0855555 0.916291
## 17: 4489.0118: 0.822246 -0.598609 -0.936514 -1.91440 3.06941 0.373173 3.17763 -0.222104 -0.693147 0.378830 -1.23664 0.162939 -1.99225 3.09557 -0.214276 2.89187 -0.228010 -2.08968 -1.57087 -2.67401 0.916291 -0.136833 0.00162351 -0.653712 -1.61313 -1.68759 -1.56055 -2.09727 -1.59237 -0.0707527 0.916291
## 18: 4488.9472: 0.845772 -0.559725 -1.04984 -1.92002 3.16702 0.377554 3.18417 -0.200471 -0.693147 0.408842 -1.24523 0.156894 -1.99481 3.15098 -0.156959 2.88323 -0.244295 -2.10406 -1.57515 -2.68928 0.916291 -0.134886 0.00164604 -0.696473 -1.57614 -1.71436 -1.51991 -2.10469 -1.55134 -0.0778439 0.916291
## 19: 4488.8699: 0.871807 -0.589159 -1.16357 -1.94568 3.25183 0.362100 3.22096 -0.243896 -0.693147 0.435514 -1.19639 0.149112 -1.98326 3.21056 -0.149030 2.86340 -0.237814 -2.05259 -1.58339 -2.69912 0.916291 -0.133673 0.00161938 -0.675689 -1.57878 -1.71980 -1.48589 -2.11824 -1.60380 -0.0797748 0.916291
## 20: 4488.8212: 0.872966 -0.589530 -1.17589 -1.92969 3.24219 0.406714 3.22419 -0.246778 -0.693147 0.442315 -1.22800 0.147928 -1.98470 3.21934 -0.147344 2.86149 -0.237985 -2.09446 -1.56484 -2.69157 0.916291 -0.132439 0.00164056 -0.690284 -1.61501 -1.69392 -1.49706 -2.10291 -1.57160 -0.0839160 0.916291
## 21: 4488.7863: 0.880701 -0.587632 -1.23063 -1.92597 3.27120 0.431150 3.24233 -0.267466 -0.693147 0.457639 -1.21746 0.143228 -1.97946 3.25554 -0.142550 2.85208 -0.236564 -2.10129 -1.57131 -2.68316 0.916291 -0.131468 0.00164477 -0.675854 -1.57611 -1.70355 -1.51206 -2.09945 -1.58127 -0.0874672 0.916291
## 22: 4488.7571: 0.887524 -0.582580 -1.28923 -1.92742 3.31877 0.423726 3.24356 -0.247666 -0.693147 0.476319 -1.22481 0.138563 -1.98367 3.29168 -0.119910 2.84503 -0.243185 -2.10175 -1.58073 -2.67735 0.916291 -0.130469 0.00165566 -0.668399 -1.58480 -1.69139 -1.51081 -2.10887 -1.59303 -0.0732245 0.916291
## 23: 4488.7536: 0.889520 -0.596261 -1.29895 -1.92850 3.31938 0.437971 3.24343 -0.243193 -0.693147 0.478499 -1.21144 0.137231 -1.98016 3.29726 -0.115102 2.84423 -0.245469 -2.09520 -1.56881 -2.67649 0.916291 -0.130308 0.00166090 -0.674683 -1.60422 -1.70308 -1.50554 -2.10122 -1.58183 -0.0892627 0.916291
## 24: 4488.7347: 0.891264 -0.585403 -1.32662 -1.93416 3.33321 0.445884 3.24523 -0.235838 -0.693147 0.487563 -1.21114 0.134883 -1.98299 3.31362 -0.110978 2.84050 -0.248402 -2.09299 -1.57320 -2.67885 0.916291 -0.129542 0.00166615 -0.676635 -1.58996 -1.70461 -1.50079 -2.10638 -1.58325 -0.0820385 0.916291
## 25: 4488.7319: 0.893715 -0.596191 -1.35228 -1.93070 3.35021 0.444985 3.25137 -0.238341 -0.693147 0.497004 -1.21540 0.131936 -1.98265 3.32745 -0.0974840 2.83662 -0.250941 -2.09960 -1.57611 -2.67593 0.916291 -0.128700 0.00167429 -0.679676 -1.59691 -1.69053 -1.50492 -2.10625 -1.58438 -0.0804168 0.916291
## 26: 4488.7178: 0.895302 -0.584688 -1.38229 -1.93136 3.36567 0.451847 3.25618 -0.236507 -0.693147 0.506909 -1.21269 0.129027 -1.98441 3.34503 -0.0908169 2.83168 -0.252446 -2.09917 -1.57561 -2.67686 0.916291 -0.127931 0.00167791 -0.674746 -1.59158 -1.69910 -1.50557 -2.10667 -1.58547 -0.0798134 0.916291
## 27: 4488.7106: 0.898064 -0.590892 -1.41148 -1.93671 3.37689 0.465787 3.25962 -0.231266 -0.693147 0.516678 -1.20770 0.125770 -1.98336 3.36498 -0.0900316 2.82668 -0.254176 -2.09395 -1.57494 -2.67750 0.916291 -0.127263 0.00168244 -0.676448 -1.58943 -1.70166 -1.49728 -2.10567 -1.58471 -0.0840481 0.916291
## 28: 4488.6959: 0.902845 -0.591213 -1.48376 -1.93629 3.41351 0.478487 3.27150 -0.225610 -0.693147 0.542142 -1.20483 0.117817 -1.98790 3.40695 -0.0698988 2.81456 -0.259531 -2.09921 -1.57366 -2.67846 0.916291 -0.125286 0.00169330 -0.671116 -1.59636 -1.70972 -1.50126 -2.10801 -1.58517 -0.0830010 0.916291
## 29: 4488.6825: 0.906480 -0.580063 -1.55801 -1.94300 3.44487 0.490292 3.28713 -0.225974 -0.693147 0.568949 -1.20040 0.109004 -1.98840 3.44228 -0.0468737 2.80168 -0.265599 -2.10197 -1.57761 -2.68254 0.916291 -0.122725 0.00171013 -0.672105 -1.58848 -1.69723 -1.49497 -2.10283 -1.58880 -0.0834633 0.916291
## 30: 4488.6770: 0.909698 -0.583750 -1.63287 -1.92689 3.47338 0.493263 3.30144 -0.219771 -0.693147 0.598297 -1.19450 0.0983827 -1.99084 3.48293 -0.0384149 2.78740 -0.273118 -2.09940 -1.58207 -2.68281 0.916291 -0.119998 0.00172898 -0.681439 -1.58273 -1.70011 -1.49847 -2.10734 -1.58262 -0.0791377 0.916291
## 31: 4488.6678: 0.911595 -0.587184 -1.70692 -1.93064 3.49471 0.511718 3.31637 -0.213203 -0.693147 0.629091 -1.19505 0.0866491 -1.98919 3.52105 -0.0145133 2.77354 -0.283656 -2.09950 -1.58375 -2.68150 0.916291 -0.117884 0.00173527 -0.678050 -1.59436 -1.70109 -1.49452 -2.10895 -1.58731 -0.0832247 0.916291
## 32: 4488.6656: 0.911755 -0.587148 -1.72527 -1.94260 3.50110 0.511432 3.31869 -0.207126 -0.693147 0.637409 -1.19252 0.0830229 -1.98930 3.53201 -0.00965552 2.76807 -0.283446 -2.10486 -1.57704 -2.68072 0.916291 -0.117482 0.00173653 -0.674506 -1.58967 -1.70110 -1.49675 -2.10588 -1.58526 -0.0821970 0.916291
## 33: 4488.6647: 0.910486 -0.584432 -1.74595 -1.94247 3.50218 0.515481 3.32445 -0.204618 -0.693147 0.648135 -1.19079 0.0774622 -1.98906 3.54618 -0.00817435 2.75953 -0.281300 -2.10704 -1.57872 -2.67901 0.916291 -0.117454 0.00173266 -0.674940 -1.58975 -1.70046 -1.49314 -2.10748 -1.58697 -0.0811653 0.916291
## 34: 4488.6638: 0.909453 -0.585989 -1.76698 -1.93933 3.50272 0.517601 3.33012 -0.200859 -0.693147 0.659581 -1.18928 0.0714154 -1.99010 3.55607 0.00187061 2.75368 -0.286477 -2.10775 -1.58071 -2.67843 0.916291 -0.117173 0.00173306 -0.673262 -1.59014 -1.70115 -1.49186 -2.10719 -1.58844 -0.0832741 0.916291
## 35: 4488.6636: 0.908105 -0.586496 -1.78644 -1.94211 3.50190 0.515692 3.33769 -0.199646 -0.693147 0.672167 -1.18827 0.0640183 -1.98993 3.56825 0.00431845 2.74844 -0.295441 -2.10666 -1.58003 -2.67488 0.916291 -0.115966 0.00174969 -0.673631 -1.59306 -1.70047 -1.49227 -2.10685 -1.58750 -0.0837323 0.916291
## 36: 4488.6632: 0.906138 -0.585926 -1.80165 -1.94169 3.49441 0.512621 3.34626 -0.196922 -0.693147 0.686406 -1.18734 0.0537857 -1.98910 3.57673 0.0110598 2.73698 -0.295995 -2.10468 -1.58042 -2.67541 0.916291 -0.114715 0.00176129 -0.674294 -1.59085 -1.70074 -1.49194 -2.10751 -1.58674 -0.0826188 0.916291
## 37: 4488.6631: 0.905998 -0.585991 -1.80023 -1.94044 3.49028 0.510626 3.34725 -0.193473 -0.693147 0.689127 -1.18570 0.0500956 -1.98835 3.57663 0.0104478 2.73353 -0.296294 -2.10828 -1.58093 -2.67749 0.916291 -0.115092 0.00174954 -0.673306 -1.59077 -1.70074 -1.49092 -2.10675 -1.58809 -0.0829296 0.916291
## 38: 4488.6630: 0.906283 -0.586156 -1.79392 -1.94108 3.48574 0.509076 3.34820 -0.192804 -0.693147 0.689958 -1.18636 0.0472211 -1.98926 3.57400 0.00894880 2.73178 -0.297574 -2.10862 -1.58121 -2.67506 0.916291 -0.115390 0.00174124 -0.673158 -1.59042 -1.70099 -1.49166 -2.10739 -1.58836 -0.0832908 0.916291
## 39: 4488.6630: 0.906453 -0.586372 -1.78768 -1.94051 3.48190 0.507454 3.34966 -0.192467 -0.693147 0.691080 -1.18600 0.0439173 -1.99134 3.57092 0.00765110 2.72899 -0.297888 -2.10807 -1.58060 -2.67496 0.916291 -0.115419 0.00174361 -0.672857 -1.59073 -1.70057 -1.49118 -2.10711 -1.58785 -0.0831941 0.916291
## 40: 4488.6630: 0.906693 -0.586258 -1.78366 -1.94073 3.47976 0.506401 3.35194 -0.191591 -0.693147 0.693576 -1.18519 0.0392088 -1.98946 3.56818 0.00635257 2.72624 -0.301864 -2.10822 -1.58101 -2.67633 0.916291 -0.115048 0.00175347 -0.673323 -1.59074 -1.70085 -1.49049 -2.10728 -1.58786 -0.0827127 0.916291
## 41: 4488.6630: 0.907046 -0.586401 -1.78639 -1.94127 3.48276 0.507014 3.35385 -0.191751 -0.693147 0.696125 -1.18569 0.0367872 -1.98839 3.56918 0.00686885 2.72281 -0.300593 -2.10794 -1.58126 -2.67679 0.916291 -0.114534 0.00175681 -0.673673 -1.59106 -1.70093 -1.49162 -2.10713 -1.58790 -0.0833066 0.916291
## 42: 4488.6630: 0.906935 -0.586076 -1.78773 -1.94083 3.48410 0.507820 3.35367 -0.191202 -0.693147 0.696350 -1.18592 0.0368833 -1.98968 3.56996 0.00681894 2.72292 -0.301273 -2.10759 -1.58103 -2.67619 0.916291 -0.114598 0.00175211 -0.673477 -1.59078 -1.70067 -1.49167 -2.10697 -1.58787 -0.0833017 0.916291
## 43: 4488.6630: 0.906779 -0.586220 -1.78703 -1.94089 3.48437 0.508317 3.35318 -0.191080 -0.693147 0.695388 -1.18512 0.0373029 -1.99102 3.56931 0.00690861 2.72324 -0.301489 -2.10859 -1.58092 -2.67552 0.916291 -0.115126 0.00174295 -0.673144 -1.59081 -1.70084 -1.49065 -2.10734 -1.58813 -0.0829092 0.916291
## 44: 4488.6630: 0.906756 -0.586226 -1.78590 -1.94066 3.48417 0.508249 3.35347 -0.191311 -0.693147 0.695460 -1.18550 0.0366618 -1.98991 3.56860 0.00637875 2.72279 -0.301992 -2.10825 -1.58096 -2.67608 0.916291 -0.114917 0.00175234 -0.673175 -1.59074 -1.70074 -1.49108 -2.10713 -1.58794 -0.0830782 0.916291
## 45: 4488.6630: 0.906775 -0.586183 -1.78592 -1.94078 3.48430 0.508209 3.35345 -0.191092 -0.693147 0.695549 -1.18558 0.0365197 -1.98997 3.56853 0.00639166 2.72258 -0.301978 -2.10801 -1.58102 -2.67617 0.916291 -0.114870 0.00175261 -0.673316 -1.59083 -1.70076 -1.49116 -2.10715 -1.58789 -0.0831023 0.916291
## 46: 4488.6630: 0.906780 -0.586190 -1.78621 -1.94078 3.48453 0.508275 3.35352 -0.191111 -0.693147 0.695594 -1.18550 0.0364435 -1.99015 3.56863 0.00642997 2.72238 -0.301996 -2.10810 -1.58101 -2.67601 0.916291 -0.114899 0.00174975 -0.673295 -1.59081 -1.70077 -1.49109 -2.10715 -1.58797 -0.0831032 0.916291
## 47: 4488.6630: 0.906774 -0.586208 -1.78634 -1.94079 3.48472 0.508404 3.35353 -0.191077 -0.693147 0.695546 -1.18551 0.0363293 -1.99022 3.56861 0.00644636 2.72208 -0.302082 -2.10811 -1.58097 -2.67600 0.916291 -0.114915 0.00174966 -0.673269 -1.59078 -1.70076 -1.49108 -2.10717 -1.58794 -0.0830743 0.916291
## converged: relative convergence (4)
Calculate model outputs:
outputs <- output_package(fit, naomi_data) #' Note that in the vignette they have naomi_mf here, is this a mistake?
The output package consists of a data frame of indicators and metadata defining the labels for each indicator:
names(outputs)
## [1] "indicators" "art_attendance" "meta_area" "meta_age_group" "meta_period" "meta_indicator"
## [7] "fit" "inputs_outputs"
If uncertainty has not been calcualted yet, the output object retures values for the mode, but not the mean or lower and upper 95% uncertainty ranges:
outputs$indicators %>%
dplyr::filter(
indicator == "prevalence", #' HIV prevalence
age_group == "Y015_049" #' Age group 15-49
) %>%
head()
The function add_output_labels()
returns the indicators
table with labels added as additional columns:
add_output_labels(outputs) %>%
dplyr::filter(
indicator == "prevalence", # HIV prevalence
age_group == "Y015_049" # Age group 15-49
) %>%
head()
system.time(fit <- sample_tmb(fit))
## user system elapsed
## 7.550 1.822 10.186
Regenerate outputs with uncertainty ranges:
system.time(outputs <- output_package(fit, naomi_data))
## user system elapsed
## 82.431 1.401 83.861
outputs_calib <- calibrate_outputs(
outputs,
naomi_mf,
spectrum_plhiv_calibration_level = "national",
spectrum_plhiv_calibration_strat = "sex_age_coarse",
spectrum_artnum_calibration_level = "national",
spectrum_artnum_calibration_strat = "sex_age_coarse",
spectrum_aware_calibration_level = "national",
spectrum_aware_calibration_strat = "sex_age_coarse",
spectrum_infections_calibration_level = "national",
spectrum_infections_calibration_strat = "sex_age_coarse"
)
outputs$indicators %>%
dplyr::filter(
indicator == "prevalence", # HIV prevalence
age_group == "Y015_049" # Age group 15-49
) %>%
head()
indicators <- add_output_labels(outputs) %>%
left_join(outputs$meta_area %>% select(area_level, area_id, center_x, center_y)) %>%
sf::st_as_sf()
## Joining, by = c("area_level", "area_id")
15-49 prevalence by district (which is area_level
4):
indicators %>%
filter(age_group == "Y015_049",
indicator == "prevalence",
area_level == 4) %>%
ggplot(aes(fill = mode)) +
geom_sf() +
viridis::scale_fill_viridis(labels = scales::percent_format()) +
th_map() +
facet_wrap(~sex)
15-49 prevalence by zone (which is area_level
2):
indicators %>%
filter(age_group == "Y015_049",
indicator == "prevalence",
area_level == 2) %>%
ggplot(aes(fill = mode)) +
geom_sf() +
viridis::scale_fill_viridis(labels = scales::percent_format()) +
th_map() +
facet_wrap(~sex)
Age-specific prevalence at a national-level:
indicators %>%
dplyr::filter(area_level == 0,
sex != "both",
age_group %in% get_five_year_age_groups(),
calendar_quarter == "CY2018Q3",
indicator == "prevalence") %>%
left_join(get_age_groups()) %>%
mutate(age_group = fct_reorder(age_group_label, age_group_sort_order)) %>%
ggplot(aes(age_group, mean, ymin = lower, ymax = upper, fill = sex)) +
geom_col(position = "dodge") +
geom_linerange(position = position_dodge(0.8)) +
scale_fill_brewer(palette = "Set1") +
scale_y_continuous(labels = scales::percent_format(1)) +
facet_wrap(~area_name) +
theme(axis.text.x = element_text(angle = 90, hjust = 1.0, vjust = 0.5))
## Joining, by = c("age_group", "age_group_label")
ART coverage by age-sex-region:
indicators %>%
filter(area_level == 1,
sex != "both",
age_group %in% get_five_year_age_groups(),
indicator == "art_coverage",
calendar_quarter == "CY2018Q3") %>%
left_join(get_age_groups()) %>%
mutate(age_group = fct_reorder(age_group_label, age_group_sort_order)) %>%
ggplot(aes(age_group, mean, ymin = lower, ymax = upper, fill = sex)) +
geom_col(position = "dodge") +
geom_linerange(position = position_dodge(0.8)) +
scale_fill_brewer(palette = "Set1") +
scale_y_continuous(labels = scales::percent_format(1)) +
facet_wrap(~area_name) +
theme(axis.text.x = element_text(angle = 90, hjust = 1.0, vjust = 0.5))
## Joining, by = c("age_group", "age_group_label")
Bubble plot of prevalence and PLHIV:
indicators %>%
filter(age_group == "Y015_064",
area_level == 4,
indicator %in% c("prevalence", "plhiv"),
calendar_quarter == "CY2018Q3") %>%
select(sex, center_x, center_y, indicator_label, mean) %>%
spread(indicator_label, mean) %>%
ggplot() +
geom_sf() +
geom_point(aes(center_x, center_y, colour = `HIV prevalence`, size = PLHIV)) +
viridis::scale_color_viridis(labels = scales::percent_format()) +
th_map() +
facet_wrap(~sex)