Full model 2: fitting
Prematurity 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, "pre-11-full-re.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_aux <- premature ~ 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")
form <- update(form_aux, . ~ . +
s(neg_mbsi_mean_1wk, pos_mbsi_mean_1wk, k = 70) +
s(neg_mckee_mean_8wk, pos_mckee_mean_8wk, k = 70) +
s(neg_ext_mbsi_mean_8wk, pos_ext_mbsi_mean_8wk, k = 70))
Run the model of interest and save results
{
sink(path_modelled_sink)
bamlss_model <- bamlss(
form, family = "binomial", data = bwdata_model,
n.iter = 10000, burnin = 0, cores = 4, combine = FALSE, light = TRUE
)
sink()
}
readLines(path_modelled_sink)
#> [1] "AICc 168427.6 logPost -84499.9 logLik -83963.4 edf 250.18 eps 0.5528 iteration 1"
#> [2] "AICc 155732.8 logPost -78372.0 logLik -77588.0 edf 278.10 eps 0.2989 iteration 2"
#> [3] "AICc 153777.7 logPost -77394.6 logLik -76602.2 edf 286.36 eps 0.1108 iteration 3"
#> [4] "AICc 153222.1 logPost -77222.7 logLik -76322.5 edf 288.27 eps 0.0550 iteration 4"
#> [5] "AICc 153055.5 logPost -77077.2 logLik -76239.0 edf 288.47 eps 0.0273 iteration 5"
#> [6] "AICc 153001.1 logPost -77012.1 logLik -76211.7 edf 288.54 eps 0.0137 iteration 6"
#> [7] "AICc 152978.8 logPost -76999.8 logLik -76200.6 edf 288.52 eps 0.0103 iteration 7"
#> [8] "AICc 152967.6 logPost -76994.6 logLik -76195.0 edf 288.49 eps 0.0046 iteration 8"
#> [9] "AICc 152961.1 logPost -76991.3 logLik -76191.8 edf 288.45 eps 0.0030 iteration 9"
#> [10] "AICc 152956.9 logPost -76989.2 logLik -76189.7 edf 288.42 eps 0.0020 iteration 10"
#> [11] "AICc 152954.0 logPost -76987.6 logLik -76188.3 edf 288.40 eps 0.0028 iteration 11"
#> [12] "AICc 152951.9 logPost -76986.5 logLik -76187.2 edf 288.39 eps 0.0014 iteration 12"
#> [13] "AICc 152950.3 logPost -76985.7 logLik -76186.5 edf 288.38 eps 0.0009 iteration 13"
#> [14] "AICc 152949.1 logPost -76985.0 logLik -76185.9 edf 288.37 eps 0.0008 iteration 14"
#> [15] "AICc 152948.2 logPost -76984.5 logLik -76185.4 edf 288.37 eps 0.0006 iteration 15"
#> [16] "AICc 152947.4 logPost -76984.1 logLik -76185.0 edf 288.37 eps 0.0005 iteration 16"
#> [17] "AICc 152946.8 logPost -76983.8 logLik -76184.7 edf 288.37 eps 0.0005 iteration 17"
#> [18] "AICc 152946.3 logPost -76983.6 logLik -76184.5 edf 288.37 eps 0.0006 iteration 18"
#> [19] "AICc 152945.9 logPost -76983.4 logLik -76184.3 edf 288.37 eps 0.0005 iteration 19"
#> [20] "AICc 152945.6 logPost -76983.3 logLik -76184.1 edf 288.37 eps 0.0006 iteration 20"
#> [21] "AICc 152945.3 logPost -76983.1 logLik -76184.0 edf 288.38 eps 0.0041 iteration 21"
#> [22] "AICc 152945.1 logPost -76983.0 logLik -76183.8 edf 288.38 eps 0.0003 iteration 22"
#> [23] "AICc 152944.9 logPost -76983.0 logLik -76183.7 edf 288.38 eps 0.0002 iteration 23"
#> [24] "AICc 152944.7 logPost -76982.9 logLik -76183.6 edf 288.39 eps 0.0002 iteration 24"
#> [25] "AICc 152944.5 logPost -76982.8 logLik -76183.6 edf 288.39 eps 0.0002 iteration 25"
#> [26] "AICc 152944.4 logPost -76982.8 logLik -76183.5 edf 288.40 eps 0.0001 iteration 26"
#> [27] "AICc 152944.3 logPost -76982.8 logLik -76183.4 edf 288.40 eps 0.0001 iteration 27"
#> [28] "AICc 152944.2 logPost -76982.8 logLik -76183.4 edf 288.40 eps 0.0001 iteration 28"
#> [29] "AICc 152944.1 logPost -76982.7 logLik -76183.3 edf 288.41 eps 0.0001 iteration 29"
#> [30] "AICc 152944.1 logPost -76982.7 logLik -76183.3 edf 288.41 eps 0.0001 iteration 30"
#> [31] "AICc 152944.0 logPost -76982.7 logLik -76183.3 edf 288.41 eps 0.0001 iteration 31"
#> [32] "AICc 152943.9 logPost -76982.7 logLik -76183.2 edf 288.42 eps 0.0001 iteration 32"
#> [33] "AICc 152943.9 logPost -76982.7 logLik -76183.2 edf 288.42 eps 0.0001 iteration 33"
#> [34] "AICc 152943.9 logPost -76982.7 logLik -76183.2 edf 288.42 eps 0.0001 iteration 34"
#> [35] "AICc 152943.8 logPost -76982.7 logLik -76183.2 edf 288.43 eps 0.0001 iteration 35"
#> [36] "AICc 152943.8 logPost -76982.7 logLik -76183.2 edf 288.43 eps 0.0000 iteration 36"
#> [37] "AICc 152943.8 logPost -76982.7 logLik -76183.2 edf 288.43 eps 0.0000 iteration 36"
#> [38] "elapsed time: 84.64min"
#> [39] "Starting the sampler..."
#> [40] "Starting the sampler..."
#> [41] "Starting the sampler..."
#> [42] "Starting the sampler..."
#> [43] ""
#> [44] "| | 0% 1184.51min"
#> [45] "| | 0% 1184.31min"
#> [46] "| | 0% 1187.11min"
#> [47] "| | 0% 1188.33min"
#> [48] "|* | 5% 1105.96min 58.21min"
#> [49] "|* | 5% 1107.94min 58.31min"
#> [50] "|* | 5% 1110.38min 58.44min"
#> [51] "|* | 5% 1110.40min 58.44min"
#> [52] "|** | 10% 1050.73min 116.75min"
#> [53] "|** | 10% 1051.22min 116.80min"
#> [54] "|** | 10% 1051.57min 116.84min"
#> [55] "|** | 10% 1053.08min 117.01min"
#> [56] "|*** | 15% 992.02min 175.06min"
#> [57] "|*** | 15% 992.10min 175.08min"
#> [58] "|*** | 15% 992.46min 175.14min"
#> [59] "|*** | 15% 993.36min 175.30min"
#> [60] "|**** | 20% 933.55min 233.39min"
#> [61] "|**** | 20% 933.64min 233.41min"
#> [62] "|**** | 20% 933.86min 233.47min"
#> [63] "|**** | 20% 934.14min 233.53min"
#> [64] "|***** | 25% 874.85min 291.62min"
#> [65] "|***** | 25% 875.22min 291.74min"
#> [66] "|***** | 25% 875.27min 291.76min"
#> [67] "|***** | 25% 875.78min 291.93min"
#> [68] "|****** | 30% 816.34min 349.86min"
#> [69] "|****** | 30% 816.85min 350.08min"
#> [70] "|****** | 30% 817.05min 350.16min"
#> [71] "|****** | 30% 817.38min 350.31min"
#> [72] "|******* | 35% 758.03min 408.17min"
#> [73] "|******* | 35% 758.37min 408.35min"
#> [74] "|******* | 35% 758.88min 408.63min"
#> [75] "|******* | 35% 759.12min 408.76min"
#> [76] "|******** | 40% 699.84min 466.56min"
#> [77] "|******** | 40% 699.93min 466.62min"
#> [78] "|******** | 40% 700.53min 467.02min"
#> [79] "|******** | 40% 700.73min 467.16min"
#> [80] "|********* | 45% 641.68min 525.01min"
#> [81] "|********* | 45% 641.70min 525.03min"
#> [82] "|********* | 45% 642.09min 525.34min"
#> [83] "|********* | 45% 642.23min 525.46min"
#> [84] "|********** | 50% 583.28min 583.28min"
#> [85] "|********** | 50% 583.37min 583.37min"
#> [86] "|********** | 50% 583.71min 583.71min"
#> [87] "|********** | 50% 583.87min 583.87min"
#> [88] "|*********** | 55% 524.95min 641.61min"
#> [89] "|*********** | 55% 525.03min 641.70min"
#> [90] "|*********** | 55% 525.31min 642.04min"
#> [91] "|*********** | 55% 525.54min 642.32min"
#> [92] "|************ | 60% 470.47min 705.70min"
#> [93] "|************ | 60% 470.64min 705.97min"
#> [94] "|************ | 60% 470.78min 706.17min"
#> [95] "|************ | 60% 470.91min 706.36min"
#> [96] "|************* | 65% 419.01min 778.17min"
#> [97] "|************* | 65% 419.43min 778.94min"
#> [98] "|************* | 65% 419.49min 779.05min"
#> [99] "|************* | 65% 419.57min 779.20min"
#> [100] "|************** | 70% 358.51min 836.52min"
#> [101] "|************** | 70% 358.80min 837.21min"
#> [102] "|************** | 70% 358.92min 837.48min"
#> [103] "|************** | 70% 358.99min 837.65min"
#> [104] "|*************** | 75% 298.24min 894.72min"
#> [105] "|*************** | 75% 298.43min 895.30min"
#> [106] "|*************** | 75% 298.58min 895.75min"
#> [107] "|*************** | 75% 298.62min 895.85min"
#> [108] "|**************** | 80% 238.26min 953.06min"
#> [109] "|**************** | 80% 238.41min 953.64min"
#> [110] "|**************** | 80% 238.57min 954.28min"
#> [111] "|**************** | 80% 238.59min 954.38min"
#> [112] "|***************** | 85% 178.48min 1011.40min"
#> [113] "|***************** | 85% 178.57min 1011.87min"
#> [114] "|***************** | 85% 178.66min 1012.39min"
#> [115] "|***************** | 85% 178.67min 1012.49min"
#> [116] "|****************** | 90% 118.86min 1069.73min"
#> [117] "|****************** | 90% 118.90min 1070.12min"
#> [118] "|****************** | 90% 118.95min 1070.53min"
#> [119] "|****************** | 90% 118.97min 1070.76min"
#> [120] "|******************* | 95% 59.37min 1128.00min"
#> [121] "|******************* | 95% 59.39min 1128.42min"
#> [122] "|******************* | 95% 59.40min 1128.60min"
#> [123] "|******************* | 95% 59.42min 1128.93min"
#> [124] "|********************| 100% 0.00sec 1186.16min"
#> [125] ""
#> [126] "|********************| 100% 0.00sec 1186.58min"
#> [127] ""
#> [128] "|********************| 100% 0.00sec 1186.72min"
#> [129] ""
#> [130] "|********************| 100% 0.00sec 1187.06min"
system.time(saveRDS(bamlss_model, file = path_modelled_data))
#> user system elapsed
#> 36.730 0.224 36.959
saveRDS(form, file = path_modelled_form)
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 290365.955 132.543 76749.751