lmdiag <- function(m1) { if(length(class(m1)) == 0) stop("not a fitted model") if(class(m1) != "lm") stop("not an lm object") s <- summary(m1)$sigma lmi <- lm.influence(m1) e <- resid(m1) if(length(m1$weights) > 0) e <- e * sqrt(m1$weights) si <- lmi$sigma h <- lmi$hat g <- 1 - h k <- e/g^0.5 isr <- k/s esr <- k/si pressi <- resid(m1)^2/(1 - h)^2 dffits <- (h^0.5 * e)/(si * g) cooks <- (isr^2 * h)/(g * m1$rank) xx <- cbind(resid(m1), isr, esr, h, cooks, dffits,pressi) xx <- data.frame(xx) names(xx) <- c("resid", "int.stud", "ext.stud", "leverage", "cooks", "dffits","press") xx }