Modelling Beyond a Straight Line

Water Quality
R
statistics
environmental science
regression
Many water-quality trends curve, plateau, or shift. I wrote a guide that pairs each method, from piecewise regression to GAMs, with a case study, and covers how to choose which model belongs in a report.
Author

Ian Gault

Published

August 20, 2026

Modified

November 16, 2026

View Vignette View on GitHub

About the data

This project uses synthetic data, built to resemble monthly water-quality monitoring records.

Trend analysis in environmental monitoring often starts with a straight line or a Mann-Kendall test. Many records curve, plateau, break, or shift level. This vignette works through methods for those records, building from the regression framework up to semi-parametric models, with each method paired with a case study analyte that needs it. The focus is on describing what happened in the observed record.

Why it matters for a decision

Model choice changes what gets reported and what action follows. A plateau read as ongoing growth can lead to a treatment upgrade nobody needed. A step change read as a gradual trend can send an investigation toward the wrong cause. A flexible model fit to noise can find a trend that isn’t there, and a model that is too simple can miss a real change.

What it covers

Framework

  • The regression framework: estimand, link, systematic component, and how ordinary least squares fits inside it
  • Transformations: how to tell whether a series needs a log-response transform, a feature-engineered regressor, or a different link function

Methods, each with a case study

  • Piecewise regression for a slope break (Total Nitrogen)
  • Changepoint detection for a level shift at an unknown date (Specific Conductance)
  • k-NN regression and LOESS to see the shape of a rise-then-plateau before choosing a model (Total Phosphorus)
  • GAMs for step-like, non-monotonic change (Total Copper), including simultaneous intervals that show where the record is rising, falling, or flat, compared with a single-slope summary
  • GAMMs for a seasonal cycle plus trend with autocorrelated residuals (Dissolved Oxygen)

Choosing a model

  • Linear vs. nonlinear comparison on two control analytes, one with a straight-line trend (Total Chloride) and one with no trend (Total Zinc), to check whether added flexibility is justified
  • Mechanism vs. shape: how the question, what is known about how the data arose, and whether the answer has to reach past the record decide which model belongs in a report. Worked through on Total Phosphorus, with a contaminant plume example where a process-based model and a forecast are justified

Design

The site has one method per chapter, each built on a case study. The home page includes a table that maps the question you’re trying to answer (exploratory, confirmatory, forensic, and so on) to the chapter to start from. The site uses a locked R package environment (renv) and an automated build, so every model, diagnostic, and figure can be regenerated from the code.