I have a lm in R in the form model <- lm( Z ~ A*B*C*D,data=mydata) I want to run the model and include all interactions expect the 4 way (A:B:C:D) is there an easy way of doing this? I then want to step down the model eliminating the non-significant terms I understand step() does this but how would I do it by hand? -- View this message in context: http://www.nabble.com/R-stepping-through-multiplie-interactions-tp21629339p21629339.html Sent from the R help mailing list archive at Nabble.com.
On 1/23/2009 12:44 PM, ppeetteerr wrote:> I have a lm in R in the form > model <- lm( Z ~ A*B*C*D,data=mydata) > I want to run the model and include all interactions expect the 4 way > (A:B:C:D) is there an easy way of doing this? I then want to step down the > model eliminating the non-significant terms I understand step() does this > but how would I do it by hand?For the first part, try this: lm(Z ~ (A + B + C + D)^3, data = mydata) -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894
Z ~ (A+B+C+D)^3 means give all main effects and interactions up to the 3 way interactions, but not above (change ^3 to ^2 to limit to 2 way interactions). You can do a semi manual stepwise procedure using the add1 and drop1 commands or the addterm and dropterm commands in the MASS package. But be aware that using a final model gained from stepwise procedures tends to give estimates of the slopes biased away from 0. Better options have been discussed quite a bit on this list (search the archives) and Frank Harrell's book "Regression Modeling Strategies" gives more information. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of ppeetteerr > Sent: Friday, January 23, 2009 10:45 AM > To: r-help at r-project.org > Subject: [R] R stepping through multiplie interactions > > > I have a lm in R in the form > model <- lm( Z ~ A*B*C*D,data=mydata) > I want to run the model and include all interactions expect the 4 way > (A:B:C:D) is there an easy way of doing this? I then want to step down > the > model eliminating the non-significant terms I understand step() does > this > but how would I do it by hand? > -- > View this message in context: http://www.nabble.com/R-stepping-through- > multiplie-interactions-tp21629339p21629339.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.