Dear all, I was working with a GLM model and wondering whether is it possible to have a model description with all possible main effects as well as all interactions. Currently I do it manually however this will become cumbersome if I have large number of variables. Means suppose I have 3 explanatory variables and want to feed automatically with all possible combinations like: glm(Response~1) glm(Response~X) glm(Response~Y) glm(Response~Z) glm(Response~X+Y) glm(Response~X+Z) glm(Response~Z+Y) glm(Response~X+Y+X*Y) glm(Response~X+Z+X*Y) .................................................... all combinations which are possible Thanks and regards,
GLMing with all possible combinations (automatically)
2 messages · Christofer Bogaso, ilai
Hi try glm(Response~ .^2, data=yourdata.frame) For all predictors (.) and 2-way interactions (^2). You might also want to see ?drop.terms and ?formula for automating the construction of all model combinations. Side note: R is not SAS (fortunately). Interaction is denoted ":", X*Y is shorthand for X+Y+X:Y. Your "X+Y+X*Y" is redundant. HTH On Wed, Mar 7, 2012 at 4:16 AM, Christofer Bogaso
<bogaso.christofer at gmail.com> wrote:
Dear all, I was working with a GLM model and wondering whether is it possible to have a model description with all possible main effects as well as all interactions. Currently I do it manually however this will become cumbersome if I have large number of variables. Means suppose I have 3 explanatory variables and want to feed automatically with all possible combinations like: glm(Response~1) glm(Response~X) glm(Response~Y) glm(Response~Z) glm(Response~X+Y) glm(Response~X+Z) glm(Response~Z+Y) glm(Response~X+Y+X*Y) glm(Response~X+Z+X*Y) .................................................... all combinations which are possible Thanks and regards,
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.