remove all terms with interaction factor in formula
Hi Folks, I'm trying to find a way to remove all terms in a formula that contain a particular interaction. For example, in the formula below, I'd like to remove all terms that contain the b:c interaction.
attributes(terms( ~ a*b*c*d))$term.labels
[1] "a" "b" "c" "d" "a:b" "a:c" [7] "b:c" "a:d" "b:d" "c:d" "a:b:c" "a:b:d" [13] "a:c:d" "b:c:d" "a:b:c:d" My eventual use is to fit models with the reduced formulas. For example:
my_df = data.frame( iv = runif(100), a=runif(100), b=runif(100),
c=runif(100), d=runif(100))
lm(iv ~ a*b*c*d, data=my_df)
I can remove particular terms with update(), but I don't see a way to remove all terms that contain a given combination of factors. Any help would be greatly appreciated. Thanks! Allie