Skip to main content
Module 7 · Lesson 3 of 316/18 in the course~24 min
Module lessons (3/3)

Residual, Outlier and Train/Test Split diagnostics

Lesson preview5 hands-on exercises readyCourse R · Module 7 — Regression and Linear Models

Analyze residuals(fit), calculate RMSE/MAE, find high leverage outliers with cooks.distance() and validate out-of-sample.

What you'll learn in this lesson

  • Extract residuals (residuals(fit)) and estimated values (fitted(fit)) to measure RMSE and MAE error.
  • Test the assumptions of the linear model: linearity, homoscedasticity and normality of the residuals (shapiro.test()).
  • Identify anomalous high influence/leverage observations via cooks.distance(fit).
  • Perform a reproducible Train/Test (70/30) split with set.seed() and sample() to measure true generalization while avoiding overfitting.

Overview

A value of R² = 0.90 on the training set can hide serious problems: a nonlinear curve forced into a straight line, a single outlier that distorts the slope, or an overly complex model that stores noise instead of signal. The diagnostics in R serve precisely to unmask these risks before using the model.

Enable Show residuals (e = y - y_hat) and Add extreme outlier on the Budget Ads -> Sales preset: watch the red dotted vertical segments stretch and R² collapse under the weight of just one high-leverage anomalous point!

Sections covered in this lesson

  1. 1Immediately observe the effect of residuals and outliers
  2. 2Error metrics and diagnostic tools in Base R
  3. 3Test yourself: guided exercises
  4. 4Concept check
Pro Lesson · Module 7 — Regression and Linear Models

Unlock "Residual, Outlier and Train/Test Split diagnostics" and the full Course R curriculum

Analyze residuals(fit), calculate RMSE/MAE, find high leverage outliers with cooks.distance() and validate out-of-sample.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course R plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.