Nonlinear regression model class
Diagnostics— Diagnostic information
Diagnostic information for the model, stored as a table. Diagnostics
can help identify outliers and influential observations.
the following fields.
|Diagonal elements of ||Leverage indicates to what extent the predicted value for an
observation is determined by the observed value for that observation.
A value close to |
|Cook's measure of scaled change in fitted values|
|Projection matrix to compute fitted from observed responses|
Fitted— Fitted response values based on input data
Fitted (predicted) values based on the input data, stored as
a numeric vector.
Fitted as close as possible to the response
Iterative— Information about fitting process
Information about the fitting process, stored as a structure with the following fields:
InitialCoefs — Initial coefficient
IterOpts — Options included
Options name-value pair argument for
MSE— Mean squared error
Mean squared error, stored as a numeric value. The mean squared error is an estimate of the variance of the error term in the model.
NumCoefficients— Number of model coefficients
Number of coefficients in the fitted model, stored as a positive
NumCoefficients is the same as
equal to the degrees of freedom for regression.
NumEstimatedCoefficients— Number of estimated coefficients
Number of estimated coefficients in the fitted model, stored
as a positive integer.
the same as
equal to the degrees of freedom for regression.
RMSE— Root mean squared error
Root mean squared error, stored as a numeric value. The root mean squared error is an estimate of the standard deviation of the error term in the model.
Robust— Robust fit information
Robust fit information, stored as a structure with the following fields:
|Robust weighting function, such as |
|Value specified for tuning parameter (can be |
|Vector of weights used in final iteration of robust fit|
This structure is empty unless
the model using robust regression.
|coefCI||Confidence intervals of coefficient estimates of nonlinear regression model|
|coefTest||Linear hypothesis test on nonlinear regression model coefficients|
|disp||Display nonlinear regression model|
|feval||Evaluate nonlinear regression model prediction|
|fit||Fit nonlinear regression model|
|plotDiagnostics||Plot diagnostics of nonlinear regression model|
|plotResiduals||Plot residuals of nonlinear regression model|
|plotSlice||Plot of slices through fitted nonlinear regression surface|
|predict||Predict response of nonlinear regression model|
|random||Simulate responses for nonlinear regression model|
Value. To learn how value classes affect copy operations, see Copying Objects (MATLAB).
Fit a nonlinear regression model for auto mileage based on the
carbig data. Predict the mileage of an average car.
Load the sample data. Create a matrix
X containing the measurements for the horsepower (
Horsepower) and weight (
Weight) of each car. Create a vector
y containing the response values in miles per gallon (
load carbig X = [Horsepower,Weight]; y = MPG;
Fit a nonlinear regression model.
modelfun = @(b,x)b(1) + b(2)*x(:,1).^b(3) + ... b(4)*x(:,2).^b(5); beta0 = [-50 500 -1 500 -1]; mdl = fitnlm(X,y,modelfun,beta0)
mdl = Nonlinear regression model: y ~ b1 + b2*x1^b3 + b4*x2^b5 Estimated Coefficients: Estimate SE tStat pValue ________ _______ ________ ________ b1 -49.383 119.97 -0.41164 0.68083 b2 376.43 567.05 0.66384 0.50719 b3 -0.78193 0.47168 -1.6578 0.098177 b4 422.37 776.02 0.54428 0.58656 b5 -0.24127 0.48325 -0.49926 0.61788 Number of observations: 392, Error degrees of freedom: 387 Root Mean Squared Error: 3.96 R-Squared: 0.745, Adjusted R-Squared 0.743 F-statistic vs. constant model: 283, p-value = 1.79e-113
Find the predicted mileage of an average auto. Since the sample data contains some missing (
NaN) observations, compute the mean using
Xnew = nanmean(X) MPGnew = predict(mdl,Xnew)
Xnew = 1.0e+03 * 0.1051 2.9794 MPGnew = 21.8073
The hat matrix H is defined in terms of the data matrix X and the Jacobian matrix J:
Here f is the nonlinear model function, and β is the vector of model coefficients.
The Hat Matrix H is
H = J(JTJ)–1JT.
The diagonal elements Hii satisfy
where n is the number of observations (rows of X), and p is the number of coefficients in the regression model.
The leverage of observation i is the value of the ith diagonal term, hii, of the hat matrix H. Because the sum of the leverage values is p (the number of coefficients in the regression model), an observation i can be considered to be an outlier if its leverage substantially exceeds p/n, where n is the number of observations.
The Cook’s distance Di of observation i is
is the jth fitted response value.
is the jth fitted response value, where the fit does not include observation i.
MSE is the mean squared error.
p is the number of coefficients in the regression model.
Cook’s distance is algebraically equivalent to the following expression:
where ei is the ith residual.