Nonlinear regression explained, with a curing example

Updated

Nonlinear regression fits an equation whose parameters enter in a nonlinear way, such as y = θ₁(1 − e^(−θ₂x)), to data by least squares. You choose the form of the curve from physics or experience; the fit finds the parameter values, their standard errors and the residual spread. The parameters usually mean something physical, like an ultimate strength or a rate constant, which is the main reason to use it instead of a polynomial.

When to use it

  • The response rises or falls toward a plateau: adhesive strength while curing, temperature of a part cooling in air, moisture loss in a dryer.
  • You know a theoretical form (Arrhenius, Michaelis–Menten, a power law with an offset) and want its parameters.
  • A polynomial fits the data you have but behaves badly beyond them, or its coefficients mean nothing.
  • You need a derived quantity, such as the time to reach 90% of full strength, with an interval.

If the model is linear in its parameters (a straight line, a polynomial, or a sum of known functions of x), use regression analysis or a fitted line plot: they need no starting values and give exact answers.

How it works

A model is nonlinear when at least one parameter is not just a multiplier of something you can compute from x. In y = θ₁(1 − e^(−θ₂x)), θ₂ sits inside the exponential, so there is no formula for the least-squares solution. The fit works by iteration:

  1. You supply starting values for every parameter, from a plot or from physics.
  2. The Gauss–Newton method replaces the curve with a straight-line approximation around the current values, using the matrix J of partial derivatives of the model with respect to each parameter, and solves that linear least-squares problem for a correction:
θ(new) = θ + (JᵀJ)⁻¹ Jᵀ (y − f(x, θ))
  1. It repeats until the sum of squared errors (SSE) stops changing. Practical programs add a safeguard, such as step halving or the Levenberg–Marquardt method, so a poor step cannot make the fit worse.

At convergence the method reports, with n points and p parameters:

S = √(SSE / (n − p)) SE(θⱼ) = S · √[(JᵀJ)⁻¹]ⱼⱼ

The usual 95% intervals, θ ± t · SE with n − p degrees of freedom, rest on the same linear approximation, so they are approximate. They work well when the curve is close to straight over the region the parameters can move in, and less well with few points or strongly curved models. Profile-likelihood intervals are more accurate in those cases.

Unlike linear regression, R² is not reliable for nonlinear models, because the usual split of the total sum of squares does not hold. Judge the fit by S and by the residual plots.

Example

A lab qualifies a structural adhesive. Lap-shear coupons are bonded, cured at room temperature and pulled at 2-hour intervals. Shear strength (MPa):

Cure time (h)24681012141618202224
Strength (MPa)4.48.29.212.713.414.315.115.716.617.517.718.0

Strength should approach a plateau, so the engineer fits the model:

Strength = θ₁ · (1 − e^(−θ₂ · time))

θ₁ is the fully cured strength and θ₂ the cure rate per hour. Starting values: θ₁ = 18 (the largest reading) and θ₂ = 0.1. Gauss–Newton converges in five iterations:

ParameterEstimateSEApproximate 95% CI
θ₁ (MPa)18.5790.42317.636 to 19.523
θ₂ (1/h)0.128560.008030.11066 to 0.14646

S = 0.505 MPa with 10 degrees of freedom (t = 2.228). A straight line through the same points has S = 1.485 MPa, three times larger.

Cure time (h)24681012141618202224
Fitted (MPa)4.217.479.9911.9413.4414.6115.5116.2016.7417.1617.4817.73
Residual0.190.73−0.790.76−0.04−0.31−0.41−0.50−0.140.340.220.27
Lap-shear strength during cure, measured and fitted51015Shear strength (MPa)MeasuredFitted2610141822Cure time (h)
Lap-shear strength during cure, measured and fitted

The production question is when parts can be handled at 90% of full strength. From the model, t₉₀ = ln(10)/θ₂ = 17.9 h. Propagating the parameter uncertainty (the delta method) gives a standard error of 1.12 h and an approximate 95% interval of 15.4 to 20.4 h, so the plant sets the handling time at 21 h.

How to read the results

  • Read the parameters as physics. θ₁ = 18.6 MPa is the strength the adhesive is heading for; the data stop at 18.0 MPa, so the fit extrapolates a little, and its interval (±0.94 MPa) shows by how much.
  • Check the residuals. They stay within about ±0.8 MPa with no clear trend. There is a stretch of five negative residuals from 10 to 18 h, but a runs test on the signs finds 5 runs where 7 are expected (p ≈ 0.23), which is common by chance. A long run of positives at the start and negatives at the end would mean the true curve has a different shape, such as an S-curve with a slow start.
  • Watch the parameter correlation. Here θ₁ and θ₂ have a correlation of −0.89: a slightly higher plateau with a slightly slower rate fits almost as well. Longer cure times in the test would separate them.
  • Treat the intervals as approximate. With 12 points and a smooth curve, the linear approximation is reasonable; with five points it may not be.

Common mistakes

  • Poor starting values. Far from the answer, Gauss–Newton can diverge or settle on a local minimum. Plot the data and read rough values off the plot.
  • Choosing a form with too many parameters. A four-parameter curve fitted to eight points can converge to meaningless values with huge standard errors.
  • Reporting R². It can look high for a bad nonlinear fit. Report S and show the residuals.
  • Ignoring changing spread. If the scatter grows with the response, least squares gives too much weight to the noisy points; consider weights or a transformation.
  • Extrapolating the plateau. If the test ends long before the curve flattens, the plateau estimate depends almost entirely on the assumed form.

Frequently asked questions

What is the difference between linear and nonlinear regression?

Linearity refers to the parameters, not the shape of the curve. y = b₀ + b₁x + b₂x² is curved but linear in b₀, b₁ and b₂, so ordinary least squares solves it directly. y = θ₁(1 − e^(−θ₂x)) is nonlinear in θ₂ and needs iteration.

Why did my nonlinear regression not converge?

Usually because of starting values far from the solution, a model that the data cannot support (too many parameters, or no data where the curve bends), or parameters on very different scales. Try better starting values, a simpler model or rescaled units.

Can I linearize the model instead?

Sometimes: taking logs turns y = a·e^(bx) into a straight line. But the log also changes how the errors behave, so the estimates differ from a nonlinear fit. Use the transformation only if the scatter is multiplicative.

How do I get a confidence interval for a derived quantity?

Use the delta method, as in the example, or refit the model with that quantity as a parameter (here, writing the model in terms of t₉₀ instead of θ₂) so the fit reports its standard error directly.

Try it with your own data

StatLab SPC is free, open-source statistics for engineers. It runs in your browser, works offline, and never uploads your data.

Open StatLab