A class to perform multiple linear regressions relying on the closed form solution.
This class performs linear regressions with multiple predictors. For example, to compute air temperature trends based on elevation, easting, northing (ie predictors). See https://www.statlearning.com/ and http://www.public.iastate.edu/~maitra/stat501/lectures/MultivariateRegression.pdf
It solves the multiple linear regression as
\[
\mathbf{Y = \theta^\top X + \epsilon}
\]
where \( \mathbf{Y} \) is the vector of the observations (or outputs), \( \mathbf{X} \) the design matrix (predictors prefixed with a column of 1's so the intercept term is included in the multiplication), \( \mathbf{\theta} \) the matrix of the regression coefficients and \( \mathbf{\epsilon} \) the matrix of errors. The \( \mathbf{Y} \) and \( \mathbf{X} \) matrices are filled with the \( \mathbf{n} \) observations and \( \mathbf{m} \) predictors (for example with 3 predictors, altitude, easting and northing) so the previous equation becomes:
\[
\underbrace{
\left(
\begin{array}{c}
obs_1 \\
obs_2 \\
\vdots \\
obs_n
\end{array}
\right)
}_{Y}
\qquad
=
\qquad
\underbrace{
\left(
\begin{array}{c}
\beta_0 \\
\beta_1 \\
\vdots \\
\beta_m
\end{array}
\right)^\top
}_{\theta}
\cdot
\underbrace{
\left(
\begin{array}{cccc}
1 & alt_1 & east_1 & north_1 \\
1 & alt_2 & east_2 & north_2 \\
\vdots & \vdots & \vdots & \vdots \\
1 & alt_n & east_n & north_n
\end{array}
\right)
}_{X}
+
\underbrace{
\left(
\begin{array}{c}
\epsilon_1 \\
\epsilon_2 \\
\vdots \\
\epsilon_m
\end{array}
\right)
}_{\epsilon}
\]
If we write \( \mathbf{\hat{\theta}} \) the least square estimate of \( \mathbf{\theta} \), then \( \mathbf{ \hat{\theta} = (X^\top X)^{-1}X^\top Y} \) and the predicted values are computed as \( \mathbf{ \hat{Y} = \hat{\theta}^\top X } \) (closed form solution).