Dear R users, How do I drop multiplication terms from a formula using update? e.g. forml=as.formula("Surv(time, status) ~ x1+x2+A*x3+A*x4+B*x5+strata(sex)") #I would like to drop all instances of variable A (the main effect and its interactions). The following: updated.forml=update(forml, ~ . -A) #gives me this: #Surv(time, status) ~ x1 + x2 + x3 + x4 + B + x5 + strata(sex) + A:x3 + A:x4 + B:x5 #but I want this: #updated.forml=as.formula("Surv(time, status) ~ x1+x2+x3+x4+B*x5+strata(sex)") Any ideas? Thanks in advance Eleni Rapsomaniki Research Associate Strangeways Research Laboratory Department of Public Health and Primary Care University of Cambridge ?
Eleni Rapsomaniki-2 wrote:> > How do I drop multiplication terms from a formula using update? > e.g. > forml=as.formula("Surv(time, status) ~ x1+x2+A*x3+A*x4+B*x5+strata(sex)") > >The easiest way is to write the formula again without the A's. Dieter -- View this message in context: http://www.nabble.com/update.formula-drop-interaction-terms-tp25873249p25886245.html Sent from the R help mailing list archive at Nabble.com.
Eleni Rapsomaniki wrote:> Dear R users, > > How do I drop multiplication terms from a formula using update? > e.g. > forml=as.formula("Surv(time, status) ~ x1+x2+A*x3+A*x4+B*x5+strata(sex)") > > #I would like to drop all instances of variable A (the main effect and its interactions). The following: > updated.forml=update(forml, ~ . -A)to drop all terms with A: update(lmo, . ~ . - A:.) Uwe Ligges> > #gives me this: > #Surv(time, status) ~ x1 + x2 + x3 + x4 + B + x5 + strata(sex) + A:x3 + A:x4 + B:x5> #but I want this: > #updated.forml=as.formula("Surv(time, status) ~ x1+x2+x3+x4+B*x5+strata(sex)") > > Any ideas? > Thanks in advance > > Eleni Rapsomaniki > > Research Associate > Strangeways Research Laboratory > Department of Public Health and Primary Care > University of Cambridge > > > ______________________________________________ > 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.