Session 8: From Explanation to Prediction

Published

16 11 2026

Modified

13 10 2026

Note

Monday, 16 November 2026, 09:00–11:15 · Room MAD 099

What this session is about

The hotel group asks two questions that sound almost the same:

  1. How much more do central hotels charge than comparable hotels further out?
  2. What price can a new hotel — two kilometres out, four stars — charge?

Both are answered with a regression, the tool you know from Statistik II. But the first is about explaining a pattern in the data we have, and the second is about predicting a number for a hotel that is not in the data. They are judged in completely different ways.

  • Part A — Explaining. A short recap of linear regression: what ordinary least squares does, how to read a model of log prices, and how “holding the star tier constant” finally answers the question from session 2 that the tables could not.
  • Part B — Predicting. A prediction is a best guess — useful only if you know how far off such guesses usually are. How to measure that with the root mean squared error on hotels the model has not seen, why a more flexible model can fit your data better and predict new data worse (overfitting), and why a single train/test split is not enough.

Report 2 is debriefed at the start.

ImportantPackages you need today

Nothing new. broom, which turns model output into tables, comes with the tidyverse.

Learning goals

  • Explain what ordinary least squares does: fitted values, residuals, the sum of squared residuals
  • Say what OLS minimises, and why a model only describes the range of data it was fitted on
  • Explain why prices are modelled on a log scale, and read a log coefficient as a percentage
  • Interpret a coefficient correctly: holding … constant, the model estimates an average association of … — and say what it does not mean
  • Explain why R² never falls when a variable is added
  • Split data into training and test sets, compute the RMSE of a prediction, and read an RMSE on the log scale as a typical factor
  • Recognise overfitting in a chart of training and test error, and explain why the result of one train/test split depends on luck
  • Say whether a question is about explaining or about predicting, and how each is judged

Slides

The slides appear here after the session.

Everything you need for the session is already below.

Materials

File Description
Exercise sheet The in-session exercise
hotels-europe_price.csv Prices — as in sessions 5 to 7
hotels-europe_features.csv Features — as in sessions 5 to 7
Slides Online after the session
Live coding document Online after the session
Exemplary solution Online after the session

Data

The Vienna hotels, taken from the Europe files: hotels in Vienna proper, priced for one weekday night in November 2017 — the rows of sessions 1 to 3, without the session 1 outlier and the single one-star hotel. Every number today can be connected to an earlier one.

Békés and Kézdi (2021), licensed CC BY-NC-SA 4.0. Unmodified.

The question we answer

When is a better-fitting model a worse model?

When it is used to predict. Ordinary least squares makes the errors as small as possible on the data it is given — and it uses every variable and every bend you allow it, even a column of random numbers. On the data it has seen, more flexibility always looks better. On data it has not seen, beyond a point, it looks worse: the model has started to learn the noise.

For explaining, the danger is a different one: a variable you left out. Regression compares like with like, but only on the variables you include.

Take-home until session 9

Important

Read James et al. (2021), ch. 2.2 “Assessing Model Accuracy” — about 15 pages, free at statlearning.com. It covers Part B of today in more depth, with the same central picture.

If you feel uncomfortable in assessing the quality of an explanatory regression model, please read Gräbner-Radkowitsch (2026) as a refresher.

Session 9: hundreds of candidate predictors and no theory about which matter. Lasso and ridge regression — and cross-validation, which answers today’s last problem: one train/test split is luck.

Going further

  • James et al. (2021), ch. 3 — linear regression, including diagnostics
  • Békés and Kézdi (2021), ch. 13 and 14 — the prediction framework, with hotel and Airbnb data
  • The broom package — tidy(), glance() and augment()

References

Békés, G. and Kézdi, G. (2021) Data analysis for business, economics, and policy, Cambridge: Cambridge University Press, available at https://gabors-data-analysis.com/.
Gräbner-Radkowitsch, C. (2026) “Regression Residuals and Model Diagnostics” C. Gräbner-Radkowitsch (ed.), Method and inquiry, available at https://euf-methodology-hub.netlify.app/resources/regression-residuals-diagnostics.
James, G., Witten, D., Hastie, T. and Tibshirani, R. (2021) An introduction to statistical learning with applications in r, 2nd edition., New York: Springer, available at https://www.statlearning.com/.