Superb Jean, many thanks

Ross

From:  Jean V Adams <jvadams@usgs.gov>
Date:  Tuesday, 6 November 2012 19:20
To:  Ross Ahmed <rossahmed@googlemail.com>
Cc:  <r-help@r-project.org>
Subject:  Re: [R] Apply same linear model to subset of dataframe

DV <- c("mpg", "drat", "gear")
IV <- list(c("cyl", "disp", "hp"), c("wt", "qsec"), c("carb", "hp"))
fits <- vector("list", length(DV))

for(i in seq(DV)) {
        fit <- lm(formula=paste(DV[i], paste(IV[[i]], collapse="+"),
sep="~"), data=mtcars)
        plot(fit$fitted, fit$resid, main=paste("DV", DV[i], sep="="))
        lapply(fit$model[, -1], function(x) plot(x, fit$resid))
        fits[[i]] <- fit
        } 


	[[alternative HTML version deleted]]


