Teaching with the labs

Each lab is designed for a single misconception and a single class of decisions. The pattern below takes about fifteen minutes and works as a lecture interlude, a lab section, or an asynchronous assignment.

1. Predict

Students answer the prediction prompt before touching a control. Most classes converge on the same wrong answer, which is exactly the point — the disagreement is the lesson.

2. Observe

Load a preset and move one control. The linked graphics update immediately, so cause and effect stay attached. Teacher mode surfaces the readouts worth writing on the board.

3. Explain

Open the mathematics tab to name what was seen, then the R bridge to connect it back to the textbook's code. Students export a permalink with their notes.

Misconception inventory

The claim each live lab is built to overturn, with the correction it demonstrates.

Sampling Distributions & the Limits of the CLT

Chapter 1 — Foundations, Data Science, Ethics, and the R Environment

Once n is above about 30, the sampling distribution is normal.

The threshold is a rule of thumb for mildly skewed, finite-variance populations. Log-normal data at n = 30 is still visibly skewed, and Cauchy data is never normal at any n because the CLT's finite-variance hypothesis fails.

The CLT doing its job
Skew that survives n = 30
The CLT failing
Robustness rescues it
Open lab

Missingness Mechanisms: MCAR, MAR, MNAR

Chapter 2 — Data Quality, Missingness, and Exploratory Visual Analytics

If I impute the missing values, I have recovered the missing data.

Imputation is a device for using the rows you kept, not for recreating information you never observed. Mean imputation fabricates a spike at the centre and shrinks the variance; under MNAR, even a perfectly specified conditional model remains biased because the deletion depends on the value that was deleted.

MCAR, complete cases
MAR, repaired
MNAR with mean imputation
Variance collapse
Open lab

Conditioning, Collinearity, and Unstable Coefficients

Chapter 3 — Linear Algebra, Matrix Computing, and Regression

Collinearity biases my regression coefficients, so I should drop one predictor.

Least squares stays unbiased at any ρ < 1; only the variance inflates. Dropping a genuinely relevant predictor introduces real omitted-variable bias, trading a variance problem for a bias problem. If prediction is the goal, collinearity may be harmless; if a single coefficient must be interpreted, the fix is better data or a regularized/identifiable target such as the sum.

Orthogonal design
Textbook warning zone
Near-singular
More data, same VIF
Open lab

PCA Geometry: Projection, Scale, and What Variance Means

Chapter 4 — Linear and Nonlinear Dimensionality Reduction

PCA finds the intrinsic structure of my data, whatever units I measure in.

PCA on the covariance matrix is not invariant to rescaling a single variable. Changing metres to millimetres inflates that variable's variance by a factor of a million and drags PC1 onto it. Only decomposition of the correlation matrix (standardizing first) is invariant, which is why it is the default for variables in different units.

Comparable units
The unit trap
Same data, standardized
No preferred direction
Open lab

Accuracy Is a Trap: Metrics Under Class Imbalance

Chapter 5 — Supervised Classification

My classifier is 99% accurate, so it works well.

With 1% prevalence, predicting “negative” for everyone is 99% accurate and useless. Accuracy weights both error types by their frequency, which hides failures on the rare class that usually matters most. Report sensitivity and precision at a stated threshold, plus AUC or average precision for the ranking, and always give the majority-class baseline for comparison.

Balanced problem
Rare disease screening
The lazy classifier
No signal at all
Open lab

Cluster Geometry: k-means, DBSCAN, and Shapes That Break Them

Chapter 8 — Unsupervised Clustering

The elbow in the inertia curve tells me the right number of clusters.

Inertia falls monotonically with k by construction, and on data with no clusters at all it still produces a smooth curve with a visible bend. An elbow is a heuristic about diminishing returns, not evidence about the number of groups. Use it alongside stability across resamples, a validation index appropriate to the cluster shape, and — decisively — subject-matter meaning.

Where k-means shines
Where k-means fails
Density to the rescue
Clusters from nothing
Open lab

Calibration Is Not Discrimination

Chapter 9 — Model Performance Assessment and Validation

My model has an AUC of 0.85, so its predicted probabilities are reliable.

AUC only measures whether positives are ranked above negatives; it is invariant to every monotone rescaling of the scores. A model can achieve any AUC while reporting probabilities that are systematically double the truth. Whenever probabilities feed a decision — treatment thresholds, expected loss, resource allocation — you must report calibration (reliability diagram, ECE, Brier, log loss) alongside discrimination, and recalibrate if needed.

Perfectly calibrated
Overconfident
Systematically alarmist
Weak but honest
Open lab

LASSO Paths, Cross-Validation, and False Discoveries

Chapter 11 — Variable Importance and Controlled Feature Selection

The variables selected at the cross-validated λ are the true predictors.

Cross-validation optimizes out-of-sample prediction error, and prediction tolerates extra weakly correlated variables far more happily than it tolerates dropping a real one. So the CV-optimal model habitually includes false discoveries, and it also under-reports the size of true effects because of shrinkage. For inferential claims about which variables matter, use methods designed for that target — knockoffs, stability selection, or debiased inference — rather than reading off the LASSO's support.

Clean sparse problem
p greater than n
Correlated predictors
Over-regularized
Open lab