Examine Quality and Adjust the Fitted Nonlinear Model
There are diagnostic plots to help you examine the quality of a model. plotDiagnostics(mdl) gives a variety of plots, including leverage and Cook's distance plots. plotResiduals(mdl) gives the difference between the fitted model and the data.
There are also properties of mdl that relate to the model quality. mdl.RMSE gives the root mean square error between the data and the fitted model. mdl.Residuals.Raw gives the raw residuals. mdl.Diagnostics contains several fields, such as Leverage and CooksDistance, that can help you identify particularly interesting observations.
This example shows how to examine a fitted nonlinear model using diagnostic, residual, and slice plots.
Load the sample data.
Create a nonlinear model of rate as a function of reactants using the hougen.m function.
beta0 = ones(5,1); mdl = fitnlm(reactants,... rate,@hougen,beta0);
Make a leverage plot of the data and model.
There is one point that has high leverage. Locate the point.
[~,maxl] = max(mdl.Diagnostics.Leverage)
maxl = 6
Examine a residuals plot.
Nothing stands out as an outlier.
Use a slice plot to show the effect of each predictor on the model.
You can drag the vertical dashed blue lines to see the effect of a change in one predictor on the response. For example, drag the X2 line to the right, and notice that the slope of the X3 line changes.