How did I do this analysis for “Peeling the Onion“?

Easy peasy!

1.  I plotted nitrate against log-transformed streamflow and realized that the linear regression I tried a couple years ago doesn’t actually work because the relationship is non-linear, even after log-transforming the data.  The high R-squared and significant p-values were leading me astray because the data is skewed, auto-correlated, and heteroskedastic, violating all the assumptions of the statistical model!

2.   I consulted Chapter 12 of Statistical Methods in Water Resources, which recommended fitting a loess smooth to the explanatory variable (discharge) and running a Mann-Kendall test on the residuals.  In the presence of skewed data, Theil-Sen robust line works better than an OLS best fit line.  Step 1, figure out what that means.  Step 2, figure out how to do it.

3. But first, I plotted the residuals against a moving average of flow in the last 365 days to account for antecedent moisture conditions.  Here I went with a linear regression, but got a poor fit until I realized I needed to include an interaction term in the model.  There’s no relationship between antecedent moisture and flow-adjusted nitrate concentrations when there’s not enough water to flush nitrate out of the soil.  Silly me!

a screen shot of R Studio

4.  I tried to correct for seasonal differences in nitrate concentrations, but realized it didn’t explain much unless you make it really complicated.  The difference between spring (Apr-Jun) and summer  (Jul-Sep) is already explained by lower flow in summer.  The difference between summer and fall (Oct-Dec) is a difference in the shape of the nitrate-flow relationship.  During low flows, nitrate will be higher in fall than summer because of denitrification in the stream.

5.  I spent a long time debugging code to make that three pane graph with model coefficients.

Okay, that was really hard.  I would never have done that if I’d known what I was getting myself into!  However, now that the code is written, it’ll be relatively easy to redo this analysis for other streams in Iowa.

Share via
Copy link