fitnlm
statistics: mdl = fitnlm (X, y, modelfun, beta0)
statistics: mdl = fitnlm (tbl, modelfun, beta0)
statistics: mdl = fitnlm (…, Name, Value)
Fit a nonlinear regression model.
mdl = fitnlm (X, y, modelfun, beta0)
fits the nonlinear regression model y = modelfun
(beta, X) to the response vector y and the
-by- predictor matrix X, starting the iterative fit
from the coefficient vector
beta0, and returns a NonLinearModel object. modelfun is a
function handle @(b, X) returning the fitted responses.
mdl = fitnlm (tbl, modelfun, beta0) takes the
predictors and response from the table tbl; the last column is the
response unless overridden by 'ResponseVar'.
The following Name/Value pairs are accepted:
| Name | Value |
|---|---|
'CoefficientNames' | a cell array of names for the
coefficients (default 'b1', 'b2', …). |
'Weights' | a vector of nonnegative observation weights. |
'ErrorModel' | the error-variance model: 'constant'
(default), 'proportional', or 'combined'. |
'RobustWgtFun' | the name of a robust weight function,
enabling robust fitting (see nlinfit). |
'Options' | a statset-style options structure controlling
the iterative fit (MaxIter, TolFun, TolX). |
'PredictorVars', 'ResponseVar' | for table input, the predictor and response variable names. |
'VarNames' | a cell array of variable names (predictors followed by the response) for numeric X. |
'Exclude' | observations to exclude from the fit. |
Source Code: fitnlm
See also: NonLinearModel, nlinfit, nlparci, nlpredci, fitlm, fitglm
Source Code: fitnlm
Fit an exponential growth model and inspect the summary.
x = [1:10]'; y = [2.1;2.9;4.2;5.3;7.1;9.4;12.8;16.5;22.1;29.8]; modelfun = @(b, x) b(1) .* exp (b(2) .* x); mdl = fitnlm (x, y, modelfun, [1; 0.3])
mdl =
Nonlinear regression model:
y ~ b1*exp(b2*x)
Estimated Coefficients:
2x4 table
Estimate SE tStat pValue
________ __________ _______ ___________
b1 1.68375 0.0351945 47.8412 4.03037e-11
b2 0.286911 0.00235084 122.046 2.27082e-14
Number of observations: 10, Error degrees of freedom: 8
Root Mean Squared Error: 0.171
R-Squared: 1, Adjusted R-Squared 1
F-statistic vs. zero model: 3.44e+04, p-value = 2.22e-16
Predictions with 95% confidence intervals on the fitted curve.
x = [1:10]'; y = [2.1;2.9;4.2;5.3;7.1;9.4;12.8;16.5;22.1;29.8]; modelfun = @(b, x) b(1) .* exp (b(2) .* x); mdl = fitnlm (x, y, modelfun, [1; 0.3]); [ypred, yci] = predict (mdl, [2.5; 5.5; 8.5])
ypred =
3.4497
8.1583
19.2935
yci =
3.3291 3.5704
7.9979 8.3186
19.1219 19.4650