With intercept: fitting


Load packages, read data and source custom scripts

Paths are defined relative to the git repository location.

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, "bw-00-inter.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_51_test.fst"))

Define formula for our model

form_mu <- born_weight ~ marital_status + race + s(municipality, bs = "re") +
    s(age)
form <- form_mu

Run the model of interest and save results

{
    sink(path_modelled_sink)
    bamlss_model <- bamlss(
        form, data = bwdata_model,
        n.iter = 1000, burnin = 0, cores = 4, combine = FALSE, light = TRUE
    )
    sink()
}
readLines(path_modelled_sink)
#>   [1] "AICc 286510.1 logPost -145383. logLik -143246. edf 8.1512 eps 0.0389 iteration   1"                                                     
#>   [2] "AICc 285278.3 logPost -143064. logLik -142629. edf 10.139 eps 0.0066 iteration   2"                                                     
#>   [3] "AICc 277333.5 logPost -140334. logLik -138642. edf 23.812 eps 0.0270 iteration   3"                                                     
#>   [4] "AICc 269105.4 logPost -135567. logLik -134506. edf 46.186 eps 0.0363 iteration   4"                                                     
#>   [5] "AICc 268609.5 logPost -134685. logLik -134251. edf 53.048 eps 0.0090 iteration   5"                                                     
#>   [6] "AICc 268602.2 logPost -134634. logLik -134245. edf 55.088 eps 0.0007 iteration   6"                                                     
#>   [7] "AICc 268602.2 logPost -134634. logLik -134245. edf 55.096 eps 0.0000 iteration   7"                                                     
#>   [8] "AICc 268602.2 logPost -134634. logLik -134245. edf 55.096 eps 0.0000 iteration   7"                                                     
#>   [9] "elapsed time:  1.69sec"                                                                                                                 
#>  [10] "Starting the sampler...Starting the sampler...Starting the sampler...Starting the sampler..."                                           
#>  [11] ""                                                                                                                                       
#>  [12] ""                                                                                                                                       
#>  [13] ""                                                                                                                                       
#>  [14] ""                                                                                                                                       
#>  [15] ""                                                                                                                                       
#>  [16] "|  "                                                                                                                                    
#>  [17] "          "                                                                                                                             
#>  [18] "        |   0%  1.07min|                    |   0%  1.07min|                |        |   0%   1.07min               |   0%  1.07min"    
#>  [19] "|*                   |   5%  1.10min  3.49sec"                                                                                          
#>  [20] ""                                                                                                                                       
#>  [21] ""                                                                                                                                       
#>  [22] "|*                   |   5%|*                   |   5%|*                   |   5%    1.11min 1.11min 1.11min    3.51sec 3.51sec 3.51sec"
#>  [23] "|**                  |  10% 57.92sec  6.44sec"                                                                                          
#>  [24] "|**                  |  10% 57.96sec  6.44sec"                                                                                          
#>  [25] "|**                  |  10% 58.07sec  6.45sec"                                                                                          
#>  [26] "|**                  |  10% 58.10sec  6.46sec"                                                                                          
#>  [27] ""                                                                                                                                       
#>  [28] "|***                 |  15% 53.27sec  9.40sec|***                 |  15% 53.27sec  9.40sec"                                             
#>  [29] "|***                 |  15% 53.49sec  9.44sec"                                                                                          
#>  [30] "|***                 |  15% 53.49sec  9.44sec"                                                                                          
#>  [31] "|****                |  20% 50.45sec 12.61sec"                                                                                          
#>  [32] "|****                |  20% 50.52sec 12.63sec"                                                                                          
#>  [33] ""                                                                                                                                       
#>  [34] "|****                |  20%|****                |  20%  50.60sec50.60sec  12.65sec12.65sec"                                             
#>  [35] "|*****               |  25% 46.83sec 15.61sec"                                                                                          
#>  [36] "|*****               |  25% 46.89sec 15.63sec"                                                                                          
#>  [37] "|*****               |  25% 46.91sec 15.64sec"                                                                                          
#>  [38] "|*****               |  25% 46.96sec 15.65sec"                                                                                          
#>  [39] ""                                                                                                                                       
#>  [40] "|******              |  30% 43.23sec 18.53sec|******              |  30% 43.23sec 18.53sec"                                             
#>  [41] "|******              |  30% 43.82sec 18.78sec"                                                                                          
#>  [42] "|******              |  30% 43.91sec 18.82sec"                                                                                          
#>  [43] ""                                                                                                                                       
#>  [44] "|*******             |  35% 40.36sec 21.74sec|*******             |  35% 40.36sec 21.74sec"                                             
#>  [45] "|*******             |  35% 40.44sec 21.77sec"                                                                                          
#>  [46] "|*******             |  35% 40.44sec 21.78sec"                                                                                          
#>  [47] "|********            |  40% 37.04sec 24.69sec"                                                                                          
#>  [48] "|********            |  40% 37.05sec 24.70sec"                                                                                          
#>  [49] "|********            |  40% 37.12sec 24.75sec"                                                                                          
#>  [50] "|********            |  40% 37.46sec 24.98sec"                                                                                          
#>  [51] "|*********           |  45% 34.02sec 27.83sec"                                                                                          
#>  [52] "|*********           |  45% 34.03sec 27.84sec"                                                                                          
#>  [53] "|*********           |  45% 34.06sec 27.87sec"                                                                                          
#>  [54] "|*********           |  45% 34.08sec 27.88sec"                                                                                          
#>  [55] ""                                                                                                                                       
#>  [56] "|**********          |  50% 30.81sec 30.81sec|**********          |  50% 30.81sec 30.81sec"                                             
#>  [57] "|**********          |  50% 30.85sec 30.85sec"                                                                                          
#>  [58] "|**********          |  50% 31.11sec 31.11sec"                                                                                          
#>  [59] "|***********         |  55% 27.56sec 33.69sec"                                                                                          
#>  [60] "|***********         |  55% 27.81sec 33.99sec"                                                                                          
#>  [61] "|***********         |  55% 27.85sec 34.03sec"                                                                                          
#>  [62] "|***********         |  55% 27.91sec 34.12sec"                                                                                          
#>  [63] "|************        |  60% 24.58sec 36.87sec"                                                                                          
#>  [64] "|************        |  60% 24.62sec 36.93sec"                                                                                          
#>  [65] "|************        |  60% 24.63sec 36.95sec"                                                                                          
#>  [66] "|************        |  60% 24.69sec 37.04sec"                                                                                          
#>  [67] "|*************       |  65% 21.42sec 39.78sec"                                                                                          
#>  [68] "|*************       |  65% 21.45sec 39.84sec"                                                                                          
#>  [69] "|*************       |  65% 21.51sec 39.95sec"                                                                                          
#>  [70] "|*************       |  65% 21.60sec 40.11sec"                                                                                          
#>  [71] "|**************      |  70% 18.41sec 42.97sec"                                                                                          
#>  [72] "|**************      |  70% 18.44sec 43.03sec"                                                                                          
#>  [73] "|**************      |  70% 18.46sec 43.06sec"                                                                                          
#>  [74] "|**************      |  70% 18.49sec 43.14sec"                                                                                          
#>  [75] "|***************     |  75% 15.29sec 45.86sec"                                                                                          
#>  [76] "|***************     |  75% 15.30sec 45.91sec"                                                                                          
#>  [77] "|***************     |  75% 15.32sec 45.97sec"                                                                                          
#>  [78] "|***************     |  75% 15.34sec 46.02sec"                                                                                          
#>  [79] "|****************    |  80% 12.20sec 48.80sec"                                                                                          
#>  [80] "|****************    |  80% 12.25sec 49.01sec"                                                                                          
#>  [81] "|****************    |  80% 12.28sec 49.11sec"                                                                                          
#>  [82] "|****************    |  80% 12.29sec 49.18sec"                                                                                          
#>  [83] "|*****************   |  85%  9.16sec 51.90sec"                                                                                          
#>  [84] "|*****************   |  85%  9.17sec 51.95sec"                                                                                          
#>  [85] "|*****************   |  85%  9.18sec 52.01sec"                                                                                          
#>  [86] "|*****************   |  85%  9.19sec 52.07sec"                                                                                          
#>  [87] "|******************  |  90%  6.10sec 54.87sec"                                                                                          
#>  [88] "|******************  |  90%  6.12sec 55.11sec"                                                                                          
#>  [89] "|******************  |  90%  6.13sec 55.21sec"                                                                                          
#>  [90] "|******************  |  90%  6.14sec 55.28sec"                                                                                          
#>  [91] "|******************* |  95%  3.05sec 57.99sec"                                                                                          
#>  [92] "|******************* |  95%  3.05sec 58.04sec"                                                                                          
#>  [93] "|******************* |  95%  3.06sec 58.11sec"                                                                                          
#>  [94] "|******************* |  95%  3.06sec 58.15sec"                                                                                          
#>  [95] "|********************| 100%  0.00sec  1.02min"                                                                                          
#>  [96] ""                                                                                                                                       
#>  [97] "|********************| 100%  0.00sec  1.02min"                                                                                          
#>  [98] ""                                                                                                                                       
#>  [99] "|********************| 100%  0.00sec  1.02min"                                                                                          
#> [100] ""                                                                                                                                       
#> [101] "|********************| 100%  0.00sec  1.02min"
system.time(saveRDS(bamlss_model, file = path_modelled_data))
#>    user  system elapsed 
#>   0.301   0.004   0.311
saveRDS(form, file = path_modelled_form)

Time to execute the task

Only useful when executed with Rscript.

proc.time()
#>    user  system elapsed 
#> 254.187   1.165  68.185