My Long-Time Peers Told Me I Regressed (s**tpost)

They meant it as an insult. I took it as a specification, and derived the whole thing from scratch.


Talking to old colleagues sucks sometimes, especially when they're cynical.

I think they were just mad, because a rizzler like me hit the skibidi toilet scuba in Ohio 6-7 times and aura farmed on them, no cap. 🚫🧢

They said: “Thommas, you’ve really regressed.”

Of course I regressed—technically it's called Regression—a statistical analysis method used to estimate the relationship between an outcome and the predictor variables. 📈📉

You probably remember from school 🏫:

y=mx+by = mx + b

But you can go deeper 🕳️🪏. Let's redefine these variables:

symbolschooldescription
y^i\hat{y}_iyythe iith prediction
β0\beta_0bbthe intercept
β1\beta_1mmthe slope
xix_ixxthe iith predictor variable

Final equation for a simple linear regression:

y^i=β0+β1xi\hat{y}_i = \beta_0 + \beta_1 x_i
Fig. 1.1 — Drag the points. The line moves to the fit that minimises the squared residuals.

You see 👀, the goal is to draw a line that minimises the residuals (eie_i) from the data points. Some people call these errors.

ei=yi−(β0+β1xi)e_i = y_i - (\beta_0 + \beta_1 x_i)

In the wild, you'll see people refer to linear regression as Ordinary Least Squares (OLS). This is because we are trying to minimise the Sum of Squared Errors (SSE), to penalise the big ones more than the small ones. Since real life data is imperfect (except for Me 🧍🏻‍♂️), let's append to our formula to account for error:

y^i=β0+β1xi+ei\hat{y}_i = \beta_0 + \beta_1 x_i + e_i SSE=∑i=1n(yi−β0−β1xi)2SSE = \sum_{i=1}^{n} (y_i - \beta_0 - \beta_1 x_i)^2

Solving for the intercept

The goal (of OLS and of Life itself) is to find the perfect balance in the line to minimise the SSE. We take the partial derivative of the SSESSE with respect to β0\beta_0 and solve for zero:

∂SSE∂β0=−2∑i=1n(yi−β0−β1xi)=0\frac{\partial SSE}{\partial \beta_0} = -2 \sum_{i=1}^{n} (y_i - \beta_0 - \beta_1 x_i) = 0 ∑i=1nyi−∑i=1nβ0−β1∑i=1nxi=0\sum_{i=1}^{n} y_i - \sum_{i=1}^{n} \beta_0 - \beta_1 \sum_{i=1}^{n} x_i = 0

If you add up a constant (β0\beta_0) exactly nn times, you just get nβ0n\beta_0. Let's move that to the other side:

∑i=1nyi=nβ0+β1∑i=1nxi\sum_{i=1}^{n} y_i = n\beta_0 + \beta_1 \sum_{i=1}^{n} x_i

Divide the entire equation by nn. When you divide a sum by nn, you get an average (which we write as yˉ\bar{y} and xˉ\bar{x}):

yˉ=β0+β1xˉ\bar{y} = \beta_0 + \beta_1 \bar{x}

Solve for β0\beta_0:

β^0=yˉ−β^1xˉ\hat{\beta}_0 = \bar{y} - \hat{\beta}_1 \bar{x}

Once you know the slope (β1\beta_1), you can find the intercept by plugging in the averages of your xx and yy data (xˉ\bar{x} and yˉ\bar{y}).

Solving for the slope

Now we do the same thing, but taking the derivative with respect to β1\beta_1:

∂SSE∂β1=−2∑i=1nxi(yi−β0−β1xi)=0\frac{\partial SSE}{\partial \beta_1} = -2 \sum_{i=1}^{n} x_i (y_i - \beta_0 - \beta_1 x_i) = 0 ∑i=1n(xiyi−β0xi−β1xi2)=0\sum_{i=1}^{n} (x_i y_i - \beta_0 x_i - \beta_1 x_i^2) = 0

Substitute the β0\beta_0 formula we just found (β0=yˉ−β1xˉ\beta_0 = \bar{y} - \beta_1 \bar{x}) into this equation:

∑i=1n(xiyi−(yˉ−β1xˉ)xi−β1xi2)=0\sum_{i=1}^{n} \left( x_i y_i - (\bar{y} - \beta_1 \bar{x}) x_i - \beta_1 x_i^2 \right) = 0

Expand it out:

∑i=1n(xiyi−yˉxi+β1xˉxi−β1xi2)=0\sum_{i=1}^{n} (x_i y_i - \bar{y} x_i + \beta_1 \bar{x} x_i - \beta_1 x_i^2) = 0

Group all the terms with β1\beta_1 on one side:

∑i=1n(xiyi−yˉxi)=β1∑i=1n(xi2−xˉxi)\sum_{i=1}^{n} (x_i y_i - \bar{y} x_i) = \beta_1 \sum_{i=1}^{n} (x_i^2 - \bar{x} x_i)

Finally, divide to isolate β1\beta_1. With a bit of algebraic rearranging, this simplifies into its final form:

β^1=∑i=1n(xi−xˉ)(yi−yˉ)∑i=1n(xi−xˉ)2\hat{\beta}_1 = \frac{\sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y})}{\sum_{i=1}^{n} (x_i - \bar{x})^2}

The slope is just the covariance (more on this another time) of xx and yy (how they move together) divided by the variance of xx (how spread out the xx values are).

Congratulations to me, I just solved Regression. 🥳🥳🥳

Well, there's actually more.

You could have more than one predictor variable. Mathematically you can have up to as many predictors (pp) as one less than the number of data points, such that p<n−1p < n - 1, making the following formula:

yi=β0+β1x1+β2x2+⋯+βpxp+eiy_i = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \dots + \beta_p x_p + e_i
Fig. 1.2 — Two predictors, so the fit is a plane rather than a line.

The one above has two predictor variables, and would be solved as such:

yi=β0+β1x1+β2x2+eiy_i = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + e_i

So I guess what I have to say is:

I'm not delulu, I'm in my GOAT era. 🤪⏳⌛🐐 (fr)

Yes, I've regressed. But it's Simple, it's Ordinary, it's Regression.

I ghosted them, sus and mid fr. 👻👻👻