SSNbayes: An R Package for Bayesian Spatio-Temporal Modelling on Stream Networks

Spatio-temporal models are widely used in many research areas from ecology to epidemiology. However, a limited number of computational tools are available for modeling river network datasets in space and time. In this paper, we introduce the R package SSNbayes for fitting Bayesian spatio-temporal models and making predictions on branching stream networks. SSNbayes provides a linear regression framework with multiple options for incorporating spatial and temporal autocorrelation. Spatial dependence is captured using stream distance and flow connectivity while temporal autocorrelation is modelled using vector autoregression approaches. SSNbayes provides the functionality to make predictions across the whole network, compute exceedance probabilities, and other probabilistic estimates, such as the proportion of suitable habitat. We illustrate the functionality of the package using a stream temperature dataset collected in the Clearwater River Basin, USA.

Edgar Santos-Fernandez (School of Mathematical Sciences, Queensland University of Technology) , Jay M. Ver Hoef (Marine Mammal Laboratory, NOAA-NMFS Alaska Fisheries Science Center.) , James McGree (School of Mathematical Sciences, Queensland University of Technology) , Daniel J. Isaak (Rocky Mountain Research Station, US Forest Service) , Kerrie Mengersen (School of Mathematical Sciences, Queensland University of Technology) , Erin E. Peterson (EP Consulting)

0.1 Supplementary materials

Supplementary materials are available in addition to this article. It can be downloaded at

G. Bal, E. Rivot, J.-L. Baglinière, J. White and E. Prévost. A hierarchical Bayesian model to quantify uncertainty of stream water temperature forecasts. PLoS One, 9(12): e115659, 2014.
S. Banerjee, B. P. Carlin and A. E. Gelfand. Hierarchical modeling and analysis for spatial data. CRC press, 2014.
B. Carpenter, A. Gelman, M. D. Hoffman, D. Lee, B. Goodrich, M. Betancourt, M. Brubaker, J. Guo, P. Li and A. Riddell. Stan: A probabilistic programming language. Journal of statistical software, 76(1): 2017.
N. Cressie, J. Frey, B. Harch and M. Smith. Spatial prediction on a river network. Journal of Agricultural, Biological, and Environmental Statistics, 11(2): 127, 2006.
N. Cressie and C. K. Wikle. Statistics for spatio-temporal data. John Wiley & Sons, 2015.
C. Donegan. Geostan: Bayesian spatial analysis (r package). 2022. URL The Comprehensive R Archive Network.
M. Dumelle, E. Peterson, J. M. Ver Hoef, A. Pearse and D. Isaak. SSN2: Spatial modeling on stream networks in R. 2023. R package version 0.1.0.
ESRI. ArcGIS Desktop. Redlands, CA.: Environmental Systems Research Institute., 2019.
A. O. Finley, S. Banerjee and A. E.Gelfand. spBayes for large univariate and multivariate point-referenced spatio-temporal data models. Journal of Statistical Software, 63(13): 1–28, 2015. URL
J. C. Frieden, E. E. Peterson, J. A. Webb and P. M. Negus. Improving the predictive power of spatial statistical models of stream macroinvertebrates using weighted autocovariance functions. Environmental Modelling & Software, 60: 320–330, 2014.
J. Gabry and T. Mahr. Bayesplot: Plotting for bayesian models. 2018. URL R package version 1.6.0.
V. Garreta, P. Monestiez and J. M. Ver Hoef. Spatial modelling and prediction on river networks: Up model, down model or hybrid? Environmetrics, 21(5): 439–456, 2010.
A. E. Gelfand, M. Fuentes, J. A. Hoeting and R. L. Smith. Handbook of environmental and ecological statistics. CRC Press, 2019.
J. D. Hamilton. Time series analysis. Princeton university press, 1994.
R. J. Hyndman and Y. Khandakar. Automatic time series forecasting: The forecast package for R. Journal of Statistical Software, 26(3): 1–22, 2008. URL
D. J. Isaak, C. H. Luce, G. L. Chandler, D. L. Horan and S. P. Wollrab. Principal components of thermal regimes in mountain river networks. Hydrology and Earth System Sciences, 22(12): 6225–6240, 2018.
D. J. Isaak, E. E. Peterson, J. M. Ver Hoef, S. J. Wenger, J. A. Falke, C. E. Torgersen, C. Sowder, E. A. Steel, M.-J. Fortin, C. E. Jordan, et al. Applications of spatial statistical network models to stream data. Wiley Interdisciplinary Reviews: Water, 1(3): 277–294, 2014.
D. J. Isaak, S. J. Wenger, E. E. Peterson, J. M. Ver Hoef, D. E. Nagel, C. H. Luce, S. W. Hostetler, J. B. Dunham, B. B. Roper, S. P. Wollrab, et al. The NorWeST summer stream temperature model and scenarios for the western US: A crowd-sourced database and new geospatial tools foster a user community and predict broad climate warming of rivers and streams. Water Resources Research, 53(11): 9181–9205, 2017. URL
D. J. Isaak, M. K. Young, C. H. Luce, S. W. Hostetler, S. J. Wenger, E. E. Peterson, J. M. Ver Hoef, M. C. Groce, D. L. Horan and D. E. Nagel. Slow climate velocities of mountain streams portend their role as refugia for cold-water biodiversity. Proceedings of the National Academy of Sciences, 113(16): 4374–4379, 2016.
F. L. Jackson, R. J. Fryer, D. M. Hannah, C. P. Millar and I. A. Malcolm. A spatio-temporal statistical model of maximum daily river temperatures to inform the management of Scotland’s Atlantic salmon rivers under climate change. Science of the Total Environment, 612: 1543–1558, 2018.
E. A. P. Kattwinkel Mira AND Szöcs. Preparing GIS data for analysis of stream monitoring data: The r package openSTARS. PLOS ONE, 15(9): 1–10, 2020. URL
D. Lee. CARBayes: An R package for Bayesian spatial modeling with conditional autoregressive priors. Journal of Statistical Software, 55(13): 1–24, 2013. URL
F. Lindgren and H. Rue. Bayesian spatial modelling with R-INLA. Journal of Statistical Software, 63(19): 1–25, 2015. URL
K. J. McGuire, C. E. Torgersen, G. E. Likens, D. C. Buso, W. H. Lowe and S. W. Bailey. Network analysis reveals multiscale controls on streamwater chemistry. Proceedings of the National Academy of Sciences, 111(19): 7030–7035, 2014. URL
M. G. McManus, E. D’Amico, E. M. Smith, R. Polinsky, J. Ackerman and K. Tyler. Variation in stream network relationships and geospatial predictions of watershed conductivity. Freshwater Science, 39(4): 704–721, 2020.
E. S. Money, G. P. Carter and M. L. Serre. Modern space/time geostatistics using river distances: Data integration of turbidity and E. coli measurements to assess fecal contamination along the raritan river in New Jersey. Environmental Science & Technology, 43(10): 3736–3742, 2009a.
E. Money, G. P. Carter and M. L. Serre. Using river distances in the space/time estimation of dissolved oxygen along two impaired river networks in new jersey. Water Research, 43(7): 1948–1958, 2009b.
E. Pebesma. CRAN Task View: Handling and Analyzing Spatio-Temporal Data. 2021. Accessed: 2021-04-13.
E. E. Peterson, A. A. Merton, D. M. Theobald and N. S. Urquhart. Patterns of spatial autocorrelation in stream water chemistry. Environmental Monitoring and Assessment, 121(1): 571–596, 2006.
E. E. Peterson and J. M. Ver Hoef. A mixed-model moving-average approach to geostatistical modeling in stream networks. Ecology, 91(3): 644–651, 2010.
E. E. Peterson, J. M. Ver Hoef, D. J. Isaak, J. A. Falke, M.-J. Fortin, C. E. Jordan, K. McNyset, P. Monestiez, A. S. Ruesch, A. Sengupta, et al. Modelling dendritic ecological networks in space: An integrated network perspective. Ecology Letters, 16(5): 707–719, 2013.
E. Peterson and J. M. Ver Hoef. STARS: An ArcGIS toolset used to calculate the spatial information needed to fit spatial statistical models to stream network data. Journal of Statistical Software, 56(2): 1–17, 2014.
J. C. Pinheiro and D. M. Bates. Mixed-effects models in s and s-PLUS. New York: Springer, 2000. DOI 10.1007/b98882.
J. Pinheiro, D. Bates, S. DebRoy, D. Sarkar and R Core Team. nlme: Linear and nonlinear mixed effects models. 2020. URL R package version 3.1-148.
P. J. Ribeiro Jr, P. J. Diggle, M. Schlather, R. Bivand and B. Ripley. geoR: Analysis of geostatistical data. 2020. URL R package version 1.8-1.
P. M. Rodrı́guez-González, C. Garcı́a, A. Albuquerque, T. Monteiro-Henriques, C. Faria, J. B. Guimarães, D. Mendonça, F. Simões, M. T. Ferreira, A. Mendes, et al. A spatial stream-network approach assists in managing the remnant genetic diversity of riparian forests. Scientific Reports, 9(1): 1–10, 2019.
A. Rushworth. Smnet: Smoothing for stream network data. 2017. URL R package version 2.1.1.
S. K. Sahu, D. P. Lee and K. S. Bakar. Bmstdr: Bayesian modeling of spatio-temporal data with r. 2022. URL R package version 0.3.0.
E. Santos-Fernandez. SSNdata: Spatial stream network datasets. 2022. URL
E. Santos-Fernandez, J. M. Ver Hoef, E. E. Peterson, J. McGree, D. J. Isaak and K. Mengersen. Bayesian spatio-temporal models for stream networks. Computational Statistics & Data Analysis, 170: 107446, 2022.
E. Santos-Fernandez, J. M. Ver Hoef, E. E. Peterson, J. McGree, C. A. Villa, C. Leigh, R. Turner, C. Roberts and K. Mengersen. Unsupervised anomaly detection in spatio-temporal stream network sensor data. preprint, 2023.
M. Schlather, A. Malinowski, P. J. Menck, M. Oesting and K. Strokorb. Analysis, simulation and prediction of multivariate random fields with package RandomFields. Journal of Statistical Software, 63(8): 1–25, 2015. URL
J. O. Skoien, G. Bloschl, G. Laaha, E. Pebesma, J. Parajka and A. Viglione. Rtop: An r package for interpolation of data with a variable spatial support, with an example from river networks. Computers & Geosciences, 2014.
Stan Development Team. RStan: The R interface to Stan. 2018. URL R package version 2.18.2.
J. M. Ver Hoef and E. E. Peterson. A moving average approach for spatial statistical models of stream networks. Journal of the American Statistical Association, 105(489): 6–18, 2010.
J. M. Ver Hoef, E. Peterson, D. Clifford and R. Shah. SSN: An R package for spatial statistical modeling on stream networks. Journal of Statistical Software, 56(3): 1–45, 2014.
J. M. Ver Hoef, E. Peterson and D. Theobald. Spatial statistical models that use flow and stream distance. Environmental and Ecological statistics, 13(4): 449–464, 2006.
C. J. Vörösmarty, P. B. McIntyre, M. O. Gessner, D. Dudgeon, A. Prusevich, P. Green, S. Glidden, S. E. Bunn, C. A. Sullivan, C. R. Liermann, et al. Global threats to human water security and river biodiversity. Nature, 467(7315): 555–561, 2010.
H. Wickham. ggplot2: Elegant graphics for data analysis. Springer-Verlag New York, 2016. URL
H. Wickham. Reshaping data with the reshape package. Journal of Statistical Software, 21(12): 1–20, 2007. URL
C. K. Wikle, L. M. Berliner and N. Cressie. Hierarchical bayesian space-time models. Environmental and Ecological Statistics, 5(2): 117–154, 1998.
C. K. Wikle, A. Zammit-Mangion and N. Cressie. Spatio-temporal statistics with r. CRC Press, 2019.
A. Zammit-Mangion and N. Cressie. FRK: An r package for spatial and spatio-temporal prediction with large datasets. Journal of Statistical Software, 98(4): 1–48, 2021.



Text and figures are licensed under Creative Commons Attribution CC BY 4.0. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: "Figure from ...".


For attribution, please cite this work as

Santos-Fernandez, et al., "SSNbayes: An R Package for Bayesian Spatio-Temporal Modelling on Stream Networks", The R Journal, 2023

BibTeX citation

  author = {Santos-Fernandez, Edgar and Hoef, Jay M. Ver and McGree, James and Isaak, Daniel J. and Mengersen, Kerrie and Peterson, Erin E.},
  title = {SSNbayes: An R Package for Bayesian Spatio-Temporal Modelling on Stream Networks},
  journal = {The R Journal},
  year = {2023},
  note = {},
  doi = {10.32614/RJ-2023-061},
  volume = {15},
  issue = {3},
  issn = {2073-4859},
  pages = {26-58}