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-04-inter-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)
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 285998.8 logPost -163704. logLik -142989. edf 9.5175 eps 0.0392 iteration 1"
#> [2] "AICc 280893.6 logPost -141836. logLik -140424. edf 22.231 eps 0.0214 iteration 2"
#> [3] "AICc 271838.7 logPost -137318. logLik -135875. edf 43.830 eps 0.0358 iteration 3"
#> [4] "AICc 268758.8 logPost -134989. logLik -134329. edf 50.228 eps 0.0199 iteration 4"
#> [5] "AICc 268607.3 logPost -134664. logLik -134250. edf 53.378 eps 0.0030 iteration 5"
#> [6] "AICc 268602.2 logPost -134635. logLik -134245. edf 55.096 eps 0.0003 iteration 6"
#> [7] "AICc 268602.2 logPost -134635. logLik -134245. edf 55.098 eps 0.0000 iteration 7"
#> [8] "AICc 268602.2 logPost -134635. logLik -134245. edf 55.098 eps 0.0000 iteration 7"
#> [9] "elapsed time: 1.44sec"
#> [10] "Starting the sampler..."
#> [11] "Starting the sampler...Starting the sampler..."
#> [12] ""
#> [13] "Starting the sampler..."
#> [14] ""
#> [15] "| | 0% 41.78sec"
#> [16] ""
#> [17] "| "
#> [18] " | 0% 42.17sec| | 0% 41.78sec| | 0% 42.17sec"
#> [19] "|* | 5%"
#> [20] " 43.24sec 2.28sec|* | 5% 43.97sec 2.31sec"
#> [21] "|* | 5% 44.56sec 2.35sec"
#> [22] "|* | 5% 44.71sec 2.35sec"
#> [23] "|** | 10% 37.78sec 4.20sec"
#> [24] "|** | 10% 37.67sec 4.19sec"
#> [25] "|** | 10% 40.58sec 4.51sec"
#> [26] "|** | 10% 40.63sec 4.51sec"
#> [27] "|*** | 15% 35.59sec 6.28sec"
#> [28] "|*** | 15% 35.93sec 6.34sec"
#> [29] "|*** | 15% 36.78sec 6.49sec"
#> [30] "|*** | 15% 36.82sec 6.50sec"
#> [31] "|**** | 20% 32.74sec 8.19sec"
#> [32] "|**** | 20% 32.85sec 8.21sec"
#> [33] "|**** | 20% 34.64sec 8.66sec"
#> [34] "|**** | 20% 34.79sec 8.70sec"
#> [35] "|***** | 25% 30.87sec 10.29sec"
#> [36] "|***** | 25% 31.04sec 10.35sec"
#> [37] "|***** | 25% 32.56sec 10.85sec"
#> [38] "|***** | 25% 32.72sec 10.91sec"
#> [39] "|****** | 30% 28.33sec 12.14sec"
#> [40] "|****** | 30% 28.40sec 12.17sec"
#> [41] "|****** | 30% "
#> [42] "29.79sec 12.77sec|****** | 30% 29.89sec 12.81sec"
#> [43] "|******* | 35% 26.29sec 14.16sec"
#> [44] "|******* | 35% 26.40sec 14.22sec"
#> [45] "|******* | 35% 27.59sec 14.86sec"
#> [46] "|******* | 35% 27.68sec 14.91sec"
#> [47] "|******** | 40% 23.94sec 15.96sec"
#> [48] "|******** | 40% 24.02sec 16.02sec"
#> [49] "|******** | 40% 25.07sec 16.72sec"
#> [50] "|******** | 40% 25.52sec 17.01sec"
#> [51] "|********* | 45% 22.03sec 18.03sec"
#> [52] "|********* | 45% 22.16sec 18.13sec"
#> [53] "|********* | 45% 22.93sec 18.76sec"
#> [54] "|********* | 45% 23.02sec 18.83sec"
#> [55] "|********** | 50% 19.82sec 19.82sec"
#> [56] "|********** | 50% 19.90sec 19.90sec"
#> [57] "|********** | 50% 20.57sec 20.57sec"
#> [58] "|********** | 50% 20.64sec 20.64sec"
#> [59] "|*********** | 55% 17.73sec 21.68sec"
#> [60] "|*********** | 55% 17.99sec 21.98sec"
#> [61] "|*********** | 55% 18.54sec 22.66sec"
#> [62] "|*********** | 55% 18.57sec 22.70sec"
#> [63] "|************ | 60% 15.82sec 23.73sec"
#> [64] "|************ | 60% 15.86sec 23.79sec"
#> [65] "|************ | 60% 16.32sec 24.48sec"
#> [66] "|************ | 60% 16.35sec 24.53sec"
#> [67] "|************* | 65% 13.76sec 25.55sec"
#> [68] "|************* | 65% 13.92sec 25.86sec"
#> [69] "|************* | 65% 14.30sec 26.56sec"
#> [70] "|************* | 65% 14.32sec 26.59sec"
#> [71] "|************** | 70% 11.74sec 27.40sec"
#> [72] "|************** | 70% 11.86sec 27.68sec"
#> [73] "|************** | 70% 12.17sec 28.40sec"
#> [74] "|************** | 70% 12.18sec 28.41sec"
#> [75] "|*************** | 75% 9.80sec 29.41sec"
#> [76] "|*************** | 75% 9.83sec 29.49sec"
#> [77] "|*************** | 75% 10.07sec 30.20sec"
#> [78] "|*************** | 75% 10.14sec 30.42sec"
#> [79] "|**************** | 80% 7.88sec 31.50sec"
#> [80] "|**************** | 80% 7.89sec 31.54sec"
#> [81] "|**************** | 80% 8.07sec 32.27sec"
#> [82] "|**************** | 80% 8.07sec 32.29sec"
#> [83] "|***************** | 85% 5.88sec 33.29sec"
#> [84] "|***************** | 85% 5.89sec 33.37sec"
#> [85] "|***************** | 85% 6.02sec 34.09sec"
#> [86] "|***************** | 85% 6.05sec 34.29sec"
#> [87] "|****************** | 90% 3.90sec 35.10sec"
#> [88] "|****************** | 90% 3.91sec 35.17sec"
#> [89] "|****************** | 90% 4.02sec 36.14sec"
#> [90] "|****************** | 90% 4.02sec 36.18sec"
#> [91] "|******************* | 95% 1.96sec 37.16sec"
#> [92] "|******************* | 95% 1.96sec 37.25sec"
#> [93] "|******************* | 95% 2.00sec 38.01sec"
#> [94] "|******************* | 95% 2.01sec 38.19sec"
#> [95] "|********************| 100% 0.00sec 38.99sec"
#> [96] ""
#> [97] "|********************| 100% 0.00sec 39.06sec"
#> [98] ""
#> [99] "|********************| 100% 0.00sec 39.75sec"
#> [100] ""
#> [101] "|********************| 100% 0.00sec 39.77sec"
system.time(saveRDS(bamlss_model, file = path_modelled_data))
#> user system elapsed
#> 0.204 0.004 0.208
saveRDS(form, file = path_modelled_form)
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 164.048 1.011 45.468