Skip to contents

A Gaussian Sliding Windows Regression Model

This R package presents a Sliding Windows Regression model with Gaussian kernels for hydrological inference, see Schrunner et al. (2023). Given an input time series (xt)_t ∈ T (describing rainfall in a hydrological setting) and a time-dependent target variable (yt)_t ∈ T describing the gauged watershed runoff, the model utilizes a set of k lagged time windows to model one water path each. For instance, surface flow, characterized by short time lags, may be represented by the first window, while groundwater flow is described by a second window with longer time lags.

A lagged time window W is an interval on the time axis bounded by time lags smin < smax relative to the current time point t,

W = [tsmax,tsmin].

Instead of smin and smax, W is represented by the following parameters for simplicity:

  • a location parameter $$\delta = \frac{s_{\min} + s_{\max}}{2}$$ indicating the window center on the time axis, i.e. the distance between the window center and the estimated time point on the time axis, and
  • a size parameter $$\sigma = \lceil \frac{s_{\max}-s_{\min}}{6} \rceil$$ defining the width of the window.

Given such a window Wi, we define a Gaussian kernel κ(i) as a weight vector approximating the shape of a Gaussian probability density function φ with mean μ = δi and standard deviation σ. The predicted runoff associated with window i is then computed as the convolution of the input time series (xt)_t ∈ T with the window kernel κ(i) as weight vector, i.e. κ(i) * xWi, where xW = (xt − smax,…,xt − smin) denotes the vector of lagged observations and * denotes the convolution operator.

Overall, the predicted output yt is modeled as a multiple linear regression model

$$ y_t = \sum\limits_{i=1}^{k} \beta_i \left(\kappa^{(i)} \ast x_{W_i}\right) + \varepsilon_t, $$

where εt denotes the model error. Due to practical considerations, we restrict regression parameters β1, …, βk to non-negative numbers.

Package structure

The core functionality of the package consists of functions train and predict, which perform the model fitting and forecasting steps, respectively. Further, functions for evaluating and plotting model results and parameters are provided.

The implementation builds on an S3 class SWR, which implements multiple generic functions, such as summary, plot, coef, dim, AIC, or BIC. Further, evaluation metrics can be computed using eval_all, which calls regression performance metrics rmse (root mean square error, RMSE), nrmse (normalized RMSE), r2 (coefficient of determination), as well as hydrological metrics nse (Nash-Sutcliffe efficiency) and kge (Kling-Gupta efficientcy). Plots are provided for the kernel vectors κ(i) via plot_kernel, as well as for the predictions using plot_prediction.

A sample dataset sampleWatershed is contained in the package. The data originates from a real-world watershed in Cowichan, British Columbia, Canada and contains daily precipitation (input time series), as well as gauged runoff (output time series). Both time series cover a period of 39 hydrological years, starting on October 01, 1979.

Installation

This version of the R package can be installed as follows:

  remotes::install_github("sschrunner/SlidingWindowReg", build_manual = TRUE, build_vignettes = TRUE)

Dependencies

  • R (>= 3.5.0)
  • combinat,
  • dplyr,
  • ggplot2,
  • hydroGOF,
  • knitr,
  • lifecycle,
  • methods,
  • nloptr,
  • rgenoud,
  • parallel,
  • pbapply,
  • rdist,
  • Rdpack (>= 0.7),
  • stats

Citation

If you use SlidingWindowReg in a report or scientific publication, we would appreciate citations to the following preprint:

Schrunner, S. et al. (2023). A Gaussian Sliding Windows Regression Model for Hydrological Inference. arXiv.org (preprint), 2023, https://doi.org/10.48550/arXiv.2306.00453

Bibtex entry:

@misc{schrunner2023gaussian,
  title={A Gaussian Sliding Windows Regression Model for Hydrological Inference}, 
  author={Stefan Schrunner and Joseph Janssen and Anna Jenul and Jiguo Cao and Ali A. Ameli and William J. Welch},
  year={2023},
  howpublished={arXiv.org (preprint)},
  eprint={2306.00453},
  archivePrefix={arXiv},
  primaryClass={stat.ME},
  doi={10.48550/arXiv.2306.00453},
  url={https://doi.org/10.48550/arXiv.2306.00453}
  }

Contact

The implemented Gaussian Sliding Windows Regression model was developed in collaboration between

  • Norwegian University of Life Sciences (NMBU), Ås, Norway,
  • University of British Columbia (UBC), Vancouver, Canada, and
  • Simon Fraser University (SFU), Burnaby, Canada

This package is currently under development. For issues, feel free to contact Stefan Schrunner.