Parametric terms: fitting
Birthweight model including covariates at municipality level with linear effects.
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-muni-02-covs-param.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
Now we define the same models as in the previous study.
form_sigma <- sigma ~ 1
form_mu <- born_weight ~ poly(remoteness, 2) + poly(prop_tap_toilet, 2)
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,
n.iter = 1000, burnin = 0, cores = 4, combine = FALSE, light = TRUE
)
sink()
}
readLines(path_modelled_sink)
#> [1] "AICc 4458216. logPost -2229216 logLik -2229102 edf 6.0000 eps 0.0299 iteration 1"
#> [2] "AICc 4458216. logPost -2229216 logLik -2229102 edf 6.0000 eps 0.0000 iteration 2"
#> [3] "AICc 4458216. logPost -2229216 logLik -2229102 edf 6.0000 eps 0.0000 iteration 2"
#> [4] "elapsed time: 0.74sec"
#> [5] "Starting the sampler..."
#> [6] "Starting the sampler...Starting the sampler..."
#> [7] ""
#> [8] "Starting the sampler..."
#> [9] ""
#> [10] "| | 0% 5.43min"
#> [11] "| | 0% 5.45min"
#> [12] "| | 0% 5.89min"
#> [13] "| | 0% 5.89min"
#> [14] "|* | 5% 4.61min 14.54sec"
#> [15] "|* | 5% 4.61min 14.55sec"
#> [16] "|* | 5% 4.69min 14.81sec"
#> [17] "|* | 5% 4.71min 14.87sec"
#> [18] "|** | 10% 4.30min 28.64sec"
#> [19] "|** | 10% 4.30min 28.65sec"
#> [20] "|** | 10% 4.31min 28.74sec"
#> [21] "|** | 10% 4.33min 28.89sec"
#> [22] "|*** | 15% 4.02min 42.56sec"
#> [23] "|*** | 15% 4.04min 42.77sec"
#> [24] "|*** | 15% 4.05min 42.88sec"
#> [25] "|*** | 15% 4.04min 42.82sec"
#> [26] "|**** | 20% 3.77min 56.62sec"
#> [27] "|**** | 20% 3.78min 56.76sec"
#> [28] "|**** | 20% 3.79min 56.79sec"
#> [29] "|**** | 20% 3.80min 57.04sec"
#> [30] "|***** | 25% 3.53min 1.18min"
#> [31] "|***** | 25% 3.54min 1.18min"
#> [32] "|***** | 25% 3.54min 1.18min"
#> [33] "|***** | 25% 3.55min 1.18min"
#> [34] "|****** | 30% 3.30min 1.41min"
#> [35] "|****** | 30% 3.30min 1.42min"
#> [36] "|****** | 30% 3.31min 1.42min"
#> [37] "|****** | 30% 3.30min 1.42min"
#> [38] "|******* | 35% 3.06min 1.65min"
#> [39] "|******* | 35% 3.07min 1.65min"
#> [40] "|******* | 35% 3.07min 1.65min"
#> [41] "|******* | 35% 3.07min 1.65min"
#> [42] "|******** | 40% 2.82min 1.88min"
#> [43] "|******** | 40% 2.82min 1.88min"
#> [44] "|******** | 40% 2.83min 1.89min"
#> [45] "|******** | 40% 2.84min 1.89min"
#> [46] "|********* | 45% 2.59min 2.12min"
#> [47] "|********* | 45% 2.59min 2.12min"
#> [48] "|********* | 45% 2.59min 2.12min"
#> [49] "|********* | 45% 2.59min 2.12min"
#> [50] "|********** | 50% 2.35min 2.35min"
#> [51] "|********** | 50% 2.36min 2.36min"
#> [52] "|********** | 50% 2.36min 2.36min"
#> [53] "|********** | 50% 2.36min 2.36min"
#> [54] "|*********** | 55% 2.11min 2.58min"
#> [55] "|*********** | 55% 2.12min 2.59min"
#> [56] "|*********** | 55% 2.12min 2.59min"
#> [57] "|*********** | 55% 2.12min 2.59min"
#> [58] "|************ | 60% 1.88min 2.82min"
#> [59] "|************ | 60% 1.88min 2.82min"
#> [60] "|************ | 60% 1.88min 2.83min"
#> [61] "|************ | 60% 1.89min 2.83min"
#> [62] "|************* | 65% 1.64min 3.05min"
#> [63] "|************* | 65% 1.65min 3.06min"
#> [64] "|************* | 65% 1.65min 3.06min"
#> [65] "|************* | 65% 1.65min 3.07min"
#> [66] "|************** | 70% 1.41min 3.29min"
#> [67] "|************** | 70% 1.41min 3.30min"
#> [68] "|************** | 70% 1.41min 3.30min"
#> [69] "|************** | 70% 1.41min 3.30min"
#> [70] "|*************** | 75% 1.17min 3.52min"
#> [71] "|*************** | 75% 1.18min 3.53min"
#> [72] "|*************** | 75% 1.18min 3.53min"
#> [73] "|*************** | 75% 1.18min 3.54min"
#> [74] "|**************** | 80% 56.44sec 3.76min"
#> [75] "|**************** | 80% 56.46sec 3.76min"
#> [76] "|**************** | 80% 56.56sec 3.77min"
#> [77] "|**************** | 80% 56.61sec 3.77min"
#> [78] "|***************** | 85% 42.27sec 3.99min"
#> [79] "|***************** | 85% 42.35sec 4.00min"
#> [80] "|***************** | 85% 42.37sec 4.00min"
#> [81] "|***************** | 85% 42.41sec 4.00min"
#> [82] "|****************** | 90% 28.18sec 4.23min"
#> [83] "|****************** | 90% 28.20sec 4.23min"
#> [84] "|****************** | 90% 28.25sec 4.24min"
#> [85] "|****************** | 90% 28.27sec 4.24min"
#> [86] "|******************* | 95% 14.09sec 4.46min"
#> [87] "|******************* | 95% 14.10sec 4.47min"
#> [88] "|******************* | 95% 14.11sec 4.47min"
#> [89] "|******************* | 95% 14.14sec 4.48min"
#> [90] "|********************| 100% 0.00sec 4.69min"
#> [91] ""
#> [92] "|********************| 100% 0.00sec 4.70min"
#> [93] ""
#> [94] "|********************| 100% 0.00sec 4.70min"
#> [95] ""
#> [96] "|********************| 100% 0.00sec 4.71min"
system.time(saveRDS(bamlss_model, file = path_modelled_data))
#> user system elapsed
#> 0.326 0.000 0.326
saveRDS(form, file = path_modelled_form)
Time to execute the task
Only useful when executed with Rscript
.
proc.time()
#> user system elapsed
#> 1159.872 5.737 298.964