### A function for Mallow's CP statistic. ### This function takes 2 arguments; ### 1. A saved "lm" object from the model of interest. ### 2. A saved "lm" object from the kitchen sink model mallows <- function(small.mod,large.mod) { ### number of parameters in the small model num.params <- small.mod$rank ### MSE for the small model s.sq <- (summary(small.mod)$sigma)^2 ### MSE for kitchen sink sig.sq <- (summary(large.mod)$sigma)^2 ### residual df for kitchen sink model res.df <- summary(small.mod)$df[2] mallowscp <- num.params + (s.sq - sig.sq) * res.df / sig.sq return(mallowscp) } ### Calculating the press residuals for an lm object press.resid <- function(my.model) { press.resids <- residuals(my.model)/(1 - lm.influence(my.model)$hat) press.stat <- sum(press.resids^2) return(press.resids) } ### Calculating the press statistic for an lm object press.stat <- function(my.model) { return(sum(press.resid(my.model)^2)) }