library(MASS) # rlm function does M-estimation # by default it uses the Huber loss function # you can specify others with the psi argument i.e. psi = psi.bisquare # otherwise it works a lot like lm x <- sort(4 * rnorm(20)) y <- 3 * x + c(rnorm(18), 32 * rnorm(2)) df <- data.frame(x = x, y = y) plot(x, y) fit.huber <- rlm(y ~ x, data = df) coef(fit.huber) abline(coef(fit.huber)[1], coef(fit.huber)[2]) fit.lm <- lm(y ~ x, data = df) abline(coef(fit.lm)[1], coef(fit.lm)[2], lty = "dashed") legend(-4, 80, legend = c("Least squares","Huber"), lty = c("dashed", "solid")) # Standardized residuals (just since you've seen them in class) rstandard(fit.lm) # what the book calls deletion residuals rstudent(fit.lm) # and some other things you may have seen hatvalues(fit.lm) cooks.distance(fit.lm)