Discrete binning only smooths: 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-09-discrete-bin-age.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(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 317041.7 logPost -270258. logLik -158512. edf 8.7495 eps 0.4705 iteration 1"
#> [2] "AICc 302009.1 logPost -156229. logLik -150995. edf 8.9683 eps 0.1038 iteration 2"
#> [3] "AICc 291838.0 logPost -146780. logLik -145908. edf 10.767 eps 0.0552 iteration 3"
#> [4] "AICc 286793.8 logPost -143774. logLik -143383. edf 13.570 eps 0.0356 iteration 4"
#> [5] "AICc 285488.7 logPost -142950. logLik -142728. edf 15.506 eps 0.0167 iteration 5"
#> [6] "AICc 285131.7 logPost -142712. logLik -142549. edf 15.949 eps 0.0033 iteration 6"
#> [7] "AICc 284834.3 logPost -142563. logLik -142401. edf 15.988 eps 0.0012 iteration 7"
#> [8] "AICc 284563.6 logPost -142427. logLik -142265. edf 15.987 eps 0.0011 iteration 8"
#> [9] "AICc 284317.2 logPost -142304. logLik -142142. edf 15.986 eps 0.0019 iteration 9"
#> [10] "AICc 284093.3 logPost -142191. logLik -142030. edf 15.985 eps 0.0017 iteration 10"
#> [11] "AICc 283890.0 logPost -142089. logLik -141929. edf 15.984 eps 0.0008 iteration 11"
#> [12] "AICc 283705.6 logPost -141997. logLik -141836. edf 15.982 eps 0.0011 iteration 12"
#> [13] "AICc 283538.5 logPost -141913. logLik -141753. edf 15.980 eps 0.0007 iteration 13"
#> [14] "AICc 283387.3 logPost -141836. logLik -141677. edf 15.979 eps 0.0006 iteration 14"
#> [15] "AICc 283250.4 logPost -141768. logLik -141609. edf 15.977 eps 0.0006 iteration 15"
#> [16] "AICc 283126.7 logPost -141705. logLik -141547. edf 15.975 eps 0.0007 iteration 16"
#> [17] "AICc 283014.9 logPost -141649. logLik -141491. edf 15.972 eps 0.0006 iteration 17"
#> [18] "AICc 282913.9 logPost -141598. logLik -141440. edf 15.970 eps 0.0006 iteration 18"
#> [19] "AICc 282822.8 logPost -141552. logLik -141395. edf 15.967 eps 0.0004 iteration 19"
#> [20] "AICc 282740.6 logPost -141510. logLik -141354. edf 15.964 eps 0.0005 iteration 20"
#> [21] "AICc 282666.5 logPost -141473. logLik -141317. edf 15.961 eps 0.0004 iteration 21"
#> [22] "AICc 282599.6 logPost -141439. logLik -141283. edf 15.957 eps 0.0003 iteration 22"
#> [23] "AICc 282539.4 logPost -141409. logLik -141253. edf 15.954 eps 0.0003 iteration 23"
#> [24] "AICc 282485.2 logPost -141381. logLik -141226. edf 15.949 eps 0.0003 iteration 24"
#> [25] "AICc 282436.4 logPost -141356. logLik -141202. edf 15.945 eps 0.0008 iteration 25"
#> [26] "AICc 282392.4 logPost -141334. logLik -141180. edf 15.940 eps 0.0002 iteration 26"
#> [27] "AICc 282352.9 logPost -141314. logLik -141160. edf 15.935 eps 0.0002 iteration 27"
#> [28] "AICc 282317.3 logPost -141295. logLik -141142. edf 15.929 eps 0.0002 iteration 28"
#> [29] "AICc 282285.2 logPost -141279. logLik -141126. edf 15.923 eps 0.0002 iteration 29"
#> [30] "AICc 282256.4 logPost -141264. logLik -141112. edf 15.916 eps 0.0001 iteration 30"
#> [31] "AICc 282230.5 logPost -141251. logLik -141099. edf 15.909 eps 0.0002 iteration 31"
#> [32] "AICc 282207.2 logPost -141239. logLik -141087. edf 15.901 eps 0.0004 iteration 32"
#> [33] "AICc 282186.2 logPost -141228. logLik -141077. edf 15.893 eps 0.0002 iteration 33"
#> [34] "AICc 282167.4 logPost -141218. logLik -141067. edf 15.884 eps 0.0001 iteration 34"
#> [35] "AICc 282150.5 logPost -141209. logLik -141059. edf 15.875 eps 0.0001 iteration 35"
#> [36] "AICc 282135.2 logPost -141201. logLik -141051. edf 15.865 eps 0.0001 iteration 36"
#> [37] "AICc 282121.6 logPost -141194. logLik -141044. edf 15.854 eps 0.0001 iteration 37"
#> [38] "AICc 282109.3 logPost -141187. logLik -141038. edf 15.843 eps 0.0001 iteration 38"
#> [39] "AICc 282098.2 logPost -141182. logLik -141033. edf 15.831 eps 0.0001 iteration 39"
#> [40] "AICc 282088.3 logPost -141176. logLik -141028. edf 15.818 eps 0.0000 iteration 40"
#> [41] "AICc 282088.3 logPost -141176. logLik -141028. edf 15.818 eps 0.0000 iteration 40"
#> [42] "elapsed time: 3.29sec"
#> [43] "Starting the sampler...Starting the sampler...Starting the sampler...Starting the sampler..."
#> [44] ""
#> [45] ""
#> [46] ""
#> [47] ""
#> [48] ""
#> [49] ""
#> [50] ""
#> [51] "|| | 0% | 0% 25.15sec25.15sec| | | 0% 25.24sec | 0% 25.24sec"
#> [52] ""
#> [53] ""
#> [54] ""
#> [55] "|* | 5%|* | 5%|* | 5%|* | 5% 25.16sec25.16sec25.16sec25.16sec 1.32sec 1.32sec 1.32sec 1.32sec"
#> [56] "|** | 10% 23.16sec 2.57sec"
#> [57] "|** | 10% 26.41sec 2.93sec"
#> [58] "|** | 10% 26.51sec 2.95sec"
#> [59] "|** | 10% 26.95sec 2.99sec"
#> [60] "|*** | 15% 22.85sec 4.03sec"
#> [61] "|*** | 15% 23.27sec 4.11sec"
#> [62] "|*** | 15% 23.88sec 4.21sec"
#> [63] "|*** | 15% 23.95sec 4.23sec"
#> [64] "|**** | 20% 20.88sec 5.22sec"
#> [65] "|**** | 20% 21.20sec 5.30sec"
#> [66] "|**** | 20% 21.59sec 5.40sec"
#> [67] "|**** | 20% 21.66sec 5.41sec"
#> [68] "|***** | 25% 20.08sec 6.69sec"
#> [69] "|***** | 25% 20.33sec 6.78sec"
#> [70] "|***** | 25% 20.63sec 6.88sec"
#> [71] "|***** | 25% 20.71sec 6.90sec"
#> [72] "|****** | 30% 18.41sec 7.89sec"
#> [73] "|****** | 30% 18.63sec 7.99sec"
#> [74] "|****** | 30% 18.82sec 8.07sec"
#> [75] "|****** | 30% 18.89sec 8.10sec"
#> [76] "|******* | 35% 17.32sec 9.32sec"
#> [77] "|******* | 35% 17.71sec 9.54sec"
#> [78] "|******* | 35% 17.72sec 9.54sec"
#> [79] "|******* | 35% 17.74sec 9.55sec"
#> [80] "|******** | 40% 15.79sec 10.53sec"
#> [81] "|******** | 40% 16.17sec 10.78sec"
#> [82] "|******** | 40% 16.17sec 10.78sec"
#> [83] "|******** | 40% 16.17sec 10.78sec"
#> [84] "|********* | 45% 14.65sec 11.99sec"
#> [85] "|********* | 45% 14.93sec 12.22sec"
#> [86] "|********* | 45% 14.98sec 12.26sec"
#> [87] "|********* | 45% 14.99sec 12.27sec"
#> [88] "|********** | 50% 13.19sec 13.19sec"
#> [89] "|********** | 50% 13.40sec 13.40sec"
#> [90] "|********** | 50% 13.45sec 13.45sec"
#> [91] "|********** | 50% 13.45sec 13.45sec"
#> [92] "|*********** | 55% 11.81sec 14.43sec"
#> [93] "|*********** | 55% 11.98sec 14.65sec"
#> [94] "|*********** | 55% 12.06sec 14.74sec"
#> [95] "|*********** | 55% 12.14sec 14.83sec"
#> [96] "|************ | 60% 10.58sec 15.87sec"
#> [97] "|************ | 60% 10.69sec 16.03sec"
#> [98] "|************ | 60% 10.70sec 16.06sec"
#> [99] "|************ | 60% 10.79sec 16.19sec"
#> [100] "|************* | 65% 9.18sec 17.05sec"
#> [101] "|************* | 65% 9.26sec 17.20sec"
#> [102] "|************* | 65% 9.28sec 17.24sec"
#> [103] "|************* | 65% 9.36sec 17.38sec"
#> [104] "|************** | 70% 7.95sec 18.56sec"
#> [105] "|************** | 70% 8.01sec 18.69sec"
#> [106] "|************** | 70% 8.01sec 18.69sec"
#> [107] "|************** | 70% 8.09sec 18.88sec"
#> [108] "|*************** | 75% 6.60sec 19.79sec"
#> [109] "|*************** | 75% 6.63sec 19.89sec"
#> [110] "|*************** | 75% 6.63sec 19.90sec"
#> [111] "|*************** | 75% 6.71sec 20.12sec"
#> [112] "|**************** | 80% 5.32sec 21.26sec"
#> [113] "|**************** | 80% 5.33sec 21.34sec"
#> [114] "|**************** | 80% 5.34sec 21.35sec"
#> [115] "|**************** | 80% 5.40sec 21.59sec"
#> [116] "|***************** | 85% 3.97sec 22.47sec"
#> [117] "|***************** | 85% 3.98sec 22.56sec"
#> [118] "|***************** | 85% 3.99sec 22.63sec"
#> [119] "|***************** | 85% 4.03sec 22.81sec"
#> [120] "|****************** | 90% 2.66sec 23.97sec"
#> [121] "|****************** | 90% 2.67sec 24.04sec"
#> [122] "|****************** | 90% 2.68sec 24.14sec"
#> [123] "|****************** | 90% 2.70sec 24.30sec"
#> [124] "|******************* | 95% 1.33sec 25.20sec"
#> [125] "|******************* | 95% 1.33sec 25.24sec"
#> [126] "|******************* | 95% 1.33sec 25.35sec"
#> [127] "|******************* | 95% 1.34sec 25.51sec"
#> [128] "|********************| 100% 0.00sec 26.44sec"
#> [129] ""
#> [130] "|********************| 100% 0.00sec 26.67sec"
#> [131] ""
#> [132] "|********************| 100% 0.00sec 26.81sec"
#> [133] ""
#> [134] "|********************| 100% 0.00sec 26.92sec"
system.time(saveRDS(bamlss_model, file = path_modelled_data))
#> user system elapsed
#> 0.108 0.001 0.108
saveRDS(form, file = path_modelled_form)
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 113.902 0.939 33.706