Add or remove terms to a lmer formula string
Arguments
- x
Either mer formula object, string containing formula, lmer object. If latter is the case, the updated object will be returned instead of a new formula.
- fixed
List of character strings containing variable names or terms to include in the formula as fixed terms.
- random
List of character strings containing variable names or terms to include in the formula as random terms.
- drop
List of character strings containing variable names or fixed terms to exclude from the formula.
- drop.random
List of character strings containing variable names or random terms to exclude from the formula.
- ...
Extra arguments passed to `update`. Works only if `x` is a lmer object.
Examples
f1 <- "a ~ b + c + (1| group)"
add_term(f1, , "Conservation")
#> Loading required package: stringr
#> [1] "a ~ b + c + (1+ Conservation | group) "
add_term(f1, "Conservation*GDP")
#> [1] "a ~ b + c + (1 | group) + Conservation*GDP"
add_term(f1, "Conservation*GDP", "Conservation")
#> [1] "a ~ b + c + (1+ Conservation | group) + Conservation*GDP"
add_term(f1, drop="female", drop.random = "g.agea")
#> drop.random wasn't found in the formula
#> [1] "a ~ b + c + ( 1 | group )"