Discrete: 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-06-discrete.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,
n.iter = 1000, burnin = 0, cores = 4, combine = FALSE, light = TRUE
)
sink()
}
readLines(path_modelled_sink)
#> [1] "AICc 286510.1 logPost -145386. logLik -143246. edf 8.1519 eps 0.0389 iteration 1"
#> [2] "AICc 285231.1 logPost -143053. logLik -142605. edf 10.148 eps 0.0068 iteration 2"
#> [3] "AICc 277146.4 logPost -140253. logLik -138549. edf 23.874 eps 0.0275 iteration 3"
#> [4] "AICc 269103.5 logPost -135548. logLik -134505. edf 46.244 eps 0.0360 iteration 4"
#> [5] "AICc 268637.0 logPost -134697. logLik -134265. edf 52.708 eps 0.0087 iteration 5"
#> [6] "AICc 268628.3 logPost -134649. logLik -134259. edf 54.975 eps 0.0006 iteration 6"
#> [7] "AICc 268628.3 logPost -134649. logLik -134259. edf 55.008 eps 0.0000 iteration 7"
#> [8] "AICc 268628.3 logPost -134649. logLik -134259. edf 55.008 eps 0.0000 iteration 7"
#> [9] "elapsed time: 1.81sec"
#> [10] "Starting the sampler..."
#> [11] "Starting the sampler...Starting the sampler..."
#> [12] ""
#> [13] "Starting the sampler..."
#> [14] ""
#> [15] "| "
#> [16] " | 0% 1.73min"
#> [17] "| | | 0% 1.73min| 0% 1.73min"
#> [18] "| | 0% 1.72min"
#> [19] ""
#> [20] ""
#> [21] "|* | 5%|* | 5%|* | 5% 1.18min 1.18min 1.18min 3.74sec 3.73sec 3.73sec"
#> [22] "|* | 5% 1.18min 3.73sec"
#> [23] "|** | 10% 1.01min 6.71sec"
#> [24] ""
#> [25] "|** | 10% 1.01min 6.72sec|** | 10% 1.01min 6.72sec"
#> [26] "|** | 10% 1.01min 6.72sec"
#> [27] ""
#> [28] "|*** | 15% 55.10sec 9.72sec|*** | 15% 55.07sec 9.72sec"
#> [29] "|*** | 15% 55.11sec 9.73sec"
#> [30] "|*** | 15% 55.20sec 9.74sec"
#> [31] "|**** | 20% 51.79sec 12.95sec"
#> [32] ""
#> [33] "|**** | 20% 51.82sec 12.95sec|**** | 20% 51.83sec 12.96sec"
#> [34] "|**** | 20% 51.89sec 12.97sec"
#> [35] "|***** | 25% 47.79sec 15.93sec"
#> [36] "|***** | 25% 47.79sec 15.93sec"
#> [37] "|***** | 25% 47.90sec 15.97sec"
#> [38] "|***** | 25% 48.12sec 16.04sec"
#> [39] "|****** | 30% 44.24sec 18.96sec"
#> [40] "|****** | 30% 44.98sec 19.27sec"
#> [41] "|****** | 30% 45.10sec 19.33sec"
#> [42] "|****** | 30% 45.41sec 19.46sec"
#> [43] "|******* | 35% 41.40sec 22.29sec"
#> [44] "|******* | 35% 41.51sec 22.35sec"
#> [45] "|******* | 35% 41.57sec 22.38sec"
#> [46] "|******* | 35% 41.79sec 22.50sec"
#> [47] "|******** | 40% 38.19sec 25.46sec"
#> [48] "|******** | 40% 38.32sec 25.55sec"
#> [49] "|******** | 40% 38.43sec 25.62sec"
#> [50] "|******** | 40% 38.67sec 25.78sec"
#> [51] "|********* | 45% 35.26sec 28.85sec"
#> [52] "|********* | 45% 35.38sec 28.95sec"
#> [53] "|********* | 45% 35.40sec 28.96sec"
#> [54] "|********* | 45% 35.47sec 29.02sec"
#> [55] "|********** | 50% 31.94sec 31.94sec"
#> [56] "|********** | 50% 32.02sec 32.02sec"
#> [57] "|********** | 50% 32.06sec 32.06sec"
#> [58] "|********** | 50% 32.08sec 32.08sec"
#> [59] "|*********** | 55% 28.65sec 35.02sec"
#> [60] "|*********** | 55% 28.94sec 35.37sec"
#> [61] "|*********** | 55% 28.98sec 35.42sec"
#> [62] "|*********** | 55% 28.99sec 35.43sec"
#> [63] "|************ | 60% 25.67sec 38.51sec"
#> [64] ""
#> [65] "|************ | 60% 25.69sec 38.53sec|************ | 60% 25.68sec 38.52sec"
#> [66] "|************ | 60% 25.69sec 38.54sec"
#> [67] "|************* | 65% 22.37sec 41.54sec"
#> [68] "|************* | 65% 22.38sec 41.56sec"
#> [69] "|************* | 65% 22.52sec 41.83sec"
#> [70] "|************* | 65% 22.55sec 41.89sec"
#> [71] "|************** | 70% 19.10sec 44.56sec"
#> [72] "|************** | 70% 19.19sec 44.78sec"
#> [73] "|************** | 70% 19.20sec 44.80sec"
#> [74] "|************** | 70% 19.22sec 44.85sec"
#> [75] ""
#> [76] "|*************** | 75%|*************** | 75% 15.94sec15.94sec 47.81sec47.81sec"
#> [77] "|*************** | 75% 15.94sec 47.83sec"
#> [78] "|*************** | 75% 16.06sec 48.17sec"
#> [79] "|**************** | 80% 12.70sec 50.81sec"
#> [80] "|**************** | 80% 12.76sec 51.04sec"
#> [81] "|**************** | 80% 12.76sec 51.04sec"
#> [82] "|**************** | 80% 12.79sec 51.16sec"
#> [83] "|***************** | 85% 9.54sec 54.03sec"
#> [84] "|***************** | 85% 9.55sec 54.09sec"
#> [85] ""
#> [86] "|***************** | 85% 9.56sec 54.15sec|***************** | 85% 9.55sec 54.14sec"
#> [87] "|****************** | 90% 6.33sec 57.00sec"
#> [88] "|****************** | 90% 6.35sec 57.12sec"
#> [89] "|****************** | 90% 6.38sec 57.38sec"
#> [90] "|****************** | 90% 6.38sec 57.40sec"
#> [91] "|******************* | 95% 3.18sec 1.01min"
#> [92] "|******************* | 95% 3.18sec 1.01min"
#> [93] ""
#> [94] "|******************* | 95%|******************* | 95% 3.18sec 3.18sec 1.01min 1.01min"
#> [95] "|********************| 100% 0.00sec 1.06min"
#> [96] ""
#> [97] "|********************| 100% 0.00sec 1.06min"
#> [98] ""
#> [99] "|********************| 100% 0.00sec 1.06min"
#> [100] ""
#> [101] "|********************| 100% 0.00sec 1.06min"
system.time(saveRDS(bamlss_model, file = path_modelled_data))
#> user system elapsed
#> 0.291 0.008 0.299
saveRDS(form, file = path_modelled_form)
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 261.837 1.108 69.821