I have some data. I want to find the linear regression of the data, but force it to include a certain point. (This question is a corollary to this old question; in that question, the user wished to force the fit to include the origin $(0, 0)$.)
Here is my data, and I want the linear regression to go through the point $(0, 100)$.
data = {{0, 100}, {4, 86}, {6, 80}, {7, 73}, {8, 66}, {13, 49}, {14, 44},
{15, 41}, {16, 33}, {17, 28}};
I know that I can fit the data to a line using
Fit[data, {1, x}, x]
or
Normal[LinearModelFit[data, x, x]]
which both yield 102.167 - 4.21667 x
, which of course does not go through $(0,100)$.
fit = Fit[data, {1, x}, x];
Show[{
ListPlot[data, PlotRange -> All, Joined -> True, Mesh -> Full,
Frame -> True],
Plot[fit, {x, 0, 25}, PlotRange -> All, PlotStyle -> Red]
}, AxesOrigin -> {0, 0}]
I thought that perhaps Fit[data, {100, x}, x]
would force Fit
to use a y-intercept of 100, but instead Fit
simply scales the constant term, yielding the same result:
102.167 - 4.21667 x
fixedLine[]
routine in my answer should be able to do this. Anyway:pt = {100, 0}; \[FormalA] \[FormalX] + {-\[FormalA], 1}.pt /. FindFit[TranslationTransform[-pt][data], \[FormalA] \[FormalX], \[FormalA], \[FormalX]]
$\endgroup$(0,0)
there really isn't a data point or a measurement at(0,0)
. Is there really a measurement at(100,0)
? $\endgroup$