New R Package {bdlnm} Released on CRAN: Bayesian Distributed Lag Non-Linear Models in R via INLA

Wait 5 sec.

[This article was first published on R-posts.com, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.CRAN, GitHubTL;DR: {bdlnm} brings Bayesian Distributed Lag Non-Linear Models (B-DLNMs) to R using INLA, allowing to model complex DLNMs, quantify uncertainty, and produce rich visualizations.BackgroundClimate change is increasing exposure to extreme environmental conditions such as heatwaves and air pollution. However, these exposures rarely have immediate effects. For example:A heatwave today may increase mortality several days laterAir pollution can have cumulative and delayed impactsDistributed Lag Non-Linear Models (DLNMs) are the standard framework for studying these effects. They simultaneously model:How risk changes with exposure level (exposure-response)How risk evolve over time (lag-response)Usually in the presence of non-linear effects, splines are used to define these two relationships. These two basis are then combined through a cross-basis function. As datasets become larger and more complex (e.g., studies with different regions and longer time periods), classical approaches show limitations. Bayesian DLNMs extend this framework by:Supporting more flexible model structuresProviding full posterior distributionsEnabling richer uncertainty quantificationThe new {bdlnm} package extends the framework of the {dlnm} package to a Bayesian setting, using Integrated Nested Laplace Approximation (INLA), a fast alternative to MCMC for Bayesian inference.Installing and loading the packageAs of March 2026, the package is available on CRAN:install.packages("bdlnm")library(bdlnm)At least the stable version of INLA 23.4.24 (or newest) must be installed beforehand. You can install the newest stable INLA version by:install.packages( "INLA", repos = c( getOption("repos"), INLA = "https://inla.r-inla-download.org/R/stable" ), dep = TRUE)Now, let’s load all the libraries we will need for this short tutorial:Load required libraries# DLNMs and splineslibrary(dlnm)library(splines)# Data manipulationlibrary(dplyr)library(reshape2)library(stringr)library(lubridate)# Visualizationlibrary(ggplot2)library(gganimate)library(ggnewscale)library(patchwork)library(scales)library(plotly)# Tableslibrary(gt)# Execution timelibrary(tictoc)Hands-on exampleWe use the built-in london dataset with daily temperature and mortality (age 75+) from 2000-2012.Before fitting any model, it is useful to explore the raw data. This plot shows daily mean temperature and mortality for the 75+ age group in London from 2000 to 2012, providing a first look at the time series we are trying to model:col_mort