Nonlinear effects (simple figures) on BW, LBW and PTB


Visualization of nonlinear effects that are not presented in 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
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"))


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)

Visualize effects on location parameters (mu and pi)

Nonlinear age effects

plot_eff_2d(
    bwdata_model, "s(age)", "Age", file.path(path_summarised, "mod-eff-nonlinear-age.pdf"),
    list(model_bw_full, model_bw_growth, model_lbw_full, model_lbw_growth, model_pre)
)
#> png 
#>   2

Nonlinear hydrological seasonality effects

plot_eff_2d(
    bwdata_model, "s(rivwk_conception)", "Seasonal river level index",
    file.path(path_summarised, "mod-eff-nonlinear-seasonality.pdf"),
    list(model_bw_full, model_bw_growth, model_lbw_full, model_lbw_growth, model_pre)
)
#> png 
#>   2

Nonlinear temporal effects

plot_eff_conception(
    bwdata_model, "s(wk_ini)", "Conception date",
    file.path(path_summarised, "mod-eff-nonlinear-temporal.pdf"),
    list(model_bw_full, model_bw_growth, model_lbw_full, model_lbw_growth, model_pre)
)
#> png 
#>   2

Visualize effects on the scale parameter (sigma)

Nonlinear age effects

plot_eff_2d_sigma(
    bwdata_model, "s(age)", "Age",
    file.path(path_summarised, "mod-eff-nonlinear-age-sigma.pdf"),
    list(model_bw_full, model_bw_growth)
)
#> png 
#>   2

Nonlinear temporal effects

plot_eff_conception_sigma(
    bwdata_model, "s(wk_ini)", "Conception date",
    file.path(path_summarised, "mod-eff-nonlinear-temporal-sigma.pdf"),
    list(model_bw_full, model_bw_growth, model_lbw_full, model_lbw_growth, model_pre)
)
#> png 
#>   2

Time to execute the task

Only useful when executed with Rscript.

proc.time()
#>    user  system elapsed 
#>  47.475   2.851  50.316