Abstract
This paper introduces the dlmwwbe R package, which implements dynamic linear models (DLMs) as outlined in Shumway and Stoffer (2025). The package provides two primary model structures designed for the smoothing and forecasting of wastewater-based epidemiological data. By utilizing state-space modeling, the framework effectively addresses the inherent noise and irregular sampling common in environmental surveillance.
Introduction
Wastewater-based epidemiology (WBE) has emerged as a vital public health tool, offering a non-invasive way to track disease prevalence in a community. However, wastewater data is notoriously "messy." Sampling is often infrequent (e.g., twice a week), measurements are subject to significant environmental noise, and the relationship between viral loads in sewage and actual clinical cases involves complex temporal lags.
Standard time-series methods often struggle with these irregularities. The dlmwwbe package addresses these challenges by implementing state-space models—specifically Dynamic Linear Models—that are mathematically tailored to handle missing data, filter out measurement noise, and capture the underlying latent trends in viral shedding.
The dllm Function for Data Smoothing
The package implements methodologies focusing on two primary model structures. The first, Dynamic Local Level Models (dllm), is used primarily for data smoothing and state estimation. The function uses Maximum Likelihood Estimation (MLE) to fit the model and applies Kalman filtering and smoothing to extract the "true" underlying signal from noisy observations.
Notably, dllm supports k-variate structures, allowing researchers to model multiple viral targets (such as the ORF and N genes of SARS-CoV-2) simultaneously. This multivariate synergy provides a more robust estimate of disease prevalence than analyzing each marker in isolation.
The pdlm Function for Predictive Modeling
The second structure, Predictive Dynamic Linear Models (pdlm), is designed for forecasting and relating wastewater metrics to clinical data. This function uses a formula interface (similar to standard regression in R) and allows for the inclusion of lags, acknowledging that wastewater signals often serve as a leading indicator for clinical outbreaks.
Practical Application and Datasets
The package includes two real-world datasets from Minnesota (March 2022 to February 2023) to demonstrate its utility:
wastewater: A long-format dataset tracking two specific viral targets (ORFlab and Nlab) collected twice weekly, illustrating how the model handles frequent missing values in a daily time series.wastewaterhealthworker: A wide-format dataset pairing flow-adjusted wastewater measurements with clinical COVID-19 positive case counts among healthcare workers, providing a "ground truth" for predictive modeling.
Key Insights
By treating the "true" viral level as a hidden (latent) state, DLMs can effectively separate the signal from the noise inherent in wastewater sampling and lab analysis. The explicit inclusion of a lags parameter in the predictive models reinforces the role of wastewater as an early-warning system, allowing the model to quantify exactly how many days or weeks wastewater leads clinical reports. Furthermore, to lower the barrier to entry for practitioners, the package includes auto_init features that automatically estimate initial parameters for the MLE process, which can otherwise be a significant hurdle in state-space modeling.
Conclusion and Future Work
The dlmwwbe package provides a streamlined workflow from raw data to MLE fitting, smoothing, and visualization. While the current version (0.1.0) represents the foundational framework, future work will involve fully integrating specific models from the associated manuscript upon publication. Researchers should note that while the methods are generalizable, optimal lag structures and variance parameters may vary significantly across different sewer sheds and climates.
Summary updated