run_pretty_model_output: Wrapper for Pretty Model Output

Description Usage Arguments Details Value Examples

Description

Wrapper for pretty_model_output(). This function takes a dataset, along with variables names for x (could be multiple), y, and possibly event status, for model fit.

Usage

1
2
3
4
5
run_pretty_model_output(x_in, model_data, y_in, event_in = NULL,
  event_level = NULL, title_name = NULL, fail_if_warning = TRUE,
  conf_level = 0.95, overall_p_test_stat = c("Wald", "LR"),
  est_digits = 3, p_digits = 4, output_type = NULL,
  sig_alpha = 0.05, background = "yellow", verbose = FALSE, ...)

Arguments

x_in

name of x variables in model (can be vector of x names)

model_data

data.frame or tibble that contains x_in, time_in, and event_in variables

y_in

name of outcome measure for logistic and linear model, or name of time component in cox model

event_in

name of event status variable. Shouled be left NULL for logistic and linear models. If event_level = NULL then this must be the name of a FALSE/TRUE or 0/1 variable, where FALSE or 0 are considered the censored level, respectively.

event_level

outcome variable event level for logistic model, and event status level for cox model.

title_name

title to use (will be repeated in first column)

fail_if_warning

Should program stop and give useful message if there is a warning message when running model (Default is TRUE)

conf_level

the confidence level required (default is 0.95).

overall_p_test_stat

"Wald" (default) or "LR"; the test.statistic to pass through to the test.statistic param in car::Anova. Ignored for lm fits.

est_digits

number of digits to round OR or HR to (default is 3)

p_digits

number of digits to round p values (default is 4)

output_type

output type, either NULL (default), "latex", or "html" (making special charaters latex friendly)

sig_alpha

the defined significance level for highlighting. Default = 0.05 (Only used if output_type not NULL)

background

background color of significant values, or no highlighting if NULL. Default is "yellow" (Only used if output_type not NULL)

verbose

a logical variable indicating if warnings and messages should be displayed. Default FALSE.

...

other params to pass to pretty_pvalues (i.e. bold or italic)

Details

x_in can be single variable name, or vector of variables to include in the model. All variables must be present in the model_data dataset.

fail_if_warning variable default to TRUE because most warnings should be addressed, such as the "Loglik converged before variable XX; beta may be infinite" warning.

Value

A tibble with: Name (if provided), Variable, Level, Est/OR/HR (95% CI), P Value (for categorical variables comparing to reference), Overall P Value (for categorical variables with 3+ levels), n/n (event).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Basic linear model example
set.seed(542542522)
ybin <- sample(0:1, 100, replace = TRUE)
ybin2 <- sample(c('Male','Female'), 100, replace = TRUE)
ybin3 <- sample(c('Dead','Alive'), 100, replace = TRUE)
y <- rexp(100,.1)
x1 <- factor(sample(LETTERS[1:2],100,replace = TRUE))
x2 <- factor(sample(letters[1:4],100,replace = TRUE))
my_data <- data.frame(y, ybin, ybin2, ybin3, x1, x2)
Hmisc::label(my_data$x1) <- "X1 Variable"

 # Single runs 
run_pretty_model_output(x_in = 'x1', model_data = my_data, y_in = 'y', event_in = 'ybin')
run_pretty_model_output(x_in = 'x1', model_data = my_data, y_in = 'y', 
     event_in = 'ybin3', event_level = 'Dead')
run_pretty_model_output(x_in = c('x1','x2'), model_data = my_data, y_in = 'y', event_in = 'ybin')
run_pretty_model_output(x_in = 'x2', model_data = my_data, y_in = 'ybin', event_in = NULL, verbose = TRUE)
run_pretty_model_output(x_in = 'x2', model_data = my_data, y_in = 'y', event_in = NULL)

# Multiple runs for different variables
library(dplyr) 
vars_to_run = c('x1', 'x2')
cox_models <- purrr::map_dfr(vars_to_run, run_pretty_model_output, model_data = my_data, 
     y_in = 'y', event_in = 'ybin')

kableExtra::kable(cox_models, 'html', caption = 'My Table') %>% 
  kableExtra::collapse_rows(c(1:2), row_group_label_position = 'stack', headers_to_remove = 1:2)

# Real World Example
data(Bladder_Cancer)
vars_to_run = c('Gender', 'Clinical_Stage_Grouped', 'PT0N0', 'Any_Downstaging')

univariate_output <- purrr::map_dfr(vars_to_run, run_pretty_model_output, model_data = Bladder_Cancer, 
      y_in = 'Survival_Months', event_in = 'Vital_Status', event_level = 'Dead')
kableExtra::kable(univariate_output, 'html') %>% 
      kableExtra::collapse_rows(c(1:2), row_group_label_position = 'stack', headers_to_remove = 1:2)

multivariable_output <- run_pretty_model_output(vars_to_run, model_data = Bladder_Cancer, 
      y_in = 'Survival_Months', event_in = 'Vital_Status', event_level = 'Dead')
kableExtra::kable(multivariable_output, 'html') %>% 
      kableExtra::collapse_rows(c(1:2), row_group_label_position = 'stack', headers_to_remove = 1:2)

wfulp/MoffittFunctions documentation built on May 24, 2019, 11:44 p.m.