Regression · Part 2
Explain how fitted models vary, quantify uncertainty, and interpret associations without confusing them with causal effects.
A fitted line is an estimate. What changes across samples, and what may we conclude?
| Metric | Formula | What does it show me? |
|---|---|---|
| RSSResidual sum of squares | Training misses, squared and added. Smaller means a closer fit to the same cases. | |
| TSSTotal sum of squares | Squared misses from always predicting the response average: the variation available to explain. | |
| RSEResidual standard error | Estimated scatter around the fitted model, in response units (such as kg). | |
| R²Coefficient of determination | Improvement over the average baseline: 1 = perfect, 0 = equal, negative = worse. | |
| Test RMSERoot mean squared error | Typical size of mistakes on new test cases, in response units. Large misses count more. |
Each dot is a model’s prediction for the same input, after training on a different sample.
Bias is the systematic error from a mismatch between the average learned relationship and the true one.
Example: a straight-line model misses a quadratic pattern.
Variance is the variability of the learned model across possible training datasets from the same population.
Here, compare the spread of predictions at the same input.
Keep input fixed and repeat training on possible datasets from the same population.
Average learned prediction minus the true mean.
Spread of learned predictions at the same input.
New observation: is an outcome not used for training. Its is the random difference from the true mean at . For example, another crop trial with the same fertilizer dose can give a different yield.
At the same input , imagine training again and predicting a new observation . Average the squared prediction errors over these repetitions.
The sum on the right is the expected Mean Squared Error (MSE).
MSE is RMSE without the square root: .
Squared bias: how far the average prediction misses.
Variance: how much predictions change across training datasets.
is the new observation’s random difference from its true mean.
This variation remains even if we predict that mean perfectly.
The simulation knows the true curve. With real data, compare validation error because the true bias and variance are usually unknown.
Compare degrees 0, 2 and 9. Purple dots show 60 fitted predictions. The blue dotted line marks the selected input x.
The simulation knows the true curve. With real data, compare validation error because the true bias and variance are usually unknown.
Each dataset has a different job. Example scores below are illustrative: lower RMSE is better.
Learn the coefficients of both curves from the same training cases.
Predict different, held-out cases.
Lower validation error → choose degree 2.
Predict a third, untouched set.
Report how well the chosen model generalizes.
Choose before testing. If a test score makes you change the model, that set is now guiding selection.
The fitted slope here is about 0.108. Another sample could give a different value.
The question: would a slope this far from zero be unusual* if the true population slope were zero?
A fitted number alone does not tell us how precise it is. We need its sampling uncertainty.
*Here, “unusual” means “unlikely to arise from sampling noise if the true population slope were zero.”
A fitted slope can be nonzero just because the sample is noisy. We state two hypotheses to check whether the data provide evidence of a linear association beyond this sampling variation.
The population slope is zero. A nonzero fitted slope can arise from sampling noise.
The population slope is positive or negative. The data may support a linear association.
Rejecting H₀ does not establish causation. Failing to reject does not establish no relationship.
Use one dataset. RSE estimates the size of the random scatter around its fitted line.
Units: response units, such as kg.
Repeat training on new datasets. Slope SE describes how much the slope estimates vary.
Units: response units per input unit.
This describes what fitted slopes would do across repeated studies. In ordinary data, the true and the true are both unknown.
Center = . Spread = .
Center = 0, spread = 1.
Computing this needs the true and .
This theoretical quantity cannot be computed from the sample alone. A simulation can supply the true values. Next, estimate from data.
We estimate the slope standard error with . Press Next: equivalent formulas appear from left to right, while the explanation follows the selected step.
Think rise/run: RSE is vertical response noise. The denominator is horizontal input spread. Their ratio estimates slope uncertainty, not the slope itself.
Replace RSE² with RSS / (n − 2): two fitted coefficients use two degrees of freedom.
Expand RSS into squared residuals. This is the same formula, written using the individual observations.
More response noise increases slope uncertainty. More cases or more input spread reduce it, all else equal. Requires n > 2 and varying inputs.
We record height and weight for 16 people. Can a line summarize how average weight changes with height?
Input: height, measured in centimetres.
Response: weight, measured in kilograms.
Four of the 16 observations:
| Height (cm) | Weight (kg) |
|---|---|
| 155 | 61.3 |
| 168 | 74.6 |
| 180 | 76.0 |
| 195 | 91.2 |
Illustrative simulated data. The plot shows all 16 observations. Table values are rounded.
First look at the observations. Next, fit a line and ask how much evidence its upward slope gives.
The line fitted to these height–weight observations slopes upward. Is this evidence of a population linear relationship, or could sampling noise produce it if the true line were flat?
Temporarily assume .
This is the zero-slope population model.
Use the same sampling setup.
Noise can make a fitted sample line tilt upward or downward.
Would a fitted slope as far from zero as ours be unusual?
If very unusual, it is evidence against the flat population line.
We assess the observed result assuming a zero slope. We do not calculate the probability that the true slope is zero. A linear association does not establish causation.
Go to the next slide for a visual intuition
Imagine the population line is flat. What slopes could noise alone produce in samples like ours?
The true slope is temporarily set to zero. Individual responses can still be noisy.
Keep the same 16 heights. Fit a new line to each hypothetical sample. Five of 500 fits are shown.
Purple bars summarize all 500 fitted slopes. Our +0.60 kg/cm lies far from their cluster.
The t test asks whether our fitted slope could plausibly result from sampling noise when the true population slope is zero.
For a positive estimated standard error. The sign shows direction, not strength of evidence.
Two simulated adult height–weight samples: the same 16 height values, the same axis scales, and the same positive fitted slope. Only residual scatter changes.
Less vertical noise gives a smaller slope SE. Dividing the same fitted slope by this smaller SE gives a larger positive t.
More vertical noise gives a larger slope SE. Dividing the same fitted slope by this larger SE gives a smaller positive t.
Slope SE also depends on sample size and horizontal input spread. Both are held fixed here, so this comparison isolates residual scatter. The t value is unitless.
The numerator asks: how far is our fitted slope from the zero slope proposed by ? Divide that signed distance by its estimated standard error.
The t value measures deviation from a hypothetical zero slope in estimated standard errors. It does not give the probability that the true slope is zero.
Assuming the true line were flat, how rare would a t value at least as far from zero as ours be?
Example: we compute this number once.
It is fixed by our original dataset.
Assume .
The same calculation on each hypothetical sample gives a new .
Same model and sampling setup, not extra data to collect.
Absolute values ignore sign.
The inequality counts both directions, including equally extreme results.
With a positive estimated SE, the fitted line is flat. Every possible is at least 0.
This gives no evidence against a zero slope, but does not prove it.
= significance threshold (often 0.05, depending on the task).
: reject the zero-slope null.
: insufficient evidence to reject it.
Smaller p means stronger evidence against a flat population line. “More extreme” means farther from zero in t units, not a larger raw slope. It is not the probability that the null is true.
Change the observed t, n or threshold α. Try t = 0, switch its sign, or load the 90-point result. Watch the decision change as p crosses α.
The curve describes repeated studies under . A larger distance from zero leaves less probability in the two tails.
Start with the supplied data. Then simulate new samples: change their size, noise, true slope or input spread. Compare the OLS line with a mean-only fit.
Start with the worked 95% interval. Then repeat the study: each new dataset gives a new fitted slope and a new interval.
This is an interval for the population slope, not for an individual future response. It does not establish causation.
Multiple linear regression combines several measured inputs in one prediction rule.
y and ε stack the n responses and errors. β stacks m + 1 coefficients. Each row of X is [1, xᵢ₁, …, xᵢₘ].
A multiple-regression coefficient describes a comparison at the same values of the other included predictors.
Predicted yield = 1 + 2 × 1 + 0.5 × 4 = 5.
Predicted yield = 1 + 2 × 2 + 0.5 × 4 = 7.
This is a model-based conditional association. A causal effect needs additional evidence about the study and mechanism.
Imagine recording ice-cream sales and shark attacks at different times of year. These illustrative values are normalized to show the pattern.
“More ice cream must be causing the attacks!”
The line rises, R² ≈ 0.53, and the slope test gives p < 0.01. These support a linear association.
What can we actually conclude?Sales and attacks vary together.
The regression alone does not explain why.
| R²Coefficient of determination | RSEResidual standard error | Test RMSERoot mean squared error | Slope tTest statistic | Slope p-valueTwo-sided test |
|---|---|---|---|---|
| 0.5300 | 0.1525 | 0.1487 | 9.3792 | < 0.01 |
In our example, ice-cream sales and shark attacks rise together. Should we arrest the ice-cream vendor?
Warm days can increase both ice-cream sales and swimming. More swimmers means more exposure to sharks.
The association alone does not show that ice cream causes shark attacks.
Correlation: two quantities vary together.
Causation: changing one produces a change in the other. A correlation alone cannot establish that.
More examples: Tyler Vigen’s Spurious Correlations ↗
These illustrative sales and attack indices rise together. Inspect the points: can this two-variable scatter tell us whether a third variable drives both?
A confounder is a shared cause that can create or distort the association between a predictor and an outcome.
Higher temperature may affect both ice-cream sales and exposure to swimming. This is a causal hypothesis to investigate.
The ice-cream sales coefficient is the slope multiplying the sales input. It can also capture the shared warm-weather pattern.
: predicted shark-risk change for +1 sales index, at fixed temperature.
: predicted change for +1 temperature index, at fixed sales.
Adding temperature changes the comparison: sales is now compared at the same temperature. The coefficient and its uncertainty can both change.
Choose the model. In Sales + temperature, select sales or temperature on X. Shark risk stays on Y.
LINE is a memory aid for four assumptions of classical linear regression:
Linearity, Independence, Normality and Equal variance.
They help justify the standard errors and p-values used to judge uncertainty in fitted coefficients.
The average response follows a weighted sum of the chosen features.
Intuition: A line describes the middle of the data. Individual observations can sit above or below it.
Why it matters: A missed curve can produce systematically wrong predictions.
The errors of different observations are independent.
Intuition: An error in one case gives no clue about the next. Repeated measurements of one person may break this.
Why it matters: Related errors can make standard errors and p-values misleading.
Linearity is in the coefficients. Using x² as a feature can still describe a curved mean (x = input).
N describes the shape of the errors. E describes their spread. Both refer to errors at fixed input values.
At each input, errors follow a normal, bell-shaped distribution centered at zero.
Intuition: Small positive and negative errors are common. Large errors in either direction are rare.
Why it matters: Together with the other assumptions, this supports exact small-sample t tests.
Errors have the same spread at every input value.
Intuition: Predicting a larger response should not automatically mean a wider cloud of errors.
Why it matters: Unequal spread can make the usual standard errors unreliable.
OLS can fit coefficients without normal errors. LINE supports classical inference about their uncertainty.
| Pattern | Possible concern | Next step |
|---|---|---|
| Curved mean pattern | Misspecified conditional mean | Consider justified features or transformations |
| Widening spread | Unequal error variance | Inspect scale; use suitable variance modeling or inference |
| Pattern over time or order | Dependent errors | Account for the sampling or temporal structure |
| Unusual isolated points | Outlier or influential observation | Check data quality and sensitivity |
A featureless plot does not prove every assumption. A normal Q–Q plot compares residual quantiles with normal-distribution quantiles to assess shape.
Define the outcome, intended use and units.
Split cases to match the intended use.
Estimate the coefficients on training data.
Compare validation error and residual patterns.
Test the chosen procedure and state assumptions.
Prediction quality, coefficient significance and causal evidence answer different questions.
Six coefficients, including the intercept.
RSE denominator: n − 6, if n > 6 and rank is full.
Yes. Its predictions can be worse than the mean-response baseline on that held-out dataset.
Least squares still has solutions, but coefficients may tie. A pseudoinverse chooses the solution with the smallest coefficient-vector length.
No. The test concerns association under assumptions. Confounding and study design remain relevant.
Next lecture: classification changes the target and the loss.
An Introduction to Statistical Learning
Chapter 3: linear regression
Penn State STAT 501
NumPy least squares
Rank, solutions and reliable solvers.
Use the local interactive examples to connect formulas, plots and predictions.
Lecture 10 · Regression · Part 2