Only covariates with binning: fitting
Birthweight model including covariates at municipality level with binning option.
Load packages, read data and source custom scripts
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-muni-01-covs-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_41_model.fst"))
Define formula for our model
form_sigma <- sigma ~ 1
form_mu <- born_weight ~ s(remoteness) + s(prop_tap_toilet)
form <- list(form_mu, form_sigma)
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 4873071. logPost -2582651 logLik -2436526 edf 9.3467 eps 0.1928 iteration 1"
#> [2] "AICc 4598169. logPost -2299275 logLik -2299074 edf 9.8623 eps 0.1272 iteration 2"
#> [3] "AICc 4486998. logPost -2243656 logLik -2243482 edf 16.524 eps 0.0336 iteration 3"
#> [4] "AICc 4459259. logPost -2229780 logLik -2229610 edf 19.637 eps 0.0176 iteration 4"
#> [5] "AICc 4457573. logPost -2228938 logLik -2228767 edf 19.775 eps 0.0049 iteration 5"
#> [6] "AICc 4457465. logPost -2228884 logLik -2228712 edf 19.776 eps 0.0008 iteration 6"
#> [7] "AICc 4457432. logPost -2228867 logLik -2228696 edf 19.763 eps 0.0003 iteration 7"
#> [8] "AICc 4457421. logPost -2228862 logLik -2228691 edf 19.756 eps 0.0001 iteration 8"
#> [9] "AICc 4457418. logPost -2228860 logLik -2228689 edf 19.753 eps 0.0001 iteration 9"
#> [10] "AICc 4457418. logPost -2228860 logLik -2228689 edf 19.753 eps 0.0001 iteration 9"
#> [11] "elapsed time: 14.76sec"
#> [12] "Starting the sampler..."
#> [13] "Starting the sampler..."
#> [14] "Starting the sampler...Starting the sampler..."
#> [15] ""
#> [16] ""
#> [17] "| | 0% 10.86min"
#> [18] "| | 0% 10.89min"
#> [19] "| | 0% 11.08min"
#> [20] "| | 0% 11.14min"
#> [21] "|* | 5% 10.36min 32.71sec"
#> [22] "|* | 5% 10.58min 33.41sec"
#> [23] ""
#> [24] "|* | 5% 10.70min 33.78sec|* | 5% 10.71min 33.82sec"
#> [25] "|** | 10% 9.79min 1.09min"
#> [26] "|** | 10% 9.86min 1.10min"
#> [27] ""
#> [28] "|** | 10% 10.09min 1.12min|** | 10% 10.10min 1.12min"
#> [29] "|*** | 15% 9.23min 1.63min"
#> [30] "|*** | 15% 9.27min 1.64min"
#> [31] ""
#> [32] "|*** | 15%|*** | 15% 9.55min 9.54min 1.68min 1.68min"
#> [33] "|**** | 20% 8.67min 2.17min"
#> [34] "|**** | 20% 8.68min 2.17min"
#> [35] ""
#> [36] "|**** | 20% 8.98min 2.24min|**** | 20% 8.98min 2.24min"
#> [37] "|***** | 25% 8.14min 2.71min"
#> [38] "|***** | 25% 8.15min 2.72min"
#> [39] ""
#> [40] "|***** | 25% |***** | 25% 8.42min 8.42min 2.81min 2.81min"
#> [41] "|****** | 30% 7.59min 3.25min"
#> [42] "|****** | 30% 7.60min 3.26min"
#> [43] ""
#> [44] "|****** | 30% 7.85min |****** | 30% 3.36min 7.85min 3.36min"
#> [45] "|******* | 35% 7.05min 3.79min"
#> [46] "|******* | 35% 7.06min 3.80min"
#> [47] ""
#> [48] "|******* | 35%|******* | 35% 7.29min 7.29min 3.93min 3.93min"
#> [49] "|******** | 40% 6.51min 4.34min"
#> [50] "|******** | 40% 6.53min 4.35min"
#> [51] "|******** | 40% 6.72min 4.48min"
#> [52] "|******** | 40% 6.72min 4.48min"
#> [53] "|********* | 45% 5.95min 4.87min"
#> [54] "|********* | 45% 5.97min 4.89min"
#> [55] "|********* | 45% 6.13min 5.01min"
#> [56] "|********* | 45% 6.14min 5.02min"
#> [57] "|********** | 50% 5.41min 5.41min"
#> [58] "|********** | 50% 5.43min 5.43min"
#> [59] "|********** | 50% 5.55min 5.55min"
#> [60] "|********** | 50% 5.56min 5.56min"
#> [61] "|*********** | 55% 4.86min 5.94min"
#> [62] "|*********** | 55% 4.89min 5.97min"
#> [63] "|*********** | 55% 4.98min 6.09min"
#> [64] "|*********** | 55% 4.98min 6.09min"
#> [65] "|************ | 60% 4.32min 6.48min"
#> [66] "|************ | 60% 4.34min 6.51min"
#> [67] "|************ | 60% 4.42min 6.63min"
#> [68] "|************ | 60% 4.42min 6.63min"
#> [69] "|************* | 65% 3.78min 7.02min"
#> [70] "|************* | 65% 3.79min 7.05min"
#> [71] "|************* | 65% 3.86min 7.17min"
#> [72] "|************* | 65% 3.86min 7.17min"
#> [73] "|************** | 70% 3.24min 7.56min"
#> [74] "|************** | 70% 3.25min 7.59min"
#> [75] "|************** | 70% 3.30min 7.71min"
#> [76] "|************** | 70% 3.31min 7.71min"
#> [77] "|*************** | 75% 2.70min 8.10min"
#> [78] "|*************** | 75% 2.71min 8.13min"
#> [79] "|*************** | 75% 2.75min 8.25min"
#> [80] "|*************** | 75% 2.75min 8.25min"
#> [81] "|**************** | 80% 2.16min 8.65min"
#> [82] "|**************** | 80% 2.17min 8.68min"
#> [83] "|**************** | 80% 2.20min 8.80min"
#> [84] "|**************** | 80% 2.20min 8.80min"
#> [85] "|***************** | 85% 1.62min 9.19min"
#> [86] "|***************** | 85% 1.63min 9.22min"
#> [87] "|***************** | 85% 1.65min 9.34min"
#> [88] "|***************** | 85% 1.65min 9.34min"
#> [89] "|****************** | 90% 1.08min 9.72min"
#> [90] "|****************** | 90% 1.08min 9.76min"
#> [91] "|****************** | 90% 1.10min 9.87min"
#> [92] "|****************** | 90% 1.10min 9.89min"
#> [93] "|******************* | 95% 32.40sec 10.26min"
#> [94] "|******************* | 95% 32.51sec 10.30min"
#> [95] "|******************* | 95% 32.89sec 10.42min"
#> [96] "|******************* | 95% 32.91sec 10.42min"
#> [97] "|********************| 100% 0.00sec 10.79min"
#> [98] ""
#> [99] "|********************| 100% 0.00sec 10.82min"
#> [100] ""
#> [101] "|********************| 100% 0.00sec 10.90min"
#> [102] ""
#> [103] "|********************| 100% 0.00sec 10.90min"
system.time(saveRDS(bamlss_model, file = path_modelled_data))
#> user system elapsed
#> 0.355 0.004 0.359
saveRDS(form, file = path_modelled_form)
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 2652.596 1.833 684.350