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, "bw-explore-smooths.rds")
bwdata_model <- fst::read_fst(file.path(path_processed, "bwdata_41_model.fst"))
Exploratory models of birthweight with covariates
terms <- list(
~ s(age),
~ s(wk_ini),
~ s(rivwk_conception, bs = "cc"),
~ s(remoteness),
~ s(rur_prop),
~ s(prop_tap_toilet),
~ s(longitud, latitud)
)
data_model <- tibble::tibble(
formula = map(terms, ~ update(., born_weight ~ .))
)
data_model <- data_model %>%
mutate(model = map(formula, ~ gam(.x, data = bwdata_model)))
saveRDS(data_model, file = path_out_model_data)
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 15.780 0.988 16.837