# Linear fitting without intercept

I want to fit the following model: $$y_t=\beta x_t+\epsilon_t$$

For that, I've tried the following

In[3]:= Transpose[data]

Out[3]= {{0, 1, 3, 5}, {1, 0, 2, 4}}

In[5]:= LinearModelFit[Transpose[data], IncludeConstantBasis -> False]

During evaluation of In[5]:= LinearModelFit::fitm: Unable to solve for the fit parameters; the design matrix is nonrectangular, non-numerical, or could not be inverted.

Out[5]= LinearModelFit[{{0, 1, 3, 5}, {1, 0, 2, 4}},
IncludeConstantBasis -> False]


What is my mistake?

The form of LinearModelFit that you are trying to use is

LinearModelFit[{m, v}]


where m is a design matrix, and v is a response vector. But in your input, m, is {0, 1, 3, 5}, which is not a matrix. Try this instead:

LinearModelFit[{
{{0}, {1}, {3}, {5}},
{1, 0, 2, 4}
},
IncludeConstantBasis -> False
]


Since you have only one paramter, you can use Grid Search method.

$$\epsilon_t=y_t-\beta x_t$$ and $$error=\sum_{i=1}^4(y_i-\beta x_i)^2$$.

We see that $$0\leq\beta\leq 1$$ from ListPlot.

 data = {{0, 1}, {1, 0}, {3, 2}, {5, 4}};
ListPlot[data, AspectRatio -> 1]


ϵ[β_] := Total[(#2 - β #1)^2 & @@@ data]
βval = Subdivide[0, 1., 100000];
Extract[βval, Ordering[ϵ[βval], 1]]


0.74286

As an alternative you could use the other structure for LinearModelFit:

data = Transpose[{{0, 1, 3, 5}, {1, 0, 2, 4}}]
lm = LinearModelFit[data, x, x, IncludeConstantBasis -> False];
lm["ParameterTable"]