From a cloud of dots to one best line
Start — the everyday picture. Mark a dot for every student in your class: how many hours they studied (across the page) versus the score they earned (up the page). The dots never line up perfectly, yet you can still see a trend — more studying tends to go with a higher score. Linear regression is simply the rule for drawing the single straight line that best threads through that messy cloud, so you can say "each extra hour is worth about this much on the test."
Build — naming the pieces. Any straight line is fixed by two numbers. The slope $\hat\beta_1$ tells you how much $y$ rises for each one-unit step in $x$; the intercept $\hat\beta_0$ is where the line sits when $x=0$. Together they give the fitted line $\hat y = \hat\beta_0 + \hat\beta_1 x$. If one extra study-hour lifts the predicted score by 5 points, then $\hat\beta_1 = 5$. But which line is "best"? For every dot we measure the residual — the vertical gap between the real point and the line. We square each gap (so positives and negatives can't cancel) and add them all up. The best line is the one that makes this total, the $\text{RSS}$, as small as possible. That is exactly why the method is called least squares.
Deepen — the precise statement. Formally we minimize $\text{RSS}=\sum_i (y_i-\hat\beta_0-\hat\beta_1 x_i)^2$. Setting the two partial derivatives to zero gives a clean closed form: $\hat\beta_1 = S_{xy}/S_{xx}$ and $\hat\beta_0=\bar y-\hat\beta_1\bar x$, so the line always passes through the mean point $(\bar x,\bar y)$. The quality of the fit is summarized by $R^2\in[0,1]$, the fraction of $y$'s variation the line explains; for a single predictor it equals the squared correlation, $R^2=r_{xy}^2$. In this sim the True slope $\beta_1$ slider sets the hidden trend, Noise $\sigma$ controls how far the dots scatter from it, and n sets how many dots you draw.
Try this in the sim above. Slide Noise $\sigma$ down toward $0.05$ and watch $R^2$ climb to nearly $1$ as the dots snap onto the line; then push $\sigma$ up to $5$ and see $R^2$ collapse even though the true slope hasn't changed. Open the Slope Sweep tab and drag the manual slope — its RSS readout never drops below the OLS value, making "least squares" visible. Finally load the With outlier preset and watch a single stray point tug the whole fitted line toward it.
Simple Linear Regression — OLS — Gauss & Legendre ~1800
$$Y_i = \beta_0 + \beta_1 X_i + \varepsilon_i,\quad \varepsilon_i \overset{iid}{\sim} \mathcal{N}(0,\sigma^2)$$
$$\boxed{\hat{\beta}_1 = \frac{S_{xy}}{S_{xx}} = \frac{\sum(x_i-\bar{x})(y_i-\bar{y})}{\sum(x_i-\bar{x})^2},\qquad \hat{\beta}_0 = \bar{y} - \hat{\beta}_1\bar{x}}$$
| Symbol | Meaning | Type | Interpretation |
|---|---|---|---|
| $\beta_0$ | True intercept | Parameter | $E[Y]$ when $X=0$ |
| $\beta_1$ | True slope | Parameter | Change in $E[Y]$ per unit $X$ |
| $\hat{\beta}_0,\hat{\beta}_1$ | OLS estimates | Statistics | Minimize RSS |
| $e_i=y_i-\hat{y}_i$ | Residual | Statistic | Observed minus fitted |
| $R^2$ | Coeff of determination | Statistic | Variance in $Y$ explained by $X$ |
| $S_{xy}$ | Cross deviation | Statistic | $\sum(x_i-\bar{x})(y_i-\bar{y})$ |
$$\text{RSS}=\sum(y_i-\beta_0-\beta_1 x_i)^2 \to \min$$
$\partial\text{RSS}/\partial\beta_0=0\Rightarrow \hat{\beta}_0=\bar{y}-\hat{\beta}_1\bar{x}$
$\partial\text{RSS}/\partial\beta_1=0\Rightarrow \hat{\beta}_1=S_{xy}/S_{xx}$
Under linearity, exogeneity, homoskedasticity, and independence, OLS is BLUE (Best Linear Unbiased Estimator) with $\text{Var}(\hat{\beta}_1)=\sigma^2/S_{xx}$.
$$R^2=1-\frac{\text{RSS}}{\text{TSS}}=\frac{\text{ESS}}{\text{TSS}}\in[0,1], \quad R^2=r_{xy}^2$$
$$t=\frac{\hat{\beta}_1}{s/\sqrt{S_{xx}}}\sim t_{n-2} \quad\text{under }H_0:\beta_1=0$$
Data: (1,2.1),(2,3.9),(3,6.2),(4,7.8),(5,10.1). $\bar{x}=3,\bar{y}=6.02$
$S_{xx}=10,\; S_{xy}=19.9$
$$\hat{\beta}_1=19.9/10=1.99,\quad\hat{\beta}_0=6.02-1.99\times3=0.05$$
$R^2=S_{xy}^2/(S_{xx}S_{yy})=19.9^2/(10\times 39.708)=0.997$ — almost perfect linear relationship.
"High R² proves the model is correct and causality holds."
R² measures fit, not model correctness or causal direction. Spurious correlations can yield R²≈1. Causality requires experimental design or causal inference methods (IV, DiD), never correlation alone.
📖 Freedman, Pisani & Purves — Statistics, Ch. 10
"The regression line passes through the origin."
OLS line always passes through $(\bar{x},\bar{y})$, not the origin. Forcing zero intercept is only valid in specific scientific contexts and changes the estimator entirely.
📖 Hogg, McKean & Craig — Ch. 9.1
"Residuals should be zero for a good model."
Good residuals should be centered at zero, homoskedastic, uncorrelated, and approximately normal — but not zero. Patterns in residual plots (fan shape, curves) indicate violated assumptions needing robust SE or transformations.
📖 Casella & Berger — Ch. 11
Using $S_{yy}$ instead of $S_{xx}$ in denominator of $\hat\beta_1$
✅ Always $\hat\beta_1=S_{xy}/S_{xx}$. Using $S_{yy}$ gives inverse regression (X on Y). Correlation is symmetric; regression is not.
🔍 Confusing correlation formula (uses $\sqrt{S_{xx}S_{yy}}$) with regression formula.
Extrapolating far beyond the observed data range
✅ OLS predictions are only reliable within the range of observed X. Extrapolation assumes linearity holds beyond the data — often false. Always note the valid prediction range.
🔍 Students plug any x into $\hat{y}=\hat\beta_0+\hat\beta_1 x$ without checking range validity.
Not checking OLS assumptions before computing p-values
✅ t-tests and F-tests require normal errors, homoskedasticity, and independence. Always plot residuals vs fitted and a QQ-plot. Use robust standard errors (HC3) or WLS if violated.
🔍 Students run regression on any data and report p-values without diagnostic checks.