Discrete binning only smooths: effects


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")

bwdata_file <- file.path(path_processed, "bwdata_51_test.fst")
model_file <- file.path(path_modelled, "bw-09-discrete-bin-age.rds")
form_file <- gsub("(\\.rds)$", "-form\\1", model_file)
model_file_burned <- gsub("(\\.rds)$", "-burned\\1", model_file)

bwdata_model <- fst::read_fst(bwdata_file)
form <- readRDS(form_file)
model <- readRDS(model_file_burned)

Compute results

model$results <- results.bamlss.default(model)

Fixed effects

summary(model)
#> 
#> Call:
#> bamlss(formula = form, data = bwdata_model, cores = 4, combine = FALSE, 
#>     light = TRUE, binning = TRUE, n.iter = 1000, burnin = 0)
#> ---
#> Family: gaussian 
#> Link function: mu = identity, sigma = log
#> *---
#> Formula mu:
#> ---
#> born_weight ~ marital_status + race + s(age_bin)
#> -
#> Parametric coefficients:
#>                     Mean     2.5%      50%    97.5% parameters
#> (Intercept)     2476.165 2458.597 2475.847 2494.889    2393.93
#> marital_status2  -12.192  -21.747  -12.188   -2.450     -11.94
#> marital_status3 -137.041 -146.510 -137.073 -127.840    -136.96
#> race2             14.307    3.118   14.488   25.457      14.68
#> race3             29.810   18.760   29.774   40.865      30.00
#> race4             52.883   41.860   52.928   63.925      53.43
#> -
#> Acceptance probabilty:
#>         Mean   2.5%    50% 97.5%
#> alpha 0.9933 0.9668 1.0000     1
#> -
#> Smooth terms:
#>                       Mean      2.5%       50%     97.5% parameters
#> s(age_bin).tau21 1.035e+06 3.254e+05 8.364e+05 2.868e+06  8.031e+06
#> s(age_bin).alpha 1.000e+00 1.000e+00 1.000e+00 1.000e+00         NA
#> s(age_bin).edf   7.907e+00 7.192e+00 7.915e+00 8.556e+00  8.818e+00
#> ---
#> Formula sigma:
#> ---
#> sigma ~ 1
#> -
#> Parametric coefficients:
#>              Mean  2.5%   50% 97.5% parameters
#> (Intercept) 5.631 5.621 5.631 5.640      5.632
#> -
#> Acceptance probabilty:
#>         Mean   2.5%    50% 97.5%
#> alpha 0.9970 0.9759 1.0000     1
#> ---
#> Sampler summary:
#> -
#> runtime = 27.42
#> ---
#> Optimizer summary:
#> -
#> AICc = 282088.4 edf = 15.8184 logLik = -141028.4
#> logPost = -141176.7 nobs = 20000 runtime = 3.29

Smoothed effects

There seems to be a problem with the labels of the random effects plot.

par(mar = c(4, 4, 0.5, 0), mfrow = c(1, 2), cex.axis = 0.7)
plot(model, scale = 0, scheme = 2, spar = FALSE)

Time to execute the task

Only useful when executed with Rscript.

proc.time()
#>    user  system elapsed 
#>   2.274   0.118   2.409