There are a few major differences between Fit
and LinearModelFit
.
LinearModelFit
generates a full model object as its output, which maintains a large set of interesting properties (such as RSquared
or ANOVATable
). These can be accessed by:
lmf = LinearModelFit[{2, 3, 4, 5}, {x}, x];
lmf["Properties"]
lmf["RSquared"]
By default, LinearModelFit
assumes that the zero-intercept may be non-zero. This property is controlled by the IncludeConstantBasis
option. LinearModelFit
has several interesting but advanced options available as well, such as the ability to define weights and perform error propagation through the model.
The final fit expression from LinearModelFit
can be extracted with Normal
.
Fit
does not assume a constant basis, and returns the fit expression directly. It does not calculate additional properties, will automatically convert exact numbers to machine precision, and only finds the least-squares fit. LinearModelFit
and Fit
can work at arbitrary precision (as unlikely as that may be to be useful), but only LinearModelFit
allows the specification of WorkingPrecision
as an option.
The primary advantage of Fit
would appear to be its simplicity and brevity. If you only need the least-squares fit expression or are doing code-golf, Fit
should suffice. In most other cases, I would recommend using LinearModelFit
, if only to be able to access the various quality measures it can calculate on the side.
Note, however, that I wouldn't expect either function to have significant errors -- they ultimately should find the same model, assuming that the constant basis is either included or excluded in both, and that no special options are specified in LinearModelFit
to adapt the model to a specific use case. It's just a question of if you want/need the additional data of the model object.
LinearModelFit
generates a model object which has some useful properties (e.g. "RSquared"), in addition to the fit itself. In short, I'd only recommendFit
if you just want the shortest code for getting the linear fit expression without any other baggage. $\endgroup$