Models specified terms in model data against an existing model and returns a clean, human readable table of summarizing the effects and statistics for the newly generated model. This functions greatly simplifies fitting a large number of variables against a set of time-to-event data.
Usage
# S3 method for coxph
build_model(
.object,
...,
.mv = FALSE,
.test = c("LRT", "Wald"),
.col.test = FALSE,
.level = 0.95,
.stat.pct.sign = TRUE,
.digits = 1,
.p.digits = 4
)
Arguments
- .object
An object of class
coxph
.- ...
One or more unquoted expressions separated by commas representing columns in the model data.frame. May be specified using
tidyselect helpers
.- .mv
A logical. Fit all terms into a single multivariable model. If left FALSE, all terms are fit in their own univariate models.
- .test
A character. The name of a
stats::drop1
test to use with the model.- .col.test
A logical. Append a columns for the test and accompanying statistic used to derive the p-value.
- .level
A double. The confidence level required.
- .stat.pct.sign
A logical. Paste a percent symbol after all reported frequencies.
- .digits
An integer. The number of digits to round numbers to.
- .p.digits
An integer. The number of p-value digits to report. Note that the p-value still rounded to the number of digits specified in
.digits
.
Value
An object of class data.frame summarizing the provided object. If the
tibble
package has been installed, a tibble will be returned.
Examples
library(survival)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
data_lung <- lung |>
mutate_at(vars(inst, status, sex), as.factor) |>
mutate(status = case_when(status == 1 ~ 0, status == 2 ~ 1))
fit <- coxph(Surv(time, status) ~ 1, data = data_lung)
# Create a univariate model for each variable
fit |> build_model(sex, age)
#> Error in eval(.object$call$data): object 'data_lung' not found