Experimental lifecycle The function combines terms from a regression model, and replaces the terms with a single row in the output table. The p-value is calculated using stats::anova().

combine_terms(x, formula_update, label = NULL, quiet = NULL, ...)

Arguments

x

a tbl_regression object

formula_update

formula update passed to the stats::update. This updated formula is used to construct a reduced model, and is subsequently passed to stats::anova() to calculate the p-value for the group of removed terms. See the stats::update help file for proper syntax. function's formula.= argument

label

Option string argument labeling the combined rows

quiet

Logical indicating whether to print messages in console. Default is FALSE

...

Additional arguments passed to stats::anova

Value

tbl_regression object

Example Output

Example 1

Example 2

Example 3

See also

Author

Daniel D. Sjoberg

Examples

# Example 1 ---------------------------------- # fit model with nonlinear terms for marker nlmod1 <- lm( age ~ marker + I(marker^2) + grade, trial[c("age", "marker", "grade")] %>% na.omit() # keep complete cases only! ) combine_terms_ex1 <- tbl_regression(nlmod1, label = grade ~ "Grade") %>% # collapse non-linear terms to a single row in output using anova combine_terms( formula_update = . ~ . - marker - I(marker^2), label = "Marker (non-linear terms)" )
#> Creating a reduced model with #> `reduced_model <- stats::update(x$model_obj, formula. = . ~ . - marker - I(marker^2))`
#> Calculating p-value comparing full and reduced models with #> `stats::anova(x$model_obj, reduced_model)`
# Example 2 ---------------------------------- # Example with Cubic Splines library(Hmisc, warn.conflicts = FALSE, quietly = TRUE) mod2 <- lm( age ~ rcspline.eval(marker, inclx = TRUE) + grade, trial[c("age", "marker", "grade")] %>% na.omit() # keep complete cases only! ) combine_terms_ex2 <- tbl_regression(mod2, label = grade ~ "Grade") %>% combine_terms( formula_update = . ~ . -rcspline.eval(marker, inclx = TRUE), label = "Marker (non-linear terms)" )
#> Creating a reduced model with #> `reduced_model <- stats::update(x$model_obj, formula. = . ~ . - rcspline.eval(marker, inclx = TRUE))`
#> Calculating p-value comparing full and reduced models with #> `stats::anova(x$model_obj, reduced_model)`
# Example 3 ---------------------------------- # Logistic Regression Example, LRT p-value combine_terms_ex3 <- glm( response ~ marker + I(marker^2) + grade, trial[c("response", "marker", "grade")] %>% na.omit(), # keep complete cases only! family = binomial ) %>% tbl_regression(label = grade ~ "Grade", exponentiate = TRUE) %>% # collapse non-linear terms to a single row in output using anova combine_terms( formula_update = . ~ . - marker - I(marker^2), label = "Marker (non-linear terms)", test = "LRT" )
#> Creating a reduced model with #> `reduced_model <- stats::update(x$model_obj, formula. = . ~ . - marker - I(marker^2))`
#> Calculating p-value comparing full and reduced models with #> `stats::anova(x$model_obj, reduced_model, test = "LRT")`