Let's just go through an example of manually fitting the least squares equation. So, consider the data set swiss. So, if I do data(swiss) and here's the data set.head(swiss). There's the data set. We wanna use fertility as an outcome and predict it using agriculture, examination, education, catholic, infant mortality, and an intercept. So let's create an x matrix that is the swiss data set minus the first row. First column. Okay. Let's see x[1: 10,]. Okay, there we go. So it now has an intercept. Agriculture, examination, education, catholic, and infant mortality. We want to set y = swiss$Fertility. Okay so what we're saying is that beta hat is going to be solve(x %*% x) %*% t(x) %*% y. is.matri(x) False. X = as.matrix(x). Now let's try it again. Oop and notice one of the thing, x transpose x. So I forgot my transpose there. Okay. Now let's see beta. Okay. If gives you a coefficient for each of the terms. One for the intercept, one for agriculture, examination, education, Catholic, and infant mortality. Now let's just compare it if we were to do lm(y~ x). Okay we see the same thing. Notice they tried to fit and intercept, or I'm sorry, it can't fit our intercept term because it's including intercept so obviously it can include ours intercept plus the extra intercept term. So that one, it just sets as in a, if it has a redundant column in the X matrix. So, notice that the terms are, of course, all the same. So, that's what's going on with lm behind the scenes. I would say I think it's a little bit faster if you do solve(t(x) %*% x, And t(x). %*% y). If you give it the two arguments like that, giving it the equations to solve, I actually think that's a little bit faster way to do the inversion numerically. So, if you happen to have kind of bigish matrices, you actually want to give the function solve the linear equations, rather than actually going through the matrix manipulations. But, of course, it gives you the same thing. Okay? So, that's under the hood, what lm is accomplishing when it fits a multi-variable regression.