Modeling smoothing splines for nonlinear curve fitting with applications to Rio Grande salinity transport
Abstract
Roughly 68% of salinity transport models for semi-arid river basins rely on linear interpolation between monitoring stations, a method that ignores the curved response of dissolved solids to variable discharge. This research developed a smoothing spline framework for nonlinear curve fitting and applied it to salinity transport along the Rio Grande between El Paso, Texas, and Presidio, Texas. Daily electrical conductivity and total dissolved solids (TDS) records from seven monitoring stations, spanning January 2019 to June 2023, formed the observational basis. The spline model used penalised cubic B-splines whose smoothing parameter and knot placement were jointly selected by generalised cross-validation (GCV). A Diophantine-equation-based indexing scheme was introduced to map knot positions onto integer lattice points, ensuring reproducibility and simplifying sensitivity checks. Multivariate extensions handled the joint behaviour of TDS, sulphate concentration, and chloride-to-sodium ratio.Cross-validation trials explored 36 combinations of smoothing parameter (0.001 to 1.0) and knot count (5 to 30). The optimal configuration—smoothing parameter 0.1 with 20 interior knots—yielded a root mean square error (RMSE) of 0.089 mg L⁻¹ and captured 91.3% of the observed TDS variance. A variance decomposition showed that the cubic component of the spline accounted for 38.2% of model variance, the quadratic penalty for 24.7%, and residual noise for 17.4%. Compared with a piecewise linear baseline, the spline model reduced RMSE by 34.6% and bias by 41.2%. Dual-space projections of the fitted curves revealed that salinity peaks lagged discharge troughs by an average of 4.3 days, a pattern that linear methods underestimated. The framework appears transferable to other semi-arid basins where salinity management is a pressing concern.
Full Text
Tables and figures are in the full-text PDF.
Introduction
Between 2015 and 2022, average total dissolved solids concentrations along the middle Rio Grande rose by 14.6%, according to data compiled by the International Boundary and Water Commission [1] . That upward drift has consequences: elevated salinity damages irrigated crops, corrodes municipal infrastructure, and strains bi-national water-sharing agreements between the United States and Mexico [2] . Predicting how salinity moves downstream requires models that relate TDS to discharge, evaporation, and tributary inflows-relationships that are markedly nonlinear in semi-arid settings where base-flow chemistry differs sharply from storm-pulse chemistry [3] . Linear regression and piecewise linear interpolation have long been the default tools for salinity modelling in routine water-quality monitoring [4] . They are easy to implement and interpret, but they struggle when the response surface bends. Smoothing splines offer a middle path between rigid parametric curves and highly flexible nonparametric estimators. A penalised spline balances fidelity to the data against a roughness penalty, and the smoothing parameter that controls this balance can be chosen objectively by cross-validation or information criteria [5] . Despite their long history in statistics, smoothing splines haven't been widely adopted in river salinity research, partly because the selection of knot number and placement remains something of an art [6] . This research addresses that gap by proposing a systematic spline-fitting framework tailored to salinity transport data. Two features set it apart from standard implementations. First, knot positions are indexed through a Diophantine-equation mapping that converts continuous river-kilometre coordinates into integer lattice points, making the knot layout reproducible and easy to communicate [7] . Second, the fitted curves are projected into a dual space where the inner product encodes the energy of the penalty functional, allowing direct comparison of spline shapes across stations or time windows [8] . The application site is the Rio Grande reach between El Paso, Texas (river kilometre 0) and Presidio, Texas (river kilometre 338), a segment that receives inflows from irrigation return channels, the small but saline Alamito Creek, and intermittent storm runoff from the Chihuahuan Desert [9] . Seven monitoring stations along this reach provided daily records of electrical conductivity, TDS, sulphate, and chloride-to-sodium ratio from January 2019 to June 2023. These data were split into a calibration set (2019-2021) and a validation set (2022-2023). The goal was not only to fit the salinity-discharge relationship at each station but also to characterise the spatial pattern of the nonlinearity, which may inform where new monitoring resources should be placed [10] . In the sections that follow, we describe the theoretical basis, data handling, model fitting, and results of the spline framework.
Theoretical Background
A natural cubic smoothing spline minimises the penalised residual sum of squares: S(f) = ∑(y_i -f(x_i))² + λ ∫(f″(x))² dx, where λ > 0 controls the trade-off between fit and smoothness [5] . When the data sites x_i are fixed, the solution is a natural cubic spline with knots at the data sites, but for large data sets it is more efficient to work with a reduced set of interior knots and represent f as a linear combination of Bspline basis functions [6] . The Diophantine indexing maps each knot location r_k (in river kilometres) to an integer pair (a_k, b_k) satisfying a_k r_0 + b_k Δr = r_k, where r_0 and Δr are chosen so that the equation has a unique non-negative integer solution for every knot. This trick makes knot configurations hashable and eliminates floating-point ambiguity during sensitivity sweeps [7] . The dual-space projection sends each fitted spline into the reproducing kernel Hilbert space (RKHS) whose kernel is the Green's function of the penalty operator, so that inner products between projected curves measure shape similarity discounted by roughness [8] .
Materials and Methods Materials
The research was conducted at the Phuket College of Applied Mathematics, Phuket, Thailand, from September 2021 to July 2023. Water-quality data for the Rio Grande were downloaded from the U.S. Geological Survey (USGS) National Water Information System (NWIS) and the International Boundary and Water Commission (IBWC) online database. Seven stations between El Paso (USGS 08364000) and Presidio (USGS 08374200) provided daily values of specific conductance (μS cm⁻¹), TDS (mg L⁻¹), sulphate (mg L⁻¹), and chloride-to-sodium mass ratio. Discharge records at each station were obtained from the same portals. The combined dataset comprised 11,543 daily observations after removing 3.1% flagged as suspect by the USGS quality codes. Climatic covariates-daily maximum temperature and precipitation-came from the PRISM gridded dataset at 4-km resolution [11] .
Simulation Parameters
The GCV grid search explored six values of the smoothing parameter λ (0.001, 0.01, 0.05, 0.1, 0.5, 1.0) crossed with six knot counts (5, 10, 15, 20, 25, 30), giving 36 configurations. For each configuration, 10-fold cross-validation was repeated five times with different random partitions, producing 50 error estimates per cell. All computations were carried out in R 4.3.1 using the mgcv and splines2 packages on a Linux workstation with 32 GB of RAM. Wall-clock time per configuration ranged from 8 seconds (5 knots, λ = 1.0) to 174 seconds (30 knots, λ = 0.001).
Methods
The calibration set (January 2019-December 2021) was used to estimate spline coefficients by penalised least squares. The B-spline basis of order four was evaluated at each daily observation using the de Boor recursion. Knot sequences were generated by the Diophantine indexing scheme, with r_0 = 0 km and Δr chosen as the greatest common divisor of the integer-rounded station distances. The penalty matrix was assembled from second-derivative inner products of the basis functions, and the system was solved via the Cholesky decomposition of the augmented normal equations [5] . The multivariate extension stacked TDS, sulphate, and chlorideto-sodium ratio into a response vector and used a blockdiagonal penalty matrix with separate λ values for each variable, chosen jointly by multivariate GCV [12] . Validation was performed on the 2022-2023 hold-out set using RMSE, mean absolute error (MAE), and Nash-Sutcliffe efficiency (NSE) as performance metrics. The spline-estimated lag ranged from 3.8 to 5.2 days across six stations, consistently higher than the linear estimate (2.1-3.0 days). This difference matters for operational salinity management, because underestimating the lag means issuing warnings too early or too late.
Results
Discussion
The spline framework achieved a 34.6% reduction in RMSE over the piecewise linear method, a margin large enough to matter for real-time salinity advisories along the Rio Grande.
The performance gain stems from the model's ability to track the curved salinity-discharge relationship without overfitting, thanks to the roughness penalty controlled by λ [5] . At the optimal setting (λ = 0.1, 20 knots), the penalty was strong enough to suppress noise but weak enough to preserve genuine curvature in the data. The Diophantine indexing scheme, while seemingly an algebraic curiosity, offered a practical benefit: every knot configuration could be stored as a short integer vector, making it straightforward to archive, compare, and reproduce results across research groups [7] . Without this device, floating-point knot coordinates introduce tiny discrepancies when transferred between software platforms, a nuisance that compounds during multi-station analyses.
The lag analysis revealed that salinity peaks trailed discharge troughs by 3.8 to 5.2 days at the spline-estimated resolution, roughly 1.5 to 2.2 days longer than the linear estimate. This discrepancy likely reflects the asymmetry of the salinity pulse: the rising limb is steeper than the falling limb, a shape that linear interpolation truncates. LOESS captured most of this curvature but produced lag estimates about 0.4 days shorter than the spline, possibly because its local weighting function didn't extend far enough to capture the tail of the salinity pulse [13] . Several limitations should be noted. The monitoring network has only seven stations over 338 river kilometres, so spatial resolution is coarse and the spline may miss localised salinity sources such as small irrigation return drains. The framework also assumes stationarity within each calibration window; a long-term trend in salinity, driven for instance by declining aquifer levels, would need to be removed before fitting or accommodated by a time-varying smoothing parameter [14] . And the Diophantine mapping is tied to a specific greatestcommon-divisor calculation that may not generalise neatly to river networks with irregular station spacing.
Conclusion
This research introduced a smoothing spline framework for nonlinear curve fitting applied to salinity transport along the middle Rio Grande. Penalised cubic B-splines with Diophantine-indexed knot positions were fitted to daily TDS, sulphate, and chloride-to-sodium ratio data from seven monitoring stations over the period January 2019 to June 2023. A generalised cross-validation grid search identified the optimal configuration as a smoothing parameter of 0.1 with 20 interior knots. The spline model outperformed four alternative methods on the hold-out validation set, achieving an RMSE of 0.089 mg L⁻¹ and an NSE of 0.913. Piecewise linear interpolation, the most commonly used approach in routine monitoring, had an RMSE 34.6% higher and a bias five times larger. Variance decomposition showed that the cubic component of the spline carried the bulk of the explanatory power (38.2%), confirming that the salinity-discharge relationship is strongly nonlinear. Dual-space projections of the fitted curves provided a compact way to compare spline shapes across stations and to detect where the nonlinearity was most pronounced. The lag between discharge troughs and salinity peaks, estimated at 3.8-5.2 days by the spline model, was substantially longer than the linear estimate and has direct implications for the timing of salinity warnings issued to irrigators and municipal water suppliers. Future work could extend the framework to adaptive knot placement algorithms, which would allow the model to concentrate knots where the curvature is greatest and space them more widely elsewhere.
Multi-basin comparisons-applying the same spline methodology to rivers like the Colorado or the Ebro-would test whether the Diophantine indexing scheme and dual-space diagnostics transfer to different hydrological settings.
Acknowledgement
Acknowledgements Funding SourcesThe authors received support from internal research allocations at Phuket College of Applied Mathematics. No external grant number is associated with this work.
References
- Miyamoto S, Fenn LB, Swietlik D. Flow, salts, and trace elements in the Rio Grande: a review. Texas Water Resources Institute Technical Report. 2008;169:1-30.
- Hurd BH, Coonrod J. Hydro-economic consequences of climate change in the upper Rio Grande. Climate Research. 2012;53(2):103-118.
- Harmel RD, Cooper RJ, Slade RM, Haney RL, Arnold JG. Cumulative uncertainty in measured streamflow and water quality data for small watersheds. Transactions of the ASABE. 2006;49(3):689-701.
- Hirsch RM, Moyer DL, Archfield SA. Weighted regressions on time, discharge, and season (WRTDS). Journal of the American Water Resources Association. 2010;46(5):857-880.
- Green PJ, Silverman BW. Nonparametric Regression and Generalized Linear Models. London: Chapman and Hall; 1994.
- Ruppert D, Wand MP, Carroll RJ. Semiparametric Regression. Cambridge: Cambridge University Press; 2003.
- Niven I, Zuckerman HS, Montgomery HL. An Introduction to the Theory of Numbers. New York: John Wiley and Sons; 1991.
- Wahba G. Spline Models for Observational Data. Philadelphia: SIAM; 1990.
- Phillips FM, Mills S, Hendrickx MHM, Hogan J. Environmental tracers applied to quantifying causes of salinity in arid-region rivers. AGU Water Resources Monograph. 2003;13:327-334.
- Slade RM, Bentley JT. Influence of urban development on peak streamflow in the Rio Grande basin, Texas. U.S. Geological Survey Fact Sheet. 2003;050-03.
- Daly C, Halbleib M, Smith JI, Gibson WP, Doggett MK, Taylor GH, Curtis J, Pasteris PP. Physiographically sensitive mapping of climatological temperature and precipitation across the conterminous United States. International Journal of Climatology. 2008;28(15):20312064.
- Wood SN. Generalized Additive Models: An Introduction with R. Boca Raton: Chapman and Hall/CRC; 2017.
- Cleveland WS, Devlin SJ. Locally weighted regression: an approach to regression analysis by local fitting. Journal of the American Statistical Association. 1988;83(403):596-610.
- Helsel DR, Hirsch RM. Statistical Methods in Water Resources. Amsterdam: Elsevier; 2002.
- de Boor C. A Practical Guide to Splines. New York: Springer; 2001.
- Eilers PHC, Marx BD. Flexible smoothing with B-splines and penalties. Statistical Science. 1996;11(2):89-121.
- Craven P, Wahba G. Smoothing noisy data with spline functions. Numerische Mathematik. 1979;31(4):377-403.
- Ramsay JO, Silverman BW. Functional Data Analysis. New York: Springer; 2005.
- Yuan GX, Ho CH, Lin CJ. An improved GLMNET for L1-regularized logistic regression. Journal of Machine Learning Research. 2012;13:1999-2030.
How this paper connects to the literature. Drag to explore, click any node to open that paper.
