Full model without rainfall: fitting
Low birthweight model including covariates at municipality level with linear effects.
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_modelled_data <- file.path(path_modelled, "lbw-15-full-no-rain.rds")
path_modelled_sink <- gsub("\\.rds$", "\\.txt", path_modelled_data)
path_modelled_form <- gsub("(\\.rds)$", "-form\\1", path_modelled_data)
bwdata_model <- fst::read_fst(file.path(path_processed, "bwdata_41_model.fst"))
Define formula for our model
form <- lbw ~ sex + born_race + birth_place +
marital_status + study_years + consult_num + s(age) +
s(wk_ini) + s(rivwk_conception, bs = "cc") +
remoteness + prop_tap_toilet + s(res_muni, bs = "re")
Run the model of interest and save results
{
sink(path_modelled_sink)
bamlss_model <- bamlss(
form, family = "binomial", data = bwdata_model,
n.iter = 8000, burnin = 0, cores = 4, combine = FALSE, light = TRUE
)
sink()
}
readLines(path_modelled_sink)
#> [1] "AICc 139282.9 logPost -69882.8 logLik -69566.2 edf 75.229 eps 0.5483 iteration 1"
#> [2] "AICc 130130.0 logPost -65998.2 logLik -64985.7 edf 79.241 eps 0.2211 iteration 2"
#> [3] "AICc 129803.7 logPost -70325.5 logLik -64822.0 edf 79.845 eps 0.0367 iteration 3"
#> [4] "AICc 129789.0 logPost -76962.0 logLik -64814.5 edf 79.985 eps 0.0067 iteration 4"
#> [5] "AICc 129787.8 logPost -78702.7 logLik -64813.9 edf 79.928 eps 0.0020 iteration 5"
#> [6] "AICc 129787.8 logPost -78905.3 logLik -64813.9 edf 79.907 eps 0.0007 iteration 6"
#> [7] "AICc 129787.8 logPost -78925.9 logLik -64814.0 edf 79.899 eps 0.0002 iteration 7"
#> [8] "AICc 129787.9 logPost -78927.9 logLik -64814.0 edf 79.896 eps 0.0000 iteration 8"
#> [9] "AICc 129787.9 logPost -78927.9 logLik -64814.0 edf 79.896 eps 0.0000 iteration 8"
#> [10] "elapsed time: 41.67sec"
#> [11] "Starting the sampler...Starting the sampler..."
#> [12] ""
#> [13] "Starting the sampler..."
#> [14] "Starting the sampler..."
#> [15] ""
#> [16] ""
#> [17] ""
#> [18] "|| | | 0% | 0% 170.55min170.55min | 0% 170.53min"
#> [19] "| | 0% 170.67min"
#> [20] "|* | 5% 159.62min 8.40min"
#> [21] "|* | 5% 160.23min 8.43min"
#> [22] "|* | 5% 160.23min 8.43min"
#> [23] "|* | 5% 160.23min 8.43min"
#> [24] "|** | 10% 151.07min 16.79min"
#> [25] ""
#> [26] "|** | 10%"
#> [27] " 151.83min 16.87min|** | 10% 151.83min 16.87min|** | 10% 151.83min 16.87min"
#> [28] "|*** | 15% 142.83min 25.20min"
#> [29] "|*** | 15% 143.47min 25.32min"
#> [30] "|*** | 15% 143.57min 25.34min"
#> [31] "|*** | 15% 143.57min 25.34min"
#> [32] "|**** | 20% 134.79min 33.70min"
#> [33] "|**** | 20% 135.27min 33.82min"
#> [34] ""
#> [35] "|**** | 20% 135.36min 33.84min|**** | 20% 135.36min 33.84min"
#> [36] "|***** | 25% 126.38min 42.13min"
#> [37] "|***** | 25% 126.75min 42.25min"
#> [38] "|***** | 25% 126.89min 42.30min"
#> [39] "|***** | 25% 126.89min 42.30min"
#> [40] "|****** | 30% 117.85min 50.51min"
#> [41] "|****** | 30% 118.25min 50.68min"
#> [42] "|****** | 30% 118.37min 50.73min"
#> [43] "|****** | 30% 118.38min 50.74min"
#> [44] "|******* | 35% 109.50min 58.96min"
#> [45] "|******* | 35% 109.81min 59.13min"
#> [46] "|******* | 35% 109.92min 59.19min"
#> [47] "|******* | 35% 109.92min 59.19min"
#> [48] "|******** | 40% 101.12min 67.41min"
#> [49] "|******** | 40% 101.43min 67.62min"
#> [50] "|******** | 40% 101.48min 67.66min"
#> [51] "|******** | 40% 101.53min 67.68min"
#> [52] "|********* | 45% 92.68min 75.83min"
#> [53] "|********* | 45% 93.01min 76.10min"
#> [54] "|********* | 45% 93.03min 76.12min"
#> [55] "|********* | 45% 93.08min 76.16min"
#> [56] "|********** | 50% 84.30min 84.30min"
#> [57] "|********** | 50% 84.59min 84.59min"
#> [58] "|********** | 50% 84.60min 84.60min"
#> [59] "|********** | 50% 84.67min 84.67min"
#> [60] "|*********** | 55% 75.88min 92.74min"
#> [61] "|*********** | 55% 76.13min 93.05min"
#> [62] "|*********** | 55% 76.16min 93.09min"
#> [63] "|*********** | 55% 76.21min 93.15min"
#> [64] "|************ | 60% 67.46min 101.19min"
#> [65] "|************ | 60% 67.69min 101.53min"
#> [66] "|************ | 60% 67.72min 101.59min"
#> [67] "|************ | 60% 67.77min 101.65min"
#> [68] "|************* | 65% 59.06min 109.69min"
#> [69] "|************* | 65% 59.24min 110.01min"
#> [70] "|************* | 65% 59.28min 110.10min"
#> [71] "|************* | 65% 59.32min 110.16min"
#> [72] "|************** | 70% 50.65min 118.18min"
#> [73] "|************** | 70% 50.80min 118.53min"
#> [74] "|************** | 70% 50.83min 118.61min"
#> [75] "|************** | 70% 50.86min 118.68min"
#> [76] "|*************** | 75% 42.21min 126.64min"
#> [77] "|*************** | 75% 42.33min 126.99min"
#> [78] "|*************** | 75% 42.37min 127.10min"
#> [79] "|*************** | 75% 42.39min 127.16min"
#> [80] "|**************** | 80% 33.77min 135.07min"
#> [81] "|**************** | 80% 33.86min 135.46min"
#> [82] "|**************** | 80% 33.89min 135.57min"
#> [83] "|**************** | 80% 33.91min 135.64min"
#> [84] "|***************** | 85% 25.33min 143.53min"
#> [85] "|***************** | 85% 25.40min 143.94min"
#> [86] "|***************** | 85% 25.42min 144.07min"
#> [87] "|***************** | 85% 25.44min 144.13min"
#> [88] "|****************** | 90% 16.89min 152.03min"
#> [89] "|****************** | 90% 16.94min 152.47min"
#> [90] "|****************** | 90% 16.96min 152.61min"
#> [91] "|****************** | 90% 16.96min 152.68min"
#> [92] "|******************* | 95% 8.45min 160.51min"
#> [93] "|******************* | 95% 8.47min 160.97min"
#> [94] "|******************* | 95% 8.48min 161.12min"
#> [95] "|******************* | 95% 8.48min 161.18min"
#> [96] "|********************| 100% 0.00sec 169.00min"
#> [97] ""
#> [98] "|********************| 100% 0.00sec 169.40min"
#> [99] ""
#> [100] "|********************| 100% 0.00sec 169.51min"
#> [101] ""
#> [102] "|********************| 100% 0.00sec 169.55min"
system.time(saveRDS(bamlss_model, file = path_modelled_data))
#> user system elapsed
#> 4.503 0.007 4.549
saveRDS(form, file = path_modelled_form)
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 40751.926 27.022 10254.004