Full model: 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-10-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 = 3000, 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.59min"
#> [39] "Starting the sampler..."
#> [40] "Starting the sampler..."
#> [41] "Starting the sampler..."
#> [42] "Starting the sampler..."
#> [43] ""
#> [44] "| | 0% 352.45min"
#> [45] "| | 0% 352.02min"
#> [46] "| | 0% 353.28min"
#> [47] "| | 0% 354.64min"
#> [48] "|* | 5% 330.41min 17.39min"
#> [49] "|* | 5% 330.66min 17.40min"
#> [50] "|* | 5% 331.39min 17.44min"
#> [51] "|* | 5% 332.72min 17.51min"
#> [52] "|** | 10% 312.86min 34.76min"
#> [53] "|** | 10% 313.18min 34.80min"
#> [54] "|** | 10% 313.72min 34.86min"
#> [55] "|** | 10% 315.14min 35.02min"
#> [56] "|*** | 15% 295.39min 52.13min"
#> [57] "|*** | 15% 295.75min 52.19min"
#> [58] "|*** | 15% 296.21min 52.27min"
#> [59] "|*** | 15% 297.59min 52.52min"
#> [60] "|**** | 20% 278.04min 69.51min"
#> [61] "|**** | 20% 278.45min 69.61min"
#> [62] "|**** | 20% 278.82min 69.70min"
#> [63] "|**** | 20% 279.95min 69.99min"
#> [64] "|***** | 25% 260.70min 86.90min"
#> [65] "|***** | 25% 261.16min 87.05min"
#> [66] "|***** | 25% 261.37min 87.12min"
#> [67] "|***** | 25% 262.19min 87.40min"
#> [68] "|****** | 30% 243.37min 104.30min"
#> [69] "|****** | 30% 243.85min 104.51min"
#> [70] "|****** | 30% 243.92min 104.54min"
#> [71] "|****** | 30% 244.53min 104.80min"
#> [72] "|******* | 35% 226.00min 121.69min"
#> [73] "|******* | 35% 226.48min 121.95min"
#> [74] "|******* | 35% 226.50min 121.96min"
#> [75] "|******* | 35% 226.95min 122.20min"
#> [76] "|******** | 40% 208.62min 139.08min"
#> [77] "|******** | 40% 209.07min 139.38min"
#> [78] "|******** | 40% 209.09min 139.39min"
#> [79] "|******** | 40% 209.39min 139.59min"
#> [80] "|********* | 45% 191.24min 156.47min"
#> [81] "|********* | 45% 191.65min 156.80min"
#> [82] "|********* | 45% 191.70min 156.85min"
#> [83] "|********* | 45% 191.90min 157.01min"
#> [84] "|********** | 50% 173.85min 173.85min"
#> [85] "|********** | 50% 174.22min 174.22min"
#> [86] "|********** | 50% 174.22min 174.22min"
#> [87] "|********** | 50% 174.48min 174.48min"
#> [88] "|*********** | 55% 156.47min 191.24min"
#> [89] "|*********** | 55% 156.77min 191.61min"
#> [90] "|*********** | 55% 156.78min 191.62min"
#> [91] "|*********** | 55% 157.08min 191.98min"
#> [92] "|************ | 60% 139.09min 208.63min"
#> [93] "|************ | 60% 139.32min 208.98min"
#> [94] "|************ | 60% 139.35min 209.03min"
#> [95] "|************ | 60% 139.65min 209.47min"
#> [96] "|************* | 65% 121.72min 226.05min"
#> [97] "|************* | 65% 121.88min 226.35min"
#> [98] "|************* | 65% 121.93min 226.44min"
#> [99] "|************* | 65% 122.21min 226.97min"
#> [100] "|************** | 70% 104.35min 243.48min"
#> [101] "|************** | 70% 104.44min 243.70min"
#> [102] "|************** | 70% 104.49min 243.82min"
#> [103] "|************** | 70% 104.77min 244.46min"
#> [104] "|*************** | 75% 86.97min 260.91min"
#> [105] "|*************** | 75% 87.02min 261.06min"
#> [106] "|*************** | 75% 87.07min 261.22min"
#> [107] "|*************** | 75% 87.32min 261.96min"
#> [108] "|**************** | 80% 69.58min 278.33min"
#> [109] "|**************** | 80% 69.60min 278.41min"
#> [110] "|**************** | 80% 69.65min 278.60min"
#> [111] "|**************** | 80% 69.86min 279.45min"
#> [112] "|***************** | 85% 52.20min 295.79min"
#> [113] "|***************** | 85% 52.20min 295.82min"
#> [114] "|***************** | 85% 52.24min 296.04min"
#> [115] "|***************** | 85% 52.41min 296.98min"
#> [116] "|****************** | 90% 34.81min 313.25min"
#> [117] "|****************** | 90% 34.81min 313.27min"
#> [118] "|****************** | 90% 34.83min 313.48min"
#> [119] "|****************** | 90% 34.95min 314.54min"
#> [120] "|******************* | 95% 17.41min 330.70min"
#> [121] "|******************* | 95% 17.41min 330.81min"
#> [122] "|******************* | 95% 17.42min 330.97min"
#> [123] "|******************* | 95% 17.48min 332.12min"
#> [124] "|********************| 100% 0.00sec 348.17min"
#> [125] ""
#> [126] "|********************| 100% 0.00sec 348.25min"
#> [127] ""
#> [128] "|********************| 100% 0.00sec 348.46min"
#> [129] ""
#> [130] "|********************| 100% 0.00sec 349.52min"
system.time(saveRDS(bamlss_model, file = path_modelled_data))
#> user system elapsed
#> 23.693 0.076 23.770
saveRDS(form, file = path_modelled_form)
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 89365.974 55.617 26481.259