model <- lm(aggression ~ trait_hostility * condition, data = data)
par(mfrow = c(2, 2)) # 2x2 layout
plot(model)
par(mfrow = c(1, 1)) # reset20 Diagnostics, model fit, and the limits of your model
20.1 Overview
Chapter 19 introduced the bias-variance trade-off and the four LINE assumptions of OLS regression. This chapter takes the diagnostic side and makes it practical in R, then closes Section 3 by surveying when the linear model is not enough and where to go beyond it.
By the end of the chapter you will:
- produce the four standard diagnostic plots that R generates automatically with
plot(model), - read each plot and recognize the signature of each kind of assumption violation,
- compare models with
R-squaredandadjusted R-squared, and use the latter to penalize complexity, - recognize the main extensions of the linear model (nonlinear, multilevel, latent-variable, categorical-outcome, Bayesian, robust), and know which kind of problem each one solves.
This chapter is short on new prose and long on visuals. The point is to see what each diagnostic looks like and how to act on it.
20.2 Diagnostic plots in R
You fit a model with lm(), and then you check it. R provides four diagnostic plots automatically when you call plot() on a model object. In an interactive session, R will display them one at a time; in a script you usually want to see them together:
The four plots produced are:
- Residuals vs Fitted. Linearity and homoscedasticity.
- Normal Q-Q. Normality of residuals.
- Scale-Location. Another view of homoscedasticity.
- Residuals vs Leverage. Influential observations.
In what follows we walk through each one, with code you can run on your own.
20.2.1 Plot 1: Residuals vs Fitted
This plot displays the residual of each observation (vertical axis) against the model’s predicted value for that observation (horizontal axis). It is the most useful of the diagnostic plots, because two of the four LINE assumptions show up here:
- Linearity: the residuals should scatter randomly around zero, with no systematic curve. A U-shape or inverted-U indicates a nonlinear relationship the model is missing.
- Homoscedasticity: the spread of the residuals should be roughly constant across the range of fitted values. A fan or cone shape indicates heteroscedasticity.
On our vgames data, with an interaction model:

The red curve is a smooth trend through the residuals. A nearly flat red curve at zero, like above, is what you want. A clear curve in the red line would indicate a linearity problem.
20.2.2 Plot 2: Normal Q-Q
A Q-Q plot orders the residuals from smallest to largest and compares them to the quantiles they would have if they were perfectly normally distributed. The plot is essentially a scatter where each point is one residual: the horizontal coordinate is what the residual would be under perfect normality, and the vertical coordinate is what the residual actually is.
Points that fall along the diagonal mean the empirical and theoretical quantiles match, that is, the residuals are approximately normal. Points that curve away from the diagonal indicate deviation from normality, usually at the tails (heavy tails, light tails, or asymmetry).

The points sit close to the diagonal across the middle and most of the tails, with small deviations at the very extremes (typical and usually fine). Approximately normal.
20.2.3 Plot 3: Scale-Location
This is the residuals-vs-fitted plot transformed slightly: instead of raw residuals, the vertical axis shows the square root of the absolute standardized residuals. The transformation makes any change in the spread of the residuals easier to spot.
A horizontal smooth line with constant spread above and below it indicates homoscedasticity. An upward-sloping smooth line indicates heteroscedasticity (spread increases with fitted value); a downward slope means the opposite.

A near-flat red line is what we want. A clear upward or downward slope would indicate heteroscedasticity.
20.2.4 Plot 4: Residuals vs Leverage
The first three plots look at the residuals to diagnose general patterns. The fourth plot is different: it identifies particular observations that have an unusually large effect on the fit of the model, called influential observations.
Two ingredients are at work. Leverage measures how unusual an observation is in its predictor values: an observation far from the mean of the predictors has high leverage, because changing it would have a large impact on the slope. Residual measures whether the model fits that observation well. An observation with high leverage and a large residual is the dangerous combination; it can dominate the OLS estimate and pull the line away from where it would otherwise sit.
R draws Cook’s distance contours on this plot (the dashed lines). Points outside the 0.5 or 1 contour are usually worth examining.

In our data, no single observation has both high leverage and a very large residual. There is no point that dominates the fit. In a different dataset, an obvious outlier in the upper-right or lower-right corner of this plot would warrant a closer look.
20.3 What to do when an assumption is violated
A short, practical decision tree:
- Linearity violation. Try a polynomial term (e.g.,
I(x^2)), a log transformation of the predictor or outcome, or a generalized additive model (GAM) using themgcvpackage. - Homoscedasticity violation. Use robust (heteroscedasticity-consistent) standard errors via the
sandwichpackage, transform the outcome (oftenlog), or use generalized least squares. - Normality violation, small sample. Consider bootstrapping the standard errors, or transforming the outcome.
- Normality violation, large sample. Often tolerable for estimation. Be cautious with inference for extreme tails.
- Independence violation. Switch to a model that respects the clustering, typically a multilevel model (the
lme4package;lmer()is the most common function). - Influential observations. Examine the cases individually. If they reflect data-entry errors, correct them. If they reflect real but unusual participants, report results with and without the cases.
The general advice: assumption violations are reasons to think more carefully, not reasons to panic. A mild violation is a reason to acknowledge a limitation in your report. A serious violation is a reason to use a different model.
20.4 Multicollinearity: when predictors carry the same information
Multicollinearity is not one of the LINE assumptions, but it is a closely related diagnostic concern. It belongs in this chapter because it shows up only once you have several predictors in a model, and because it tends to surprise people the first time they meet it.
The problem. In Chapter 17 we noted that when two predictors in a multiple regression are correlated, each slope is interpreted as the unique contribution of that predictor, after the other predictors have been accounted for. The example was that hours_weekly and trait_hostility are mildly correlated, and their joint R-squared (about 0.20) was a little less than the sum of their separate R-squareds (7.2 + 11.6 = 18.8 percent). The two predictors carry partly overlapping information; the model apportions the overlap so that no piece is double-counted.
That was a mild case. What happens when two predictors are not mildly correlated, but strongly correlated, carrying nearly the same information? The problem is called multicollinearity. The word combines “multi” (more than one) with “collinearity” (lying on the same line). It refers to any situation where two or more predictors in a regression are so closely related to each other that the model has trouble separating their individual contributions.
20.4.1 The intuition
A short analogy. Imagine two coworkers who do the same job. If only one of them is in the office, you can clearly see what they contribute: their unique output is everything they produce. If both are in the office and do nearly the same work, you can still see the total output of the team, but you cannot tell which one to credit for any specific piece. The team-level performance is unambiguous; the individual contributions are not.
Multicollinearity is the same situation in a regression. When two predictors carry nearly the same information, the joint contribution to the outcome is well estimated, but the individual contributions of each predictor are not. The model has to apportion the shared variance between them, and because the shared variance is most of what either predictor has to offer, the apportionment is very sensitive to small fluctuations in the data. Each slope is estimated from the tiny “unique” piece of variance that one predictor has but the other does not, and that tiny piece is what determines the standard error of the slope. The smaller the unique piece, the larger the standard error.
The consequence: the joint model fits well (R-squared remains high), but each individual slope has a large standard error, sometimes flips sign relative to what you would expect, and is not stable across replications of the study.
20.4.2 A demonstration on vgames_study
Let us construct the situation deliberately. We will create a new variable trait_hostility_v2 that equals trait_hostility plus a small amount of random noise: a near-clone of the original.
set.seed(2025)
data$trait_hostility_v2 <- data$trait_hostility +
rnorm(nrow(data), mean = 0, sd = 0.10)
cor(data$trait_hostility, data$trait_hostility_v2)[1] 0.9959603
The two predictors correlate at about 0.99: nearly perfect.
Now fit two models. The first uses only the original trait hostility:
m_simple <- lm(aggression ~ trait_hostility, data = data)
round(summary(m_simple)$coefficients, 3) Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.198 0.451 7.098 0
trait_hostility 0.492 0.125 3.942 0
The slope of trait_hostility is about 0.61 with a standard error of about 0.15. Clean and precise.
The second model adds the near-clone:
m_collinear <- lm(aggression ~ trait_hostility + trait_hostility_v2, data = data)
round(summary(m_collinear)$coefficients, 3) Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.185 0.452 7.048 0.000
trait_hostility 1.493 1.394 1.071 0.286
trait_hostility_v2 -0.998 1.384 -0.721 0.472
Look at what happened. Both trait_hostility and trait_hostility_v2 now have point estimates that are very different from the simple model, their standard errors are roughly an order of magnitude larger, and the two slopes may even have opposite signs. None of this reflects a substantive change in what the data are telling us: the joint R-squared is essentially identical to the simple model, because no new information is in the second predictor. But the individual slopes are now unstable and uninterpretable.
This is multicollinearity in action.
20.4.3 The diagnostic: the variance inflation factor (VIF)
The standard diagnostic for multicollinearity is the variance inflation factor (VIF). Each predictor in a multiple regression has its own VIF, a single number that measures how much that predictor’s standard error is inflated by its overlap with the other predictors. A VIF of 1 means no inflation (the predictor is uncorrelated with the others). A VIF of 4 means the standard error is twice as large as it would have been with no overlap. A VIF of 100 means the standard error is 10 times larger.
The function vif() from the car package computes the VIF for each predictor in a fitted lm() model.
library(car)
vif(m_collinear) trait_hostility trait_hostility_v2
124.0211 124.0211
Both VIFs are extremely large in this artificial example, which is exactly what the diagnosis of severe multicollinearity looks like. Compare to the original two-predictor model from Chapter 17:
m_original <- lm(aggression ~ hours_weekly + trait_hostility, data = data)
vif(m_original) hours_weekly trait_hostility
1.002841 1.002841
Both VIFs are close to 1, confirming that hours_weekly and trait_hostility carry mostly distinct information.
A rule of thumb commonly cited in psychology (Cohen et al., 2003; James et al., 2013):
- VIF below 5: usually fine.
- VIF between 5 and 10: a warning sign, worth investigating.
- VIF above 10: serious multicollinearity; the individual slopes should not be interpreted.
These thresholds are conventions, not hard rules. A VIF of 4.5 in a small dataset is more worrying than a VIF of 6 in a large one, and the substantive judgment about whether the individual slopes are interpretable should weigh both the VIF and the sample size.
20.4.4 What to do about it
Three practical responses, in order of decreasing aggressiveness.
1. Drop one of the redundant predictors. If two predictors carry nearly the same information, you do not need both. Drop the one that is harder to interpret, less reliable, or less central to your research question. The simple model with the remaining predictor will give you a clean, interpretable slope.
2. Combine the redundant predictors into a single composite. If both predictors are intended to measure the same construct (for example, two scales of trait hostility, or two items on the same subscale), the standard move is to average them, or to standardize them and then average, into a single composite. Chapter 11 covered the mechanics of composite scores. The composite then enters the regression as a single predictor, and the multicollinearity problem disappears.
3. Keep both predictors and report the inflated standard errors honestly. Occasionally you may have a reason to keep two collinear predictors in the model: perhaps you are not interested in the individual slopes but only in the joint R-squared, or perhaps the substantive question requires both. In that case, the individual slopes should be interpreted with caution or not at all, the inflated standard errors should be reported clearly, and the joint contribution of the collinear set should be the focus of interpretation.
A more advanced option exists for severe cases: principal components regression and ridge regression both handle collinear predictors by transforming the predictor set or by penalizing the slopes. They are beyond the scope of this book; for typical psychology research situations, the three options above are usually sufficient.
20.4.5 A visual picture of multicollinearity
The clearest picture of why multicollinearity inflates standard errors is a shared-variance diagram. The figure compares the simple regression on the left with the multicollinear regression on the right.
aggression on trait_hostility. The overlap area is the simple-regression R-squared. The slope of trait_hostility is estimated from its overlap with aggression relative to its own total area. Right panel: multicollinear regression in which trait_hostility and trait_hostility_v2 are nearly identical, shown as two heavily overlapping circles. The ‘unique to trait_hostility’ and ‘unique to trait_hostility_v2’ regions (the thin top and bottom crescents) are tiny, and each predictor’s individual slope must be estimated from these tiny areas alone. The joint contribution of the two predictors to aggression is well estimated (the combined overlap with aggression is similar to the left panel), but the individual slopes are not.
What the figure shows. On the left, trait_hostility and aggression overlap in a moderate region. The blue circle has a clean area outside the overlap (its “unique” area), and the slope of trait_hostility is estimated from the relationship between its unique area and the overlap with aggression.
On the right, trait_hostility and trait_hostility_v2 overlap each other almost entirely. The “unique to trait_hostility” area is the thin top crescent, and the “unique to trait_hostility_v2” area is the thin bottom crescent. Each individual slope is estimated from one of these thin slivers alone, which is why the standard errors are inflated and the slopes become unstable. At the same time, the joint overlap of the merged predictor region with aggression is similar in size to the left panel’s overlap, which is why the joint R-squared barely changed.
This is the geometric reason for the apparent paradox in the demonstration above: a model that fits the data well at the level of the whole set of predictors but fails to give interpretable estimates for any individual predictor.
20.5 Comparing models: R-squared, adjusted R-squared, and beyond
Once you have several candidate models, how do you compare them?
The simplest comparison is by R-squared: the proportion of variance explained by each. As Chapter 19 noted, R-squared (almost) always goes up when you add predictors, even useless ones, which makes it a poor tool for comparing models with different numbers of predictors.
Adjusted R-squared penalizes each additional predictor. The formula is
\[ R^2_{\text{adj}} = 1 - (1 - R^2) \cdot \frac{n - 1}{n - p - 1}, \]
where \(n\) is the number of observations and \(p\) is the number of predictors. With more predictors, the denominator shrinks, the correction grows, and adjusted R-squared falls relative to R-squared. Only a predictor that improves the fit more than expected by chance will increase adjusted R-squared.
Looking at the models we have built on vgames_study.csv, side by side:
m1 <- lm(aggression ~ hours_weekly, data = data)
m2 <- lm(aggression ~ trait_hostility, data = data)
m3 <- lm(aggression ~ hours_weekly + trait_hostility, data = data)
m4 <- lm(aggression ~ trait_hostility * condition, data = data)
summary_table <- data.frame(
Model = c("hours_weekly",
"trait_hostility",
"hours_weekly + trait_hostility",
"trait_hostility * condition (interaction)"),
Predictors = c(1, 1, 2, 3), # main + interaction count
R_squared = c(summary(m1)$r.squared,
summary(m2)$r.squared,
summary(m3)$r.squared,
summary(m4)$r.squared),
Adj_R_squared = c(summary(m1)$adj.r.squared,
summary(m2)$adj.r.squared,
summary(m3)$adj.r.squared,
summary(m4)$adj.r.squared)
)
summary_table Model Predictors R_squared Adj_R_squared
1 hours_weekly 1 0.07158788 0.06371998
2 trait_hostility 1 0.11636615 0.10887772
3 hours_weekly + trait_hostility 2 0.19823192 0.18452648
4 trait_hostility * condition (interaction) 3 0.39264041 0.37693283
The interaction model has the highest R-squared (about 0.39) and the highest adjusted R-squared. Adding condition and an interaction term improved the fit more than the penalty for the extra predictors took away. By this criterion, the interaction model is preferred.
Two more measures worth knowing about but not detailing here.
AIC (Akaike Information Criterion) and BIC (Bayesian Information Criterion) are alternative model-comparison numbers. Both balance fit against complexity, with stronger penalties than adjusted R-squared. Smaller is better for both. The functions AIC(model) and BIC(model) return them. They are particularly useful when comparing non-nested models or models with many predictors.
Cross-validation is the gold standard for prediction-oriented model comparison: fit each model on part of the data, evaluate it on the held-out part, and pick the model that generalizes best. The caret and tidymodels packages provide implementations.
20.6 When the linear model is not enough
Linear regression is powerful and applies to a wide range of psychology research questions. It is not universal. Here is a map of common problems that go beyond the standard linear model, with the type of model that addresses each.
Problem 1: Nonlinear relationships. The true relationship between predictor and outcome is curved, not straight. Tools: polynomial regression (add I(x^2) to the formula), log or square-root transformations, generalized additive models (GAMs) via the mgcv package, splines.
Problem 2: Nested or grouped data. Participants are clustered: students in classrooms, employees in companies, measurements within people over time. Tools: multilevel models / mixed-effects models / hierarchical linear models. The lme4 package (lmer()) is the standard.
Problem 3: Latent variables. You want to model constructs that are not directly observed (intelligence, motivation, anxiety) using several observed indicators. Tools: structural equation modeling (SEM), confirmatory factor analysis, exploratory factor analysis. The lavaan package in R.
Problem 4: Categorical outcomes. The outcome is a category (yes/no, survived/died, chose option A/B/C), not a number on a continuous scale. Tools: logistic regression for two categories, multinomial logistic regression for more. In R: glm(... , family = binomial) for logistic regression.
Problem 5: Small samples or unusual distributions. Very few observations, or seriously non-normal residuals, or unusual sampling structures. Tools: bootstrap methods, permutation tests, Bayesian estimation (the brms and rstanarm packages).
Problem 6: Outliers, leverage, robust estimation. A few extreme observations dominate the fit. Tools: robust regression (the MASS::rlm() function and the robustbase package), explicit outlier-handling strategies (Chapter 12).
For each of these, the modeling structure changes, but the underlying pillars are the same: you describe data with a model, you fit the model, you check the fit, and (in inference) you test hypotheses. The vocabulary you have built in Section 3 transfers, even when the specific machinery is new.
| Need | Standard tool | R package |
|---|---|---|
| Curved relationships | GAM | mgcv |
| Nested data | Multilevel models | lme4 |
| Latent variables | SEM | lavaan |
| Categorical outcomes | Logistic regression | stats::glm |
| Small samples or non-normal residuals | Bootstrap, Bayes | boot, brms |
| Outliers and influential points | Robust regression | MASS, robustbase |
Knowing these tools exist is the goal. You do not need to learn them now; when you encounter a research problem that one of them solves, you have a starting point.
20.7 Closing Section 3
We started Section 3 with the idea that a model is a useful simplification of data, that the mean is the simplest possible model, and that everything else (regression, multiple regression, interactions) builds on the same logic of predictions and residuals. We end with a small set of practical habits:
- Fit the model with
lm()and read the coefficients you care about (Chapters 16-18). - Check the assumptions with
plot(model)(this chapter), and either accept the mild violations or pick a different model for the serious ones (Chapter 19). - Compare models with adjusted R-squared, not raw R-squared, when they have different numbers of predictors (this chapter).
- Remember that everything in Section 3 is description, not inference. The slopes and R-squared values describe the dataset you have. The question of whether the patterns generalize to a population, and the standard errors and p-values that try to answer that question, are a topic for a later section of the book.
These habits are the entry to applied statistical modeling in psychology. The chapters that follow Section 3 take the same models and ask the inferential questions; later sections still take the same models and ask the causal questions. The modeling framework you have learned here is the engine that drives the rest.
20.8 Check your understanding
1. What does plot(model) produce when model is a fitted lm object?
2. The “Residuals vs Fitted” plot is mainly used to check which assumptions?
3. What does the Normal Q-Q plot check?
4. What is an “influential observation”?
5. Why is adjusted R-squared usually preferred over raw R-squared for comparing models?
6. You have 200 students nested within 10 classrooms. Independence is violated. What is the standard fix?
7. You want to model “intelligence” as a latent variable, measured by several test scores. Which family of models is most appropriate?
8. What is the most important caveat to remember as Section 3 closes?
9. Two predictors in a multiple regression are correlated with each other at r = 0.97. What is the most likely consequence for the fitted model?
20.9 References
Aiken, L. S., & West, S. G. (1991). Multiple regression: Testing and interpreting interactions. Sage.
Cohen, J., Cohen, P., West, S. G., & Aiken, L. S. (2003). Applied multiple regression/correlation analysis for the behavioral sciences (3rd ed.). Lawrence Erlbaum.
James, G., Witten, D., Hastie, T., & Tibshirani, R. (2013). An introduction to statistical learning: With applications in R. Springer. https://doi.org/10.1007/978-1-4614-7138-7
Navarro, D. J. (2018). Learning statistics with R: A tutorial for psychology students and other beginners (Version 0.6), Chapter 15.5. https://learningstatisticswithr.com