# set.seed(1)

n = 100

m = 1

x = rnorm(n)
y = m*x + 0.5*rnorm(n)

par(pty = 's')
window.max = 5
plot(x, y, pch = 16, cex = 0.5, xlim = c(-window.max, window.max), ylim = c(-window.max, window.max))

lm.out = lm(y ~ x)
abline(a = lm.out$coefficients[1], b = lm.out$coefficients[2])
ypred = lm.out$fitted.values
segments(x0 = x, x1 = x, y0 = ypred, y1 = y)