multiple.regression.with.ci <- function(regress.out, level=0.95) { ################################################################ # # # This function takes the output from an lm # # (linear model) command in R and provides not # # only the usual output from the summary command, but # # adds confidence intervals for intercept and slope. # # # # This version accommodates multiple regression parameters # # # ################################################################ usual.output <- summary(regress.out) t.quantile <- qt(1-(1-level)/2, df=regress.out$df) number.vars <- length(regress.out$coefficients) temp.store.result <- matrix(rep(NA, number.vars*2), nrow=number.vars) for(i in 1:number.vars) { temp.store.result[i,] <- summary(regress.out)$coefficients[i] + c(-1, 1) * t.quantile * summary(regress.out)$coefficients[i+number.vars] } intercept.ci <- temp.store.result[1,] slopes.ci <- temp.store.result[-1,] output <- list(regression.table = usual.output, intercept.ci = intercept.ci, slopes.ci = slopes.ci) return(output) }