46  Nonlinear Regression

Polynomial regression bends a line by adding powers of \(X\), but it is still, underneath, a linear model: linear in its coefficients, fit by ordinary least squares. Some relationships cannot be written that way at all. Nonlinear regression covers the broader class of curves where the coefficients themselves enter the equation nonlinearly, most commonly through exponential, logarithmic, or power functions:

  • Exponential: \(Y = a \, e^{bX}\)
  • Logarithmic: \(Y = a + b \ln(X)\)
  • Power: \(Y = a X^{b}\)

These show up constantly in agricultural science: pesticide residues decay exponentially after application, crop biomass often follows a logistic-style saturation curve over the growing season, and reaction rates in soil chemistry frequently follow a power law.

46.1 Fitting a Nonlinear Model

Because the relationship is not linear in its parameters, ordinary least squares does not directly apply. Nonlinear least squares (in R, the nls() function) instead searches iteratively for the parameter values that minimize the sum of squared residuals, starting from an initial guess and refining it step by step. This means a starting guess is required for each parameter, and a poor starting guess can occasionally cause the search to fail to converge, unlike a polynomial or linear model where the solution is found in one step.

46.2 Worked Example

After an insecticide is sprayed on a standing crop, its residue level declines over time until it eventually falls below the maximum residue limit set for that crop, the threshold that determines the pre-harvest interval (the minimum number of days that must pass before the crop can be safely harvested). A field trial measured residue levels on ten separate days after spraying.

Days Since Spray Residue Level (ppm)
0 10.0
2 7.4
4 5.5
6 4.1
8 3.0
10 2.2
12 1.7
14 1.2
16 0.9
18 0.7
20 0.5

The pattern is a classic exponential decay: residue falls by roughly the same proportion every two days rather than by the same fixed amount, which rules out a straight line and points toward the exponential form \(Y = a \, e^{-bX}\).

46.3 Nonlinear Regression in R

46.4 Reading the Result

The parameter \(a\) is the estimated residue level at the moment of spraying, day zero, which should land close to 10 ppm given how the trial was set up. The parameter \(b\) is the decay rate: a larger \(b\) means the residue clears faster. Once both parameters are estimated, the model can be solved for the day on which residue is expected to fall to any chosen safety threshold, which is exactly the calculation a regulator or an exporter needs when setting a pre-harvest interval. This is a case where the nonlinear model is not just a better statistical fit than a straight line, it is the only form that produces a sensible answer, since a linear fit would eventually predict negative residue levels, which is meaningless.


Summary

Concept Description
Foundations
Nonlinear Regression Models where the parameters enter nonlinearly, not reducible to a polynomial fit by least squares
Common Nonlinear Forms Exponential, logarithmic, and power forms cover most nonlinear relationships seen in agricultural data
Fitting with nls() R's nls() searches iteratively from a starting guess to minimize squared residuals
Worked Example
Worked Example: Pesticide Residue Decay Insecticide residue declining exponentially over 20 days after spraying, fit with a * exp(-b * days)
Solving for a Threshold Once a and b are estimated, the fitted equation can be solved for the day residue drops below a safety limit