Statistics Library / Chapter 5

Regression and prediction

Describe a relationship, then ask whether the model is useful for its intended task.

Connect the ideas

A model expresses a conditional relationship. Its outcome scale, link, dependence structure and uncertainty need to match the question.

Continuous outcomes, binary responses, ordered categories and counts call for different models. Residuals compare observations with model expectations. Diagnostics can expose a mismatch; they cannot establish every design assumption.

A residual is a difference from the modelAt the same predictor value, the vertical distance from an observation to the fitted relation is a residual.residualfitted relationshipPredictorOutcome
A residual is a difference from the model. At the same predictor value, the vertical distance from an observation to the fitted relation is a residual. Schematic illustration; not calculated from a dataset.
Before you continue

Specify the outcome, predictors, interactions and clustering. Inspect residual behavior, influential observations and the range over which the model is used.

A mathematical connection: Multiple linear regression model

Y=β0+β1X1+β2X2+⋯+εY = \beta_0 + \beta_1 X_1 + \beta_2 X_2 + \dots + \varepsilon

beta_j the slope of Y per one-unit change in X_j, holding other predictors fixed; epsilon the residual.

Read the formula in context: Linear regression

A coefficient is conditional on the model and included variables. Adjustment does not by itself remove confounding; extrapolation can be especially fragile.

Further reading: CMU · Models, diagnostics and scientific reports · An Introduction to Statistical Learning.

Before you begin

What you will learn

  • Distinguish observed responses, fitted values and residuals.
  • Use assumptions and diagnostics to qualify model-based claims.
  • Separate training fit, future prediction and causal interpretation.

A fitted line is a starting point

For a simple fitted linear relationship, y^i=b0+b1xi\hat{y}_i=b_0+b_1x_i is the model's fitted value for row ii. The residual ei=yi−y^ie_i=y_i-\hat{y}_i compares that fitted value with the observed response. It is not the same as an unobserved population error or a future prediction error.

A coefficient describes a relationship under the model and its conditioning choices. It does not become a causal effect merely because other predictors were included. Examine the design, functional form, residual patterns and influential observations before trusting an interpretation.

A model can fit training observations well and perform poorly on new cases. Validation should reflect the intended use and preserve relevant grouping or time order. A confidence interval for a modeled mean and a prediction interval for an individual response answer different questions.

Worked reasoning / Original illustration

Fit for which task?

A team fits a model to historical service times and wants to use it for next month’s staffing.

  1. Check whether the historical observations represent the future setting and whether there are time or group dependencies.
  2. Inspect residual behavior, extrapolation and influential cases rather than only a fit score.
  3. Evaluate predictions on appropriately separated data, using a performance measure that matches the staffing decision.

The intended prediction setting determines what a useful evaluation must preserve.

Read the ideas in sequence

Follow these readings, then return for the reasoning check below.

  1. 5.1
    Linear regression

    Linear regression fits a straight-line relationship between a continuous outcome and one or more predictors, reporting each predictor's coefficient with a significance test, an overall model fit (R-squared), and a full set of assumption diagnostics.

  2. 5.2
    Linearity

    Linearity is the assumption that the outcome changes by a constant amount per unit of a predictor (OLS) or by a constant amount on the log-odds scale (logistic regression), rather than curving.

  3. 5.3
    Residual

    A residual is the difference between an observed value and the value the model predicted for it: residual = observed minus fitted.

  4. 5.4
    Prediction interval

    A 95% prediction interval is a range built so that, in repeated use, 95% of such intervals contain a single new observation at the given predictor values; it is wider than the confidence interval for the mean because it covers the scatter of individual values as well as the uncertainty in the fitted line.

  5. 5.5
    Overfitting

    Overfitting is when a model learns the noise and idiosyncrasies of its training data so closely that it fits new, unseen data noticeably worse than it fit the data it was trained on.

  6. 5.6
    Cross-validation

    Cross-validation estimates how well a model will perform on new data by repeatedly holding out part of the data for testing while fitting on the rest, and averaging performance over the held-out parts.

Pause and reason

Check your understanding

Adding predictors improves a model’s training fit. Has its performance on future cases necessarily improved?

Show explanation

No. Extra flexibility can capture noise in the training data. Compare appropriate validation performance and inspect the model’s assumptions and intended use. A training-fit improvement alone does not establish better generalization.

Take it with you

Keep the observation, fitted value, residual, inference and future prediction in their separate roles.

Begin this chapter's readings →

Further university reading

The chapter bridges and reasoning checks are original KernelStats material. These sources offer further study; they have not reviewed or endorsed this book. Read about sources and review limits.