Nonlinear regression

Nonlinear regression (nls) for mechanistic models

When the equation comes from the mechanism — a saturating enzyme, an exponential decay, a logistic growth — the right model is nonlinear and its parameters mean something. Magic Stat fits these by nonlinear least squares with the same optimum and standard errors as R's nls, and lets you write your own equation when none of the built-in ones fits.

The honest part

Nonlinear least squares needs a model worth fitting

Nonlinear regression fits a model whose parameters enter the equation in a nonlinear way — Vmax and Km in Michaelis–Menten, or a rate and a scale in an exponential. The estimates are found by iterative search rather than in one algebraic step, and they come with standard errors, t statistics and confidence intervals, under the same asymptotic theory used by R's nls.

The catch is identifiability and starting values. A model whose parameters trade off against each other has no single well-defined optimum, and a poor starting point can send the search off. Magic Stat uses the same starting values as R's selfStart for each built-in model, and if the requested start fails it will try sensible alternatives rather than return nothing — but a model that is not supported by the data can still fail, and that is a real result.

The model comparison numbers — AIC and BIC — are computed in R's convention, so two models fitted to the same data can be compared on equal footing.

What it does

What Magic Stat gives you for nonlinear regression

How it works

Choose the model, fit the curve

  1. Load the data. the predictor and the outcome as columns.
  2. Choose Nonlinear Regression (nls). Statistics → Nonlinear Regression (nls).
  3. Select the model. a built-in mechanistic form, or Custom to write your own equation.
  4. Fit. estimates, standard errors and AIC/BIC come out with the fitted curve.
  5. Export. the curve to the gallery, the analysis to the report.
Options

The settings, in the dialog

Models: Michaelis–Menten (Vm·x/(K+x)) · Exponential (a·e^(b·x)) · Asymptotic (Asym+(R0−Asym)·e^(−e^lrc·x)) · Logistic (Asym/(1+e^((xmid−x)/scal))) · Power (a·x^b).

Custom formula: write the equation yourself — e.g. y = c + A*sin(2*pi*t/12 + phi) — using the selected columns as variables; free symbols become fitted parameters.

Frequently asked

Nonlinear regression questions, answered honestly

How do I choose the model?

From the mechanism. Michaelis–Menten for saturation, exponential for growth or decay, logistic for S-shaped growth, power for scaling. If no mechanistic form applies, a polynomial or a custom equation is the more honest route.

What if the fit does not converge?

It usually means poor starting values or a model the data cannot support. Magic Stat tries the standard start and, if that fails, alternative starts. If it still fails, the parameters are not identifiable from your data — a genuine answer, not a software bug.

How does this differ from polynomial regression?

A polynomial is flexible but its coefficients have no mechanistic meaning. A nonlinear model encodes the process, so parameters such as a rate or a half-saturation constant can be reported and interpreted. Use the nonlinear model when you have the equation.

Do I need R?

No. R's nls is the reference these results are built to match. If you need specialised variance structures or weights beyond what is here, R's modelling framework remains the broader tool.

Is my data uploaded somewhere?

No. Everything runs on your machine. The only automatic signal is an anonymous installation counter.

Polynomial regression → Linear regression → GAM analysis →