As the question says, can one force a fit through the origin $(0,0)$ as one can when fitting a trendline to your data in MS Excel? If so, how do you do that?
|
|||||||||||||
|
|
Another possibility, a bit more general :
One can add constraints on the parameters to the model :
|
|||||||||||||
|
|
I have given a derivation of the needed formulae in this math.SE answer. As already mentioned by belisarius, the canonical method for finding the equation of the least-squares line constrained to pass through the origin in Mathematica would be either of
which produces the explicit linear function, or
which produces just the slope of the best-fit line as a replacement rule. To handle the case of a least-squares line constrained to pass through an arbitrary point $(h,k)$, you can again use either of
This returns the best-fit line as a pure function. Here are a few examples, taken from Kolb's Curve Fitting for Programmable Calculators:
|
|||
|
|
|
belisarius gives the solution but forgot to tell why it is the solution. The general equation for your linear regression line is $y = a x + b$ which you write in the
The second parameter is a list of functions. Fit will find the best fit by making a weighted sum of these functions, i.e. $ a_1 \cdot x + a_2 \cdot 1 $ If you want a line through the origin the constant term should be zero, and the
Example:
gives us
|
||||
|
|



