Eric Vander Wal
2008-Jul-07 15:18 UTC
[R] Running "all possible subsets" of a GLM (binomial) model
I have spent a fair amount of time looking for a package that is automated to run glm (binomial) regression models with all possible subsets of my independent variables. Something akin to Lumley's "leaps" package, but can be applied to glms, not just lms; or something similar to Stata's brute force "tryem" function? If anyone can point me in the right direction I would really appreciate it. Thanks, Eric vdWal [[alternative HTML version deleted]]
hadley wickham
2008-Jul-07 17:04 UTC
[R] Running "all possible subsets" of a GLM (binomial) model
On Mon, Jul 7, 2008 at 10:18 AM, Eric Vander Wal <ejvander at lakeheadu.ca> wrote:> I have spent a fair amount of time looking for a package that is automated > to run glm (binomial) regression models with all possible subsets of my > independent variables. Something akin to Lumley's "leaps" package, but can > be applied to glms, not just lms; or something similar to Stata's brute > force "tryem" function? If anyone can point me in the right direction I > would really appreciate it.Have a look at fitall in the meifly package: fitall <- function(y, x, method=lm, ...) { data <- cbind(y=y, x) combs <- do.call(expand.grid, rep(list(c(FALSE, TRUE)), ncol(x)))[-1, ] vars <- apply(combs, 1, function(i) names(x)[i]) form <- paste("y ~ ", lapply(vars, paste, collapse=" + "), sep = "") form <- lapply(form, as.formula) models <- lapply(form, function(f) eval(substitute(method(f, data=data, ...), list(f=f, data=data, method=method)))) names(models) <- 1:length(models) class(models) <- c("ensemble", class(models)) models } That should get you started - the meifly package also contains a few functions for summarising and visualising these ensembles of models. See http://had.co.nz/meifly/ for a little more detail, and a paper using meifly for a simple case study. Hadley -- http://had.co.nz/
Ben Bolker
2008-Jul-07 17:07 UTC
[R] Running "all possible subsets" of a GLM (binomial) model
Eric Vander Wal <ejvander <at> lakeheadu.ca> writes:> > I have spent a fair amount of time looking for a package that is automated > to run glm (binomial) regression models with all possible subsets of my > independent variables. Something akin to Lumley's "leaps" package, but can > be applied to glms, not just lms; or something similar to Stata's brute > force "tryem" function? If anyone can point me in the right direction I > would really appreciate it. > > Thanks, Eric vdWal > > [[alternative HTML version deleted]] >There is a "dRedging" package at http://www.zbs.bialowieza.pl/users/kamil/r/ that is oriented toward model-averaging but might do what you want. (The potential for abuse of this package makes me terribly nervous, but if used with great care and common sense I can see that it can be useful.) Ben Bolker