Modelling Beyond a Straight Line

R
statistics
environmental science
regression
A Quarto site walking through nonlinear and non-monotonic trend detection for water-quality data - piecewise regression, changepoint detection, k-NN, LOESS, GAMs and GAMMs - for an environmental-consulting audience.
Author

Ian Gault

Published

August 20, 2026

View on GitHub View Vignette

Not every water-quality trend is a straight line. This vignette works through the toolkit for series that curve, plateau, break, or shift level, building from OLS assumptions up to semi-parametric models, with each method paired to a case study analyte that actually needs it.

What it covers

  • The regression framework: estimand, link, systematic component, and how OLS sits inside it as the identity-link/Gaussian special case
  • Diagnosing which kind of nonlinearity a series needs: a log-response transform, a feature-engineered regressor, or a link function
  • Piecewise / segmented linear regression for a slope break at an unknown location
  • Changepoint detection for a level shift at an unknown location
  • k-NN regression and LOESS smoothing for a rise-then-plateau shape, compared side by side on the same data
  • GAMs (mgcv) for step-like, non-monotonic change with no periodic or polynomial pattern
  • GAMMs for a seasonal cycle plus trend, with autocorrelated residuals
  • A closing comparison of linear vs. nonlinear fits on two control analytes

Design

The site is organized as one method per chapter, each grounded in a specific case study rather than a generic worked example, and framed around inference on the observed record rather than forecasting - k-NN, LOESS, GAM, and GAMM all extrapolate poorly outside the fitted range. It’s a working site: some chapters are complete case studies, others are still scaffolds being filled in.