| Statistics Toolbox™ | ![]() |
b = nlinfit(X,y,fun,b0)
[b,r,J,COVB,mse] = nlinfit(X,y,fun,b0)
[...] = nlinfit(X,y,fun,b0,options)
b = nlinfit(X,y,fun,b0) returns a p-by-1 vector b of coefficient estimates for a nonlinear regression of the responses in y on the predictors in X using the model specified by fun. X is an n-by-p matrix of p predictors at each of n observations. y is an n-by-1 vector of observed responses. fun is a function handle, specified using the @ sign (as in @myfun) to a function of the form
yhat = myfun(b,X)
where b is a coefficient vector. b0 is a vector containing initial values for the coefficients.
[b,r,J,COVB,mse] = nlinfit(X,y,fun,b0) returns the fitted coefficients b, the residuals r, the Jacobian J of fun, the estimated covariance matrix COVB for the fitted coefficients, and an estimate mse of the variance of the error term. You can use these outputs with nlpredci to produce error estimates on predictions, and with nlparci to produce error estimates on the estimated coefficients. If you use the robust fitting option (see below), you must use COVB and may need mse as input to nlpredci or nlparci to insure that the confidence intervals take the robust fit properly into account.
[...] = nlinfit(X,y,fun,b0,options) specifies control parameters for the algorithm used in nlinfit. options is a structure created by a call to statset. Applicable statset parameters are:
'MaxIter' — Maximum number of iterations allowed. The default is 100.
'TolFun' — Termination tolerance on the residual sum of squares. The defaults is 1e-8.
'TolX' — Termination tolerance on the estimated coefficients b. The default is 1e-8.
'Display' — Level of display output during estimation. The choices are
'off' (the default)
'iter'
'final'
'DerivStep' — Relative difference used in finite difference gradient calculation. May be a scalar, or the same size as the parameter vector b0. The default is eps^(1/3).
'FunValCheck' — Check for invalid values, such as NaN or Inf, from the objective function. Values are 'off' or 'on' (the default).
'Robust' — Invoke robust fitting option. Values are 'off' (the default) or 'on'.
'WgtFun' — A weight function for robust fitting. Valid only when 'Robust' is 'on'. It can be 'bisquare' (the default), 'andrews', 'cauchy', 'fair', 'huber', 'logistic', 'talwar', or 'welsch'. It can also be a function handle that accepts a normalized residual as input and returns the robust weights as output.
'Tune' — The tuning constant used in robust fitting to normalize the residuals before applying the weight function. The value is a positive scalar, with the default value dependent on the weight function. This parameter is required if the weight function is specified as a function handle.
Note Robust nonlinear fitting uses an algorithm that iteratively reweights response values and recomputes a least-squares fit. The least-squares component of the algorithm differs from linear least squares, but the reweighting loop is identical to that for robust linear methods. In particular, the weight function and its tuning parameter are the same as described for robustfit. Note that nlinfit counts iterations of both the reweighting loop and the least-squares fit toward the maximum number of iterations. |
nlinfit treats NaNs in y or fun(b,X) as missing data and ignores the corresponding rows.
nlintool is a graphical user interface to nlinfit.
The data in reaction.mat are partial pressures of three chemical reactants and the corresponding reaction rates. The function hougen implements the nonlinear Hougen-Watson model for reaction rates. The following fits the model to the data:
load reaction
betahat = nlinfit(reactants,rate,@hougen,beta)
betahat =
1.2526
0.0628
0.0400
0.1124
1.1914[1] Seber, G. A. F., and C. J. Wild, Nonlinear Regression, John Wiley & Sons Inc., 1989.
![]() | net | nlintool | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |