NonlinearModelFit
✖
NonlinearModelFit
constructs a nonlinear model with formula form that fits the yi for each xi using the free parameters βi.
constructs a nonlinear model where form depends on the variables xk.
constructs a nonlinear model subject to the parameter constraints cons.
Details and Options




- NonlinearModelFit attempts to model the input data using a general mathematical formula with free parameters.
- NonlinearModelFit produces a nonlinear model of the form
under the assumption that the original
are independent normally distributed with mean
and common standard deviation.
- NonlinearModelFit returns a symbolic FittedModel object to represent the nonlinear model it constructs. The properties and diagnostics of the model can be obtained from model["property"].
- The value of the best-fit function from NonlinearModelFit at a particular point x1, … can be found from model[x1,…].
- The best-fit function from NonlinearModelFit[data,form,pars,vars] is the same as the result from FindFit[data,form,pars,vars].
- NonlinearModelFit[data,form,{{β1,val1},…},vars] starts the search for a fit with {β1->val1,…}.
- Possible forms of data are:
-
{y1,y2,…} equivalent to the form {{1,y1},{2,y2},…} {{x11,x12,…,y1},…} a list of independent values xij and the responses yi {{x11,x12,…}y1,…} a list of rules between input values and response {{x11,x12,…},…}{y1,y2,…} a rule between a list of input values and responses {{x11,…,y1,…},…}n fit the n column of a matrix
Tabular[…]name fit the column name in a tabular object - With multivariate data such as
, the number of coordinates xi1, xi2, … should equal the number of variables xi.
- The data points can be approximate real numbers. Uncertainty can be specified using Around.
- NonlinearModelFit takes the following options:
-
AccuracyGoal Automatic the number of digits of accuracy sought ConfidenceLevel 95/100 confidence level for parameters and predictions EvaluationMonitor None expression to evaluate whenever form is evaluated Gradient Automatic the list of gradient components for form MaxIterations Automatic maximum number of iterations to use Method Automatic method to use PrecisionGoal Automatic the precision sought StepMonitor None the expression to evaluate whenever a step is taken VarianceEstimatorFunction Automatic function for estimating the error variance Weights Automatic weights for data elements WorkingPrecision Automatic the precision used in internal computations - With ConfidenceLevel->p, probability-p confidence intervals are computed for parameter and prediction intervals.
- With the setting Weights->{w1,w2,…}, the error variance for yi is assumed to be proportional to
.
- With the setting Weights->Automatic, the weights will be set to 1 if the data contains exact values. If the data contains Around values, the weights will be set to
, with
the total response variance.
- The total response variance
is a function of the initial response variance Δyi2 and the independent values variance
.
- The uncertainties
are propagated through the model using AroundReplace, and the resulting variance is added to response variance Δyi2. The function FindRoot is used internally to find a self-consistent solution according to the Fasano and Vio method.
- With the setting VarianceEstimatorFunction->f, the common variance is estimated by f[res,w], where res={y1-
,y2-
,…} is the list of residuals and w is the list of weights.
- Using VarianceEstimatorFunction->(1&) and Weights->{1/Δy12,1/Δy22,…}, Δyi is treated as the known uncertainty of measurement yi, and parameter standard errors are effectively computed only from the weights.
- Possible settings for Method include:
-
"ConjugateGradient" nonlinear conjugate gradient "Gradient" gradient descent "LevenbergMarquardt" Gauss–Newton method for least squares "Newton" Newton method "QuasiNewton" quasi-Newton BFGS "InteriorPoint" interior point method "NMinimize" use NMinimize for optimization Automatic automatic default method - Additional method suboptions can be given in the form Method->{…,opts}.
- The Method option can take any local optimization method as specified in the tutorial Unconstrained Optimization: Methods for Local Minimization. »
- Any global optimization method can be specified as a submethod to the "NMinimize" method. They can be found in the Numerical Algorithms for Constrained Global Optimization tutorial. »
- For constrained models, properties based on approximate normality assumptions may not be valid. When such values are computed, the values are generated along with a warning message.
- Properties related to data and the fitted function using model["property"] include:
-
"BestFit" fitted function "BestFitParameters" parameter estimates "Data" the input data or design matrix and response vector "Function" best-fit pure function "Response" response values in the input data "Weights" weights used to fit the data - Types of residuals include:
-
"FitResiduals" difference between actual and predicted responses "StandardizedResiduals" fit residuals divided by the standard error for each residual "StudentizedResiduals" fit residuals divided by single deletion error estimates - Properties related to the sum of squared errors include:
-
"ANOVA" analysis of variance data "EstimatedVariance" estimate of the error variance - Properties and diagnostics for parameter estimates include:
-
"CorrelationMatrix" asymptotic parameter correlation matrix "CovarianceMatrix" asymptotic parameter covariance matrix "ParameterEstimates" table of fitted parameter information "ParameterBias" estimated bias in the parameter estimates "ParameterConfidenceRegion" ellipsoidal parameter confidence region - Properties for curvature diagnostics include:
-
"CurvatureConfidenceRegion" confidence region for curvature diagnostics "FitCurvature" table of fit curvature information "MaxIntrinsicCurvature" measure of maximum intrinsic curvature "MaxParameterEffectsCurvature" measure of maximum parameter effects curvature - Properties related to influence measures include:
-
"HatDiagonal" diagonal elements of the hat matrix "SingleDeletionVariances" list of variance estimates with the data point omitted
- Properties of predicted values include:
-
"MeanPredictionBands" confidence bands for mean predictions "MeanPredictions" confidence intervals for the mean predictions "PredictedResponse" fitted values for the data "SinglePredictionBands" confidence bands based on single observations "SinglePredictions" confidence intervals for the predicted response of single observations - Properties that measure goodness of fit include:
-
"AdjustedRSquared" adjusted for the number of model parameters
"AIC" Akaike Information Criterion "AICc" finite sample corrected AIC "BIC" Bayesian Information Criterion "RSquared" coefficient of determination
Options
Properties
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
Fit a nonlinear model to some data:

https://wolfram.com/xid/0bzrhw01segbnw4ng-fr8gq2

https://wolfram.com/xid/0bzrhw01segbnw4ng-ito2gu


https://wolfram.com/xid/0bzrhw01segbnw4ng-i19ql9

Evaluate the model at a point:

https://wolfram.com/xid/0bzrhw01segbnw4ng-cy4qr5

Visualize the fitted function with the data:

https://wolfram.com/xid/0bzrhw01segbnw4ng-ky8uld

Extract and plot the residuals:

https://wolfram.com/xid/0bzrhw01segbnw4ng-o0cv4


https://wolfram.com/xid/0bzrhw01segbnw4ng-jxmybb

Scope (15)Survey of the scope of standard use cases
Data (7)
Fit a model of one variable, assuming increasing integer-independent values:

https://wolfram.com/xid/0bzrhw01segbnw4ng-hf4cmk

Fit a model of more than one variable:

https://wolfram.com/xid/0bzrhw01segbnw4ng-bvlb1y

https://wolfram.com/xid/0bzrhw01segbnw4ng-dco39z


https://wolfram.com/xid/0bzrhw01segbnw4ng-d3u3zn


https://wolfram.com/xid/0bzrhw01segbnw4ng-n6f6mz

Fit a rule of input values and responses:

https://wolfram.com/xid/0bzrhw01segbnw4ng-jqt9yr

Specify a column as the response:

https://wolfram.com/xid/0bzrhw01segbnw4ng-ccidut

Give starting values when parameters are far from the default value 1:

https://wolfram.com/xid/0bzrhw01segbnw4ng-c1p3pj

https://wolfram.com/xid/0bzrhw01segbnw4ng-o9latu


https://wolfram.com/xid/0bzrhw01segbnw4ng-idjus

With the default starting values, the model is effectively 0:

https://wolfram.com/xid/0bzrhw01segbnw4ng-ybfg4


https://wolfram.com/xid/0bzrhw01segbnw4ng-hj2clp

Obtain a list of available properties for a nonlinear model:

https://wolfram.com/xid/0bzrhw01segbnw4ng-haavoo


https://wolfram.com/xid/0bzrhw01segbnw4ng-hmjjxg

Properties (8)
Data & Fitted Functions (1)

https://wolfram.com/xid/0bzrhw01segbnw4ng-hu5oz

https://wolfram.com/xid/0bzrhw01segbnw4ng-fj8t12


https://wolfram.com/xid/0bzrhw01segbnw4ng-na9fdf


https://wolfram.com/xid/0bzrhw01segbnw4ng-btkjeg

Obtain the fitted function as a pure function:

https://wolfram.com/xid/0bzrhw01segbnw4ng-2573y

Residuals (1)

https://wolfram.com/xid/0bzrhw01segbnw4ng-c96hoj

https://wolfram.com/xid/0bzrhw01segbnw4ng-e4h1qz


https://wolfram.com/xid/0bzrhw01segbnw4ng-c6mebv

https://wolfram.com/xid/0bzrhw01segbnw4ng-iyrir

Visualize scaled residuals in stem plots:

https://wolfram.com/xid/0bzrhw01segbnw4ng-fc0pug

Plot the absolute differences between the standardized and Studentized residuals:

https://wolfram.com/xid/0bzrhw01segbnw4ng-zwlex

Sums of Squares (1)
Fit a nonlinear model to some data:

https://wolfram.com/xid/0bzrhw01segbnw4ng-bvfu5x

Extract the estimated error variance:

https://wolfram.com/xid/0bzrhw01segbnw4ng-c0a7u8

Obtain the analysis of variance table:

https://wolfram.com/xid/0bzrhw01segbnw4ng-xre76

Get the sums of squares column from the table:

https://wolfram.com/xid/0bzrhw01segbnw4ng-dv5b70

Parameter Estimation Diagnostics (1)
Obtain a formatted table of parameter information:

https://wolfram.com/xid/0bzrhw01segbnw4ng-yeijh

https://wolfram.com/xid/0bzrhw01segbnw4ng-g1mvmy


https://wolfram.com/xid/0bzrhw01segbnw4ng-vvtd9

Extract the column of -statistic values:

https://wolfram.com/xid/0bzrhw01segbnw4ng-m5b3hb

Curvature Diagnostics (1)
Fit a nonlinear model to some data:

https://wolfram.com/xid/0bzrhw01segbnw4ng-dea3ag

Obtain a table of curvature measures for the fitted model:

https://wolfram.com/xid/0bzrhw01segbnw4ng-bh3yuu

Extract the list of numeric values from the table:

https://wolfram.com/xid/0bzrhw01segbnw4ng-66fxz

Extract the max parameter effects curvature value:

https://wolfram.com/xid/0bzrhw01segbnw4ng-2ux26

Influence Measures (1)
Fit some data containing extreme values to a nonlinear model:

https://wolfram.com/xid/0bzrhw01segbnw4ng-dxjd2

Use single deletion variances to check the impact on the error variance of removing each point:

https://wolfram.com/xid/0bzrhw01segbnw4ng-bw2le3

Check the diagonal elements of the hat matrix to assess influence of points on the fitting:

https://wolfram.com/xid/0bzrhw01segbnw4ng-fbslf9

Prediction Values (1)

https://wolfram.com/xid/0bzrhw01segbnw4ng-hzioq

Plot the predicted values against the observed values:

https://wolfram.com/xid/0bzrhw01segbnw4ng-c2gdcw

Obtain tabular results for mean- and single-prediction confidence intervals:

https://wolfram.com/xid/0bzrhw01segbnw4ng-ho9ak9


https://wolfram.com/xid/0bzrhw01segbnw4ng-ietrop

Get the single-prediction intervals from the table:

https://wolfram.com/xid/0bzrhw01segbnw4ng-fhixbf

Extract 99% mean prediction bands:

https://wolfram.com/xid/0bzrhw01segbnw4ng-vx0x8

Generalizations & Extensions (2)Generalized and extended use cases
Fit data to a model defined by a numerical operation:

https://wolfram.com/xid/0bzrhw01segbnw4ng-d7mjw9

https://wolfram.com/xid/0bzrhw01segbnw4ng-jlw8

https://wolfram.com/xid/0bzrhw01segbnw4ng-jq2e9w


https://wolfram.com/xid/0bzrhw01segbnw4ng-b7fqic

Use ParametricNDSolveValue to make the computation much faster by caching solutions of the differential equation:

https://wolfram.com/xid/0bzrhw01segbnw4ng-ghv7u3


https://wolfram.com/xid/0bzrhw01segbnw4ng-f36tv4

Perform other mathematical operations on the functional form of the model:

https://wolfram.com/xid/0bzrhw01segbnw4ng-i4rgx5

Integrate symbolically and numerically:

https://wolfram.com/xid/0bzrhw01segbnw4ng-brsld4


https://wolfram.com/xid/0bzrhw01segbnw4ng-ly2tj7

Find a predictor value that gives a particular value for the model:

https://wolfram.com/xid/0bzrhw01segbnw4ng-pmp2d

Options (10)Common values & functionality for each option
ConfidenceLevel (1)
The default gives 95% confidence intervals:

https://wolfram.com/xid/0bzrhw01segbnw4ng-ecoitr

https://wolfram.com/xid/0bzrhw01segbnw4ng-j4wn3


https://wolfram.com/xid/0bzrhw01segbnw4ng-b58ly3


https://wolfram.com/xid/0bzrhw01segbnw4ng-l2hd6e


https://wolfram.com/xid/0bzrhw01segbnw4ng-qrf46

Set the level to 90% within FittedModel:

https://wolfram.com/xid/0bzrhw01segbnw4ng-ihsmr4

Method (3)
Use the default method for minimizing the least-squares objective function:

https://wolfram.com/xid/0bzrhw01segbnw4ng-y6xuco

Use Newton's method for optimization:

https://wolfram.com/xid/0bzrhw01segbnw4ng-tgll73

Configure the step control method for Newton's algorithm:

https://wolfram.com/xid/0bzrhw01segbnw4ng-i339qo

Use the interior point method with constraints:

https://wolfram.com/xid/0bzrhw01segbnw4ng-64ysmv

Perform a more exhaustive search with the global optimization methods from NMinimize:

https://wolfram.com/xid/0bzrhw01segbnw4ng-tvuiy4

Use the submethod "RandomSearch":

https://wolfram.com/xid/0bzrhw01segbnw4ng-fmqwot

Specify the number of initial search points for the "RandomSearch" algorithm:

https://wolfram.com/xid/0bzrhw01segbnw4ng-b38cit

VarianceEstimatorFunction (1)
Use the default unbiased estimate of error variance:

https://wolfram.com/xid/0bzrhw01segbnw4ng-d4of89

https://wolfram.com/xid/0bzrhw01segbnw4ng-gya2cd


https://wolfram.com/xid/0bzrhw01segbnw4ng-jcrgh

Assume a known error variance:

https://wolfram.com/xid/0bzrhw01segbnw4ng-em28ru

Estimate the variance by the mean squared error:

https://wolfram.com/xid/0bzrhw01segbnw4ng-eykbej

Weights (4)
Fit a model using equal weights:

https://wolfram.com/xid/0bzrhw01segbnw4ng-d74zow

https://wolfram.com/xid/0bzrhw01segbnw4ng-io2mln

Give explicit weights for the data points:

https://wolfram.com/xid/0bzrhw01segbnw4ng-gr7fv

Use Around values to give different weights to data points:

https://wolfram.com/xid/0bzrhw01segbnw4ng-b88ln0


https://wolfram.com/xid/0bzrhw01segbnw4ng-ex1yjq

Find the weights that were used to account for the uncertainty in the data:

https://wolfram.com/xid/0bzrhw01segbnw4ng-ee2z8f

Use Around values in both the independent values and responses:

https://wolfram.com/xid/0bzrhw01segbnw4ng-b8p7lg


https://wolfram.com/xid/0bzrhw01segbnw4ng-ehp5a

In some cases, the root finding algorithm that handles uncertainty in the independent variates does not converge using the standard option settings:

https://wolfram.com/xid/0bzrhw01segbnw4ng-i712o3


Use the FixedPoint algorithm with a low DampingFactor and high MaxIterations to reach convergence:

https://wolfram.com/xid/0bzrhw01segbnw4ng-oifq1n

WorkingPrecision (1)
Use WorkingPrecision to get higher precision in parameter estimates:

https://wolfram.com/xid/0bzrhw01segbnw4ng-olb75


https://wolfram.com/xid/0bzrhw01segbnw4ng-cpb4wl


https://wolfram.com/xid/0bzrhw01segbnw4ng-uefph

Reduce the precision in property computations after the fitting:

https://wolfram.com/xid/0bzrhw01segbnw4ng-cjjn8p

Applications (1)Sample problems that can be solved with this function

https://wolfram.com/xid/0bzrhw01segbnw4ng-iiinqn
Fit a nonlinear model to the data:

https://wolfram.com/xid/0bzrhw01segbnw4ng-fyrh8

Obtain and visualize 90% confidence bands for the fit:

https://wolfram.com/xid/0bzrhw01segbnw4ng-lp2zjz

Obtain 95%, 99%, and 99.9% confidence bands:

https://wolfram.com/xid/0bzrhw01segbnw4ng-hcwlgq
Visualize the confidence bands for the various levels:

https://wolfram.com/xid/0bzrhw01segbnw4ng-l7uyg3

Properties & Relations (5)Properties of the function, and connections to other functions
NonlinearModelFit fits linear and nonlinear models assuming normally distributed errors:

https://wolfram.com/xid/0bzrhw01segbnw4ng-23q98

https://wolfram.com/xid/0bzrhw01segbnw4ng-xyy7q


https://wolfram.com/xid/0bzrhw01segbnw4ng-jw4mzi

LinearModelFit fits linear models assuming normally distributed errors:

https://wolfram.com/xid/0bzrhw01segbnw4ng-hq5ql8

FindFit and NonlinearModelFit fit equivalent models:

https://wolfram.com/xid/0bzrhw01segbnw4ng-f4ja0x

https://wolfram.com/xid/0bzrhw01segbnw4ng-oov7mh


https://wolfram.com/xid/0bzrhw01segbnw4ng-k8uh75


https://wolfram.com/xid/0bzrhw01segbnw4ng-imbp8

NonlinearModelFit allows for extraction of additional information about the fitting:

https://wolfram.com/xid/0bzrhw01segbnw4ng-bdsgz8

NonlinearModelFit assumes normally distributed responses:

https://wolfram.com/xid/0bzrhw01segbnw4ng-mojlid

https://wolfram.com/xid/0bzrhw01segbnw4ng-g4yusx

LogitModelFit assumes binomially distributed responses:

https://wolfram.com/xid/0bzrhw01segbnw4ng-ifep8u


https://wolfram.com/xid/0bzrhw01segbnw4ng-1zgny


https://wolfram.com/xid/0bzrhw01segbnw4ng-d7xe8

The same is true for ProbitModelFit:

https://wolfram.com/xid/0bzrhw01segbnw4ng-e9wuy


https://wolfram.com/xid/0bzrhw01segbnw4ng-dqhfj3


https://wolfram.com/xid/0bzrhw01segbnw4ng-b06stb

NonlinearModelFit will use the time stamps of a TimeSeries as variables:

https://wolfram.com/xid/0bzrhw01segbnw4ng-55rjns

https://wolfram.com/xid/0bzrhw01segbnw4ng-8vunzb


https://wolfram.com/xid/0bzrhw01segbnw4ng-c50i1w

Rescale the time stamps and fit again:

https://wolfram.com/xid/0bzrhw01segbnw4ng-hiel46


https://wolfram.com/xid/0bzrhw01segbnw4ng-7d00cg


https://wolfram.com/xid/0bzrhw01segbnw4ng-emgg00


https://wolfram.com/xid/0bzrhw01segbnw4ng-siexdh

NonlinearModelFit acts pathwise on a multipath TemporalData:

https://wolfram.com/xid/0bzrhw01segbnw4ng-1mqe20

Possible Issues (3)Common pitfalls and unexpected behavior
Distributional assumptions are based upon an unconstrained model:

https://wolfram.com/xid/0bzrhw01segbnw4ng-frkfex

Here the confidence interval for contains points that violate the constraint:

https://wolfram.com/xid/0bzrhw01segbnw4ng-b4mfkg


The coefficient of determination in NonlinearModelFit is calculated with uncorrected data:

https://wolfram.com/xid/0bzrhw01segbnw4ng-vxuola

https://wolfram.com/xid/0bzrhw01segbnw4ng-wrf255

The coefficient of determination:

https://wolfram.com/xid/0bzrhw01segbnw4ng-462hwt

Direct calculation using residuals and data:

https://wolfram.com/xid/0bzrhw01segbnw4ng-mv0odk

Sometimes is defined using centralized data:

https://wolfram.com/xid/0bzrhw01segbnw4ng-f1la5p

Fit data that spans over multiple orders of magnitude:

https://wolfram.com/xid/0bzrhw01segbnw4ng-bjl91a

An exponential fit might appear correct at first glance:

https://wolfram.com/xid/0bzrhw01segbnw4ng-c41j92


https://wolfram.com/xid/0bzrhw01segbnw4ng-hdg3de

But shows significant deviations on a log scale:

https://wolfram.com/xid/0bzrhw01segbnw4ng-1t40hh

This can be addressed by using weights inversely proportional to the variance:

https://wolfram.com/xid/0bzrhw01segbnw4ng-83s7cy


https://wolfram.com/xid/0bzrhw01segbnw4ng-pvn6q1

Wolfram Research (2008), NonlinearModelFit, Wolfram Language function, https://reference.wolfram.com/language/ref/NonlinearModelFit.html (updated 2025).
Text
Wolfram Research (2008), NonlinearModelFit, Wolfram Language function, https://reference.wolfram.com/language/ref/NonlinearModelFit.html (updated 2025).
Wolfram Research (2008), NonlinearModelFit, Wolfram Language function, https://reference.wolfram.com/language/ref/NonlinearModelFit.html (updated 2025).
CMS
Wolfram Language. 2008. "NonlinearModelFit." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/NonlinearModelFit.html.
Wolfram Language. 2008. "NonlinearModelFit." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. https://reference.wolfram.com/language/ref/NonlinearModelFit.html.
APA
Wolfram Language. (2008). NonlinearModelFit. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NonlinearModelFit.html
Wolfram Language. (2008). NonlinearModelFit. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NonlinearModelFit.html
BibTeX
@misc{reference.wolfram_2025_nonlinearmodelfit, author="Wolfram Research", title="{NonlinearModelFit}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/NonlinearModelFit.html}", note=[Accessed: 23-April-2025
]}
BibLaTeX
@online{reference.wolfram_2025_nonlinearmodelfit, organization={Wolfram Research}, title={NonlinearModelFit}, year={2025}, url={https://reference.wolfram.com/language/ref/NonlinearModelFit.html}, note=[Accessed: 23-April-2025
]}