When fitting data to a model, it is often important to obtain additional results to compare the data to the fitted function. You may wish to check the significance of parameters and assess the assumptions of the model, the influence of data points, and the goodness of fit. In the Wolfram Language you can obtain these results directly from FittedModel objects returned by model fitting functions such as LinearModelFit, NonlinearModelFit, and GeneralizedLinearModelFit.
You can fit a simple linear regression model using LinearModelFit:
The output is a FittedModel object that contains information about the fitting and original data. You can get results and diagnostics directly from the object.
Use Normal to give the functional form of the fitted model:
FittedModel objects also contain many results and diagnostics that are relevant to the type of model they represent (in this case a linear model). You can evaluate the FittedModel with "Properties" to get a full list of the available properties for that model.
Here Length is used to give the number of properties known for this model:
It is often important to ask whether or not the parameter estimates are statistically significant, that is, whether or not the parameter values are significantly different from 0. For instance, with a linear model you might look at the ‐value for a -statistic associated with that parameter. The ‐value is the probability of observing a -statistic at least as far from 0 as the one obtained.
Use "ParameterTable" with the FittedModel to display a table that summarizes the parameter estimates, -statistics, and ‐values:
You can use other properties to get the -statistics and ‐values individually. This is particularly useful if you want to compute other results based on those properties. Use "ParameterPValues" with the FittedModel to view just the -values:
By default, 95% confidence intervals are returned. You can get other intervals with other levels of confidence by using the ConfidenceLevel option.
Visualize the residuals using ListPlot:
Though the available properties differ somewhat, results and diagnostics for nonlinear and generalized linear models can be obtained in the same way. You can fit models of these types by using NonlinearModelFit, GeneralizedLinearModelFit, LogitModelFit, or ProbitModelFit.
Use NonlinearModelFit to fit the data to an exponential model:
Just as in the linear model case, use Show to combine the plots of the data points and the model:
You can also view tabular results for estimates at individual points. Use "SinglePredictionConfidenceIntervalTable" with the FittedModel to view such a table of predicted values with their error estimates and confidence intervals:
Visualize the regions bounded by the bands along with the fitted function and use Filling to more easily see the regions of each confidence level: