Discrete binning: 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-08-discrete-bin.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_bin)
form <- form_mu
Run the model of interest and save results
{
sink(path_modelled_sink)
bamlss_model <- bamlss(
form, data = bwdata_model, binning = TRUE,
n.iter = 1000, burnin = 0, cores = 4, combine = FALSE, light = TRUE
)
sink()
}
readLines(path_modelled_sink)
#> [1] "AICc 314201.0 logPost -281319. logLik -157090. edf 10.260 eps 0.2655 iteration 1"
#> [2] "AICc 301662.7 logPost -157024. logLik -150818. edf 12.461 eps 0.0958 iteration 2"
#> [3] "AICc 287480.9 logPost -145229. logLik -143703. edf 36.826 eps 0.0634 iteration 3"
#> [4] "AICc 278765.8 logPost -140087. logLik -139330. edf 52.671 eps 0.0478 iteration 4"
#> [5] "AICc 276084.6 logPost -138484. logLik -137986. edf 55.438 eps 0.0205 iteration 5"
#> [6] "AICc 275371.7 logPost -138045. logLik -137629. edf 55.839 eps 0.0058 iteration 6"
#> [7] "AICc 274781.1 logPost -137748. logLik -137334. edf 55.877 eps 0.0026 iteration 7"
#> [8] "AICc 274235.5 logPost -137475. logLik -137061. edf 55.880 eps 0.0018 iteration 8"
#> [9] "AICc 273732.4 logPost -137223. logLik -136810. edf 55.883 eps 0.0018 iteration 9"
#> [10] "AICc 273269.3 logPost -136991. logLik -136578. edf 55.885 eps 0.0017 iteration 10"
#> [11] "AICc 272843.9 logPost -136778. logLik -136365. edf 55.887 eps 0.0015 iteration 11"
#> [12] "AICc 272453.8 logPost -136582. logLik -136170. edf 55.888 eps 0.0016 iteration 12"
#> [13] "AICc 272096.8 logPost -136403. logLik -135992. edf 55.889 eps 0.0015 iteration 13"
#> [14] "AICc 271770.5 logPost -136240. logLik -135829. edf 55.890 eps 0.0011 iteration 14"
#> [15] "AICc 271472.7 logPost -136090. logLik -135680. edf 55.891 eps 0.0010 iteration 15"
#> [16] "AICc 271201.4 logPost -135954. logLik -135544. edf 55.891 eps 0.0009 iteration 16"
#> [17] "AICc 270954.4 logPost -135830. logLik -135421. edf 55.891 eps 0.0009 iteration 17"
#> [18] "AICc 270729.9 logPost -135717. logLik -135308. edf 55.891 eps 0.0009 iteration 18"
#> [19] "AICc 270526.0 logPost -135615. logLik -135206. edf 55.891 eps 0.0007 iteration 19"
#> [20] "AICc 270341.0 logPost -135522. logLik -135114. edf 55.891 eps 0.0008 iteration 20"
#> [21] "AICc 270173.4 logPost -135438. logLik -135030. edf 55.890 eps 0.0006 iteration 21"
#> [22] "AICc 270021.6 logPost -135361. logLik -134954. edf 55.889 eps 0.0009 iteration 22"
#> [23] "AICc 269884.2 logPost -135292. logLik -134886. edf 55.888 eps 0.0005 iteration 23"
#> [24] "AICc 269759.9 logPost -135230. logLik -134823. edf 55.886 eps 0.0007 iteration 24"
#> [25] "AICc 269647.6 logPost -135173. logLik -134767. edf 55.884 eps 0.0005 iteration 25"
#> [26] "AICc 269546.2 logPost -135122. logLik -134717. edf 55.883 eps 0.0004 iteration 26"
#> [27] "AICc 269454.7 logPost -135076. logLik -134671. edf 55.880 eps 0.0008 iteration 27"
#> [28] "AICc 269372.0 logPost -135034. logLik -134630. edf 55.878 eps 0.0287 iteration 28"
#> [29] "AICc 269297.5 logPost -134996. logLik -134592. edf 55.875 eps 0.0003 iteration 29"
#> [30] "AICc 269230.3 logPost -134962. logLik -134559. edf 55.872 eps 0.0003 iteration 30"
#> [31] "AICc 269169.8 logPost -134932. logLik -134528. edf 55.869 eps 0.0003 iteration 31"
#> [32] "AICc 269115.2 logPost -134904. logLik -134501. edf 55.865 eps 0.0003 iteration 32"
#> [33] "AICc 269066.1 logPost -134879. logLik -134477. edf 55.861 eps 0.0003 iteration 33"
#> [34] "AICc 269021.8 logPost -134856. logLik -134454. edf 55.857 eps 0.0002 iteration 34"
#> [35] "AICc 268982.0 logPost -134836. logLik -134434. edf 55.852 eps 0.0002 iteration 35"
#> [36] "AICc 268946.1 logPost -134818. logLik -134417. edf 55.847 eps 0.0002 iteration 36"
#> [37] "AICc 268913.8 logPost -134801. logLik -134400. edf 55.841 eps 0.0002 iteration 37"
#> [38] "AICc 268884.8 logPost -134786. logLik -134386. edf 55.835 eps 0.0001 iteration 38"
#> [39] "AICc 268858.7 logPost -134773. logLik -134373. edf 55.829 eps 0.0001 iteration 39"
#> [40] "AICc 268835.1 logPost -134761. logLik -134361. edf 55.822 eps 0.0001 iteration 40"
#> [41] "AICc 268814.0 logPost -134750. logLik -134351. edf 55.814 eps 0.0001 iteration 41"
#> [42] "AICc 268795.0 logPost -134740. logLik -134341. edf 55.806 eps 0.0001 iteration 42"
#> [43] "AICc 268777.9 logPost -134731. logLik -134333. edf 55.798 eps 0.0001 iteration 43"
#> [44] "AICc 268762.5 logPost -134723. logLik -134325. edf 55.789 eps 0.0001 iteration 44"
#> [45] "AICc 268762.5 logPost -134723. logLik -134325. edf 55.789 eps 0.0001 iteration 44"
#> [46] "elapsed time: 5.81sec"
#> [47] "Starting the sampler..."
#> [48] "Starting the sampler..."
#> [49] "Starting the sampler..."
#> [50] "Starting the sampler..."
#> [51] ""
#> [52] ""
#> [53] "| | | 0% 35.74sec | 0% 36.04sec"
#> [54] "| | 0% 35.74sec"
#> [55] "| | 0% 36.63sec"
#> [56] "|* | 5% 38.85sec 2.04sec"
#> [57] "|* | 5% 39.10sec 2.06sec"
#> [58] "|* | 5% 39.24sec 2.07sec"
#> [59] "|* | 5% 39.12sec 2.06sec"
#> [60] "|** | 10% 36.13sec 4.01sec"
#> [61] "|** | 10% 36.30sec 4.03sec"
#> [62] "|** | 10% 36.46sec 4.05sec"
#> [63] "|** | 10% 36.41sec 4.04sec"
#> [64] "|*** | 15% 32.06sec 5.66sec"
#> [65] "|*** | 15% 32.32sec 5.70sec"
#> [66] "|*** | 15% 32.48sec 5.73sec"
#> [67] "|*** | 15% 32.42sec 5.72sec"
#> [68] "|**** | 20% 30.33sec 7.58sec"
#> [69] "|**** | 20% 30.54sec 7.64sec"
#> [70] "|**** | 20% 30.63sec 7.66sec"
#> [71] "|**** | 20% 30.73sec 7.68sec"
#> [72] "|***** | 25% 27.80sec 9.27sec"
#> [73] "|***** | 25% 28.18sec 9.39sec"
#> [74] "|***** | 25% 28.75sec 9.58sec"
#> [75] "|***** | 25% 28.92sec 9.64sec"
#> [76] "|****** | 30% 26.03sec 11.16sec"
#> [77] "|****** | 30% 26.25sec 11.25sec"
#> [78] "|****** | 30% 26.38sec 11.31sec"
#> [79] "|****** | 30% 26.37sec 11.30sec"
#> [80] "|******* | 35% 24.32sec 13.10sec"
#> [81] "|******* | 35% 24.53sec 13.21sec"
#> [82] "|******* | 35% 24.61sec 13.25sec"
#> [83] "|******* | 35% 24.67sec 13.29sec"
#> [84] "|******** | 40% 22.16sec 14.77sec"
#> [85] "|******** | 40% 22.34sec 14.89sec"
#> [86] "|******** | 40% 22.42sec 14.94sec"
#> [87] "|******** | 40% 22.47sec 14.98sec"
#> [88] "|********* | 45% 20.36sec 16.66sec"
#> [89] "|********* | 45% 20.56sec 16.82sec"
#> [90] "|********* | 45% 20.61sec 16.86sec"
#> [91] "|********* | 45% 20.67sec 16.91sec"
#> [92] "|********** | 50% 18.59sec 18.59sec"
#> [93] "|********** | 50% 18.79sec 18.79sec"
#> [94] "|********** | 50% 18.83sec 18.83sec"
#> [95] "|********** | 50% 18.90sec 18.90sec"
#> [96] "|*********** | 55% 16.61sec 20.31sec"
#> [97] "|*********** | 55% 16.74sec 20.46sec"
#> [98] "|*********** | 55% 16.78sec 20.51sec"
#> [99] "|*********** | 55% 16.83sec 20.58sec"
#> [100] "|************ | 60% 14.80sec 22.20sec"
#> [101] "|************ | 60% 14.91sec 22.37sec"
#> [102] "|************ | 60% 14.95sec 22.43sec"
#> [103] "|************ | 60% 14.99sec 22.49sec"
#> [104] "|************* | 65% 12.97sec 24.08sec"
#> [105] "|************* | 65% 12.98sec 24.11sec"
#> [106] "|************* | 65% 13.00sec 24.14sec"
#> [107] "|************* | 65% 13.04sec 24.21sec"
#> [108] "|************** | 70% 11.05sec 25.78sec"
#> [109] "|************** | 70% 11.13sec 25.97sec"
#> [110] "|************** | 70% 11.15sec 26.02sec"
#> [111] "|************** | 70% 11.18sec 26.09sec"
#> [112] "|*************** | 75% 9.24sec 27.71sec"
#> [113] "|*************** | 75% 9.31sec 27.92sec"
#> [114] "|*************** | 75% 9.32sec 27.97sec"
#> [115] "|*************** | 75% 9.36sec 28.07sec"
#> [116] "|**************** | 80% 7.35sec 29.39sec"
#> [117] "|**************** | 80% 7.40sec 29.60sec"
#> [118] "|**************** | 80% 7.41sec 29.65sec"
#> [119] "|**************** | 80% 7.44sec 29.77sec"
#> [120] "|***************** | 85% 5.53sec 31.33sec"
#> [121] "|***************** | 85% 5.56sec 31.50sec"
#> [122] "|***************** | 85% 5.57sec 31.55sec"
#> [123] "|***************** | 85% 5.59sec 31.67sec"
#> [124] "|****************** | 90% 3.69sec 33.25sec"
#> [125] "|****************** | 90% 3.72sec 33.47sec"
#> [126] "|****************** | 90% 3.72sec 33.52sec"
#> [127] "|****************** | 90% 3.74sec 33.66sec"
#> [128] "|******************* | 95% 1.84sec 34.94sec"
#> [129] "|******************* | 95% 1.85sec 35.14sec"
#> [130] "|******************* | 95% 1.85sec 35.19sec"
#> [131] "|******************* | 95% 1.86sec 35.33sec"
#> [132] "|********************| 100% 0.00sec 36.84sec"
#> [133] ""
#> [134] "|********************| 100% 0.00sec 37.04sec"
#> [135] ""
#> [136] "|********************| 100% 0.00sec 37.08sec"
#> [137] ""
#> [138] "|********************| 100% 0.00sec 37.19sec"
system.time(saveRDS(bamlss_model, file = path_modelled_data))
#> user system elapsed
#> 0.197 0.007 0.205
saveRDS(form, file = path_modelled_form)
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 157.708 1.137 46.570