Municipality effects of remoteness and sanitation on BW, LBW and PTB
In this script, we compute municipality effects of remoteness and sanitation on birth outcomes. The resulting figure can be seen at section Visualize municipality effects of remoteness and sanitation. This output corresponds to Extended Data Figure 8 of our paper.
Load packages, read data and source custom scripts
rm(list = ls())
library(bamlss)
#> Loading required package: coda
#> Loading required package: colorspace
#> Loading required package: mgcv
#> Loading required package: nlme
#> This is mgcv 1.8-31. For overview type 'help("mgcv-package")'.
#>
#> Attaching package: 'bamlss'
#> The following object is masked from 'package:mgcv':
#>
#> smooth.construct
library(gamlss.dist)
#> Loading required package: MASS
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following object is masked from 'package:MASS':
#>
#> select
#> The following object is masked from 'package:bamlss':
#>
#> n
#> The following object is masked from 'package:nlme':
#>
#> collapse
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(purrr)
library(patchwork)
#>
#> Attaching package: 'patchwork'
#> The following object is masked from 'package:MASS':
#>
#> area
library(ggplot2)
path_proj <- day2day::git_path()
path_data <- file.path(path_proj, "data")
path_processed <- file.path(path_data, "processed")
path_modelled <- file.path(path_data, "modelled")
path_summarised <- file.path(path_data, "summarised")
source(file.path(path_proj, "src", "51-bamlss.R"))
source(file.path(path_proj, "src", "57-bamlss-vis-paper.R"))
source(file.path(path_proj, "src", "56-bamlss-vis-gg.R"))
bwdata_file <- file.path(path_processed, "bwdata_41_model.fst")
path_model_bw_full <- file.path(path_modelled, "bw-10-full-re-t-burned.rds")
path_model_bw_growth <- file.path(path_modelled, "bw-20-growth-re-t-burned.rds")
path_model_lbw_full <- file.path(path_modelled, "lbw-10-full-re-burned.rds")
path_model_lbw_growth <- file.path(path_modelled, "lbw-20-growth-re-burned.rds")
path_model_pre <- file.path(path_modelled, "pre-11-full-re-burned.rds")
bwdata_model <- fst::read_fst(bwdata_file)
model_bw_full <- readRDS(path_model_bw_full)
model_bw_growth <- readRDS(path_model_bw_growth)
model_lbw_full <- readRDS(path_model_lbw_full)
model_lbw_growth <- readRDS(path_model_lbw_growth)
model_pre <- readRDS(path_model_pre)
Create figure
types <- factor(c("No", "Yes"))
legend_title <- "Controlling for gestational age?"
guides_none <- guides(fill = "none", col = "none", linetype = "none")
gg_1_1 <- gg_smooths(
list(model_bw_full, model_bw_growth), bwdata_model,
"mu", "remoteness", 0, intercept = FALSE
) +
labs(y = "Mean change (grams)", subtitle = "(a)") +
guides_none
#> Note: Using an external vector in selections is ambiguous.
#> ℹ Use `all_of(var)` instead of `var` to silence this message.
#> ℹ See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
#> This message is displayed once per session.
gg_1_2 <- gg_smooths(
list(model_lbw_full, model_lbw_growth), bwdata_model,
"pi", "remoteness", 1, intercept = FALSE, FUN = c95_exp
) +
labs(y = "LBW odds ratio", x = "Remoteness", subtitle = "(b)") +
guides_none
gg_1_3 <- gg_smooths(
list(model_pre), bwdata_model,
"pi", "remoteness", 1, types = types[1], intercept = FALSE, FUN = c95_exp
) +
labs(y = "PTB odds ratio", subtitle = "(c)") +
guides_none
gg_2_1 <- gg_smooths(
list(model_bw_full, model_bw_growth), bwdata_model,
"mu", "prop_tap_toilet", 0, intercept = FALSE
) +
labs(y = "Mean change (grams)", subtitle = "(d)") +
guides_none
gg_2_2 <- gg_smooths(
list(model_lbw_full, model_lbw_growth), bwdata_model,
"pi", "prop_tap_toilet", 1, intercept = FALSE, FUN = c95_exp
) +
labs(y = "LBW odds ratio", x = "Population proportion with sanitation", subtitle = "(e)",
fill = legend_title, col = legend_title, linetype = legend_title) +
theme(legend.position = "bottom")
gg_2_3 <- gg_smooths(
list(model_pre), bwdata_model,
"pi", "prop_tap_toilet", 1, types = types[1], intercept = FALSE, FUN = c95_exp
) +
labs(y = "PTB odds ratio", subtitle = "(f)") +
guides_none
base_size <- 7
gg <- gg_1_1 + gg_1_2 + gg_1_3 + gg_2_1 + gg_2_2 + gg_2_3 +
plot_layout(guides = "collect", nrow = 2) &
theme(legend.position = "bottom",
legend.title = element_text(size = base_size, face = "bold"),
legend.text = element_text(size = base_size),
axis.title = element_text(size = base_size),
axis.text = element_text(size = base_size),
plot.title = element_text(size = base_size),
plot.margin = margin(3, 7, 0, 0))
ggsave(file.path(path_summarised, "paper-mod-eff-municipality-covs.pdf"), gg ,
width = 18, height = 11.7, units = "cm")
ggsave(file.path(path_summarised, "paper-mod-eff-municipality-covs.jpg"), gg ,
width = 18, height = 11.7, units = "cm", dpi = 350)
Visualize municipality effects of remoteness and sanitation
print(gg, vp = grid::viewport(gp = grid::gpar(cex = 1.15)))
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 54.761 2.846 57.588