[R] update.formula drop interaction terms

Uwe Ligges ligges at statistik.tu-dortmund.de
Wed Oct 14 10:42:20 CEST 2009



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.




More information about the R-help mailing list