Linear model with random effects: 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")

source(file.path(path_proj, "src", "51-bamlss.R"))

bwdata_file <- file.path(path_processed, "bwdata_41_model.fst")
model_file <- file.path(path_modelled, "bw-muni-08-lm-re.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)

Summary

summary(model)
#> 
#> Call:
#> bamlss(formula = form, data = bwdata_model, cores = 4, combine = FALSE, 
#>     light = TRUE, n.iter = 1000, burnin = 0)
#> ---
#> Family: gaussian 
#> Link function: mu = identity, sigma = log
#> *---
#> Formula mu:
#> ---
#> born_weight ~ remoteness + prop_tap_toilet + s(res_muni, bs = "re")
#> -
#> Parametric coefficients:
#>                    Mean    2.5%     50%   97.5% parameters
#> (Intercept)     3200.15 3131.03 3203.72 3257.87    3232.79
#> remoteness       -56.64 -124.94  -60.14   17.72     -57.49
#> prop_tap_toilet  149.47   31.29  142.96  293.85     -51.00
#> -
#> Acceptance probabilty:
#>         Mean   2.5%    50% 97.5%
#> alpha 0.9920 0.9621 0.9988     1
#> -
#> Smooth terms:
#>                      Mean    2.5%     50%   97.5% parameters
#> s(res_muni).tau21 2142.83 1369.52 2067.18 3319.95    3823.12
#> s(res_muni).alpha    1.00    1.00    1.00    1.00         NA
#> s(res_muni).edf     41.81   41.25   41.84   42.25      42.35
#> ---
#> Formula sigma:
#> ---
#> sigma ~ 1
#> -
#> Parametric coefficients:
#>              Mean  2.5%   50% 97.5% parameters
#> (Intercept) 6.225 6.223 6.225 6.228      6.225
#> -
#> Acceptance probabilty:
#>         Mean   2.5%    50% 97.5%
#> alpha 0.9993 0.9937 1.0000     1
#> ---
#> Sampler summary:
#> -
#> runtime = 743.851
#> ---
#> Optimizer summary:
#> -
#> AICc = 4456381 edf = 46.3523 logLik = -2228144
#> logPost = -2228395 nobs = 291479 runtime = 9.681

Parametric effects

par(mar = c(4, 4, 0.5, 0), mfrow = c(1, 2), cex.axis = 0.7)
plot2d_bamlss(model, bwdata_model, model = "mu", term = "remoteness", grid = 50, FUN = c95)
plot2d_bamlss(model, bwdata_model, model = "mu", term = "prop_tap_toilet", grid = 50, FUN = c95)

Time to execute the task

Only useful when executed with Rscript.

proc.time()
#>    user  system elapsed 
#>  22.018   0.333  22.370