Residual Plots with Simulated Data

The Good Case (p=1)

We generate some data with \(p=1\) which perfectly follows the model:

n <- 20
x <- runif(n, -2, 3)
y <- 1 + 2 * x + rnorm(n, 0, 0.2)

Since \(p=1\) we can consider an x-y-plot in addition to a residual plot and a Q-Q-plot:

m <- lm(y ~ x)
plot(x, y)
abline(m)

plot(fitted(m), resid(m), xlab="fitted values", ylab="residuals")

qqnorm(resid(m))

library(car)
qqPlot(resid(m))