Skip to content

Commit 70e8711

Browse files
committed
Lots of Seth fixes, change paper name, change repo name #55
1 parent 6ddfda3 commit 70e8711

File tree

8 files changed

+119
-53
lines changed

8 files changed

+119
-53
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# elgm-inf
1+
# naomi-aghq
22

3-
Code for the manuscript Howes, Stringer, Flaxman and Eaton "Fast approximate Bayesian inference of HIV indicators using the Naomi small-area estimation model" (in preparation).
3+
Code for the manuscript Howes, Stringer, Flaxman and Eaton "Fast approximate Bayesian inference of HIV indicators using PCA adaptive Gauss-Hermite quadrature" (in preparation).
44

55
[Naomi](https://github.com/mrc-ide/naomi) ([Eaton et al, 2021](https://onlinelibrary.wiley.com/doi/10.1002/jia2.25788)) is a spatial evidence synthesis model used to produce district-level HIV epidemic indicators in sub-Saharan Africa.
66
Multiple outcomes of interest, including HIV prevalence, HIV incidence and treatment coverage are jointly modelled using both household survey data and routinely reported health system data.
77
The model is provided as a [tool](https://naomi.unaids.org/) for countries to input their data to and generate estimates during a yearly process supported by UNAIDS.
88
Currently, inference is conducted using empirical Bayes and a Gaussian approximation via the [`TMB`](https://kaskr.github.io/adcomp/_book/Introduction.html) R package.
9-
We propose a new inference method which extends adaptive Gauss-Hermite quadrature to deal with >20 hyperparameters, enabling fast and accurate inference for Naomi and other [extended latent Gaussian](https://www.tandfonline.com/doi/full/10.1080/10618600.2022.2099403) models.
9+
We propose a new inference method extending adaptive Gauss-Hermite quadrature to deal with >20 hyperparameters, enabling fast and accurate inference for Naomi and other [extended latent Gaussian](https://www.tandfonline.com/doi/full/10.1080/10618600.2022.2099403) models.
1010
Using data from Malawi, our method improves the accuracy of inferences across a range of metrics, while being substantially faster to run than Hamiltonian Monte Carlo with the No-U-Turn sampler.
11-
By extending the [`aghq`](https://github.com/awstringer1/aghq) package ([Stringer, 2021](https://arxiv.org/abs/2101.04468)) we facilitate easy, flexible use of our method when provided a [`TMB`](https://kaskr.github.io/adcomp/_book/Introduction.html) C++ template for the model's log-posterior.
11+
Our implementation uses the [`aghq`](https://github.com/awstringer1/aghq) package ([Stringer, 2021](https://arxiv.org/abs/2101.04468)) facilitating easy, flexible use of the method when provided a [`TMB`](https://kaskr.github.io/adcomp/_book/Introduction.html) C++ template for the model's log-posterior.
1212

1313
![Example district-level Naomi model outputs for adults aged 15-49.](naomi_results.png)
1414

File renamed without changes.

src/docs_paper/appendix.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Appendix to "Fast approximate Bayesian inference of HIV indicators using the Naomi small-area estimation model"
2+
title: Appendix to "Fast approximate Bayesian inference of HIV indicators using principal components analysis adaptive Gauss-Hermite quadrature"
33
author:
44
- Adam Howes^[Department of Mathematics, Imperial College London]
55
- Alex Stringer^[Department of Statistics and Actuarial Science, University of Waterloo]

src/docs_paper/citations.bib

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,3 +671,17 @@ @article{karatzoglou2019package
671671
year={2019}
672672
}
673673

674+
@Article{brooks2017glmmTMB,
675+
author = {Mollie E. Brooks and Kasper Kristensen and Koen J. {van
676+
Benthem} and Arni Magnusson and Casper W. Berg and Anders Nielsen
677+
and Hans J. Skaug and Martin Maechler and Benjamin M. Bolker},
678+
title = {{glmmTMB} Balances Speed and Flexibility Among Packages
679+
for Zero-inflated Generalized Linear Mixed Modeling},
680+
year = {2017},
681+
journal = {The R Journal},
682+
doi = {10.32614/RJ-2017-066},
683+
pages = {378--400},
684+
volume = {9},
685+
number = {2},
686+
}
687+

src/docs_paper/figures.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ mvQuad::rescale(gg5, m = mu, C = cov, dec.type = 1)
9393
figA5 <- add_points(figA0, gg5) +
9494
labs(size = "")
9595

96-
figA <- (figA1 + figA2) / (figA3 + figA4 + figA5)
96+
figA <- (figA1 + figA2) / (figA3 + figA4 + figA5) +
97+
plot_annotation(tag_levels = "A") &
98+
theme(plot.tag.position = c(0.15, 0.95))
9799

98100
#' Fig B
99101

src/docs_paper/orderly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ depends:
6060
id: latest
6161
use:
6262
depends/posterior-contraction.png: posterior-contraction.png
63-
depends/mean-sd.png: mean-sd.png
63+
depends/mean-sd.png: mean-sd-alt.png
6464
depends/mean-sd.csv: mean-sd.csv
6565
- check_hyper-marginals:
6666
id: latest

src/docs_paper/paper.Rmd

Lines changed: 51 additions & 30 deletions
Large diffs are not rendered by default.

src/naomi-simple_contraction/script.R

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,18 @@ posterior_contraction_plot <- bind_rows(df_hyper, df_latent) %>%
5858
coord_flip() +
5959
labs(x = "", y = "Posterior contraction", col = "Type", shape = "Type") +
6060
scale_color_manual(values = c("#56B4E9", "#009E73")) +
61-
scale_y_continuous(limits = c(-0.3, 1), breaks = c(-0.2, 0, 0.2, 0.4, 0.6, 0.8, 1)) +
61+
scale_y_continuous(
62+
limits = c(-1, 1),
63+
breaks = c(-1.0, -0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6, 0.8, 1.0)
64+
) +
65+
geom_hline(yintercept = 0, linetype = "dashed", size = 0.25) +
66+
annotate("text", x = 36, y = -0.6, size = 3, label = "Prior tighter") +
67+
annotate("text", x = 36, y = 0.4, size = 3, label = "Posterior tighter") +
68+
annotate("segment", x = 35, xend = 35, y = 0, yend = -1.0, size = 0.25, arrow = arrow(length = unit(0.2, "cm"))) +
69+
annotate("segment", x = 35, xend = 35, y = 0, yend = 1.0, size = 0.25, arrow = arrow(length = unit(0.2, "cm"))) +
6270
theme_minimal()
6371

64-
ggsave("posterior-contraction.png", posterior_contraction_plot, h = 6.5, w = 6.25)
72+
ggsave("posterior-contraction.png", posterior_contraction_plot, h = 6.5, w = 6.25, bg = "white")
6573

6674
#' Which have lower amounts of posterior contraction?
6775
names(subset(posterior_contraction, posterior_contraction < 0.5))
@@ -126,47 +134,68 @@ df_metrics <- df_metrics %>%
126134

127135
write_csv(df_metrics, "mean-sd.csv")
128136

129-
mean_sd_plot <- ggplot(df_plot, aes(x = truth, y = approximate)) +
137+
mean_sd_plot <- ggplot(df_plot, aes(x = truth, y = approximate - truth)) +
130138
geom_point(shape = 1, alpha = 0.4) +
131139
facet_grid(indicator ~ method) +
132-
coord_fixed(ratio = 1) +
133-
geom_abline(slope = 1, intercept = 0, linetype = "dashed") +
140+
geom_abline(slope = 0, intercept = 0, linetype = "dashed") +
134141
geom_text(data = df_metrics, aes(x = -Inf, y = Inf, label = label), size = 3, hjust = 0, vjust = 1.5) +
135-
labs(x = "NUTS", y = "") +
142+
labs(x = "NUTS", y = "Approximation - NUTS") +
136143
theme_minimal()
137144

138145
ggsave("mean-sd.png", mean_sd_plot, h = 6, w = 6.25)
139146

140147
#' Split into two plots for presentations etc.
141148

149+
jitter_amount <- 0.02
150+
142151
mean_plot <- df_plot %>%
143152
filter(indicator == "Posterior mean estimate") %>%
144-
ggplot(aes(x = truth, y = approximate)) +
145-
geom_point(shape = 1, alpha = 0.4) +
153+
ggplot(aes(x = truth, y = approximate - truth)) +
154+
geom_jitter(shape = 1, alpha = 0.4, width = jitter_amount, height = jitter_amount) +
155+
lims(y = c(-0.4, 0.4)) +
146156
facet_grid(indicator ~ method) +
147-
coord_fixed(ratio = 1) +
148-
geom_abline(slope = 1, intercept = 0, linetype = "dashed") +
157+
geom_abline(slope = 0, intercept = 0, linetype = "dashed", size = 0.25) +
149158
geom_text(
150159
data = filter(df_metrics, indicator == "Posterior mean estimate"),
151160
aes(x = -Inf, y = Inf, label = label), size = 3, hjust = 0, vjust = 1.5
152161
) +
153-
labs(x = "NUTS", y = "") +
162+
labs(x = "NUTS", y = "Approximation - NUTS") +
154163
theme_minimal()
155164

156165
ggsave("mean.png", mean_plot, h = 4, w = 6.25)
157166

158167
sd_plot <- df_plot %>%
159168
filter(indicator == "Posterior SD estimate") %>%
160-
ggplot(aes(x = truth, y = approximate)) +
161-
geom_point(shape = 1, alpha = 0.4) +
169+
ggplot(aes(x = truth, y = approximate - truth)) +
170+
geom_jitter(shape = 1, alpha = 0.4, width = jitter_amount, height = jitter_amount) +
171+
lims(y = c(-0.6, 0.6)) +
162172
facet_grid(indicator ~ method) +
163-
coord_fixed(ratio = 1) +
164-
geom_abline(slope = 1, intercept = 0, linetype = "dashed") +
173+
geom_abline(slope = 0, intercept = 0, linetype = "dashed", size = 0.25) +
165174
geom_text(
166175
data = filter(df_metrics, indicator == "Posterior SD estimate"),
167176
aes(x = -Inf, y = Inf, label = label), size = 3, hjust = 0, vjust = 1.5
168177
) +
169-
labs(x = "NUTS", y = "") +
178+
labs(x = "NUTS", y = "Approximation - NUTS") +
170179
theme_minimal()
171180

172181
ggsave("sd.png", sd_plot, h = 4, w = 6.25)
182+
183+
sd_plot_alt <- sd_plot +
184+
theme(
185+
strip.background = element_blank(),
186+
strip.text.x = element_blank()
187+
)
188+
189+
y_axis <- ggplot(data.frame(l = mean_plot$labels$y, x = 1, y = 1)) +
190+
geom_text(aes(x, y, label = l), angle = 90) +
191+
theme_void() +
192+
coord_cartesian(clip = "off")
193+
194+
mean_plot_alt <- mean_plot
195+
mean_plot_alt$labels$x <- ""
196+
mean_plot_alt$labels$y <- sd_plot_alt$labels$y <- ""
197+
198+
mean_sd_plot_alt <- y_axis + (mean_plot_alt / sd_plot_alt) +
199+
plot_layout(widths = c(1, 30))
200+
201+
ggsave("mean-sd-alt.png", mean_sd_plot_alt, h = 6, w = 6.25)

0 commit comments

Comments
 (0)