Municipality one-term models: smooths


Simple univariate GAM models to evaluate the relationship birthweight and each covariates.

Load packages, read data and source custom scripts

rm(list = ls())
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(mgcv)
#> Loading required package: nlme
#> 
#> Attaching package: 'nlme'
#> The following object is masked from 'package:dplyr':
#> 
#>     collapse
#> This is mgcv 1.8-31. For overview type 'help("mgcv-package")'.
library(purrr)

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_out_model_data <- file.path(path_modelled,  "lbw-explore-smooths-muni.rds")

bwdata_model <- fst::read_fst(file.path(path_processed, "bwdata_41_model.fst"))

Exploratory models of low birthweight with municipality covariates

terms <- list(
    ~ s(remoteness),
    ~ s(rur_prop),
    ~ s(prop_tap_toilet)
    )

data_model <- tibble::as_tibble(expand.grid(
    formula = map(terms, ~ update(., lbw ~ .)),
    gamma = c(1, log(nrow(bwdata_model)), 18, 40)
))

data_model <- data_model %>%
    mutate(model = map2(formula, gamma,
                        ~ gam(.x, "binomial", data = bwdata_model, gamma = .y)))

saveRDS(data_model, file = path_out_model_data)

Time to execute the task

Only useful when executed with Rscript.

proc.time()
#>    user  system elapsed 
#>  78.791   2.107  81.015