pretty_model_output: Fancy Table Output of Linear, Logistic, and Cox Models

Description Usage Arguments Details Value Examples

Description

pretty_model_output() takes a Linear, Logistic, and Cox model fit object and calculate estimates, odds ratios, or hazard ratios, respectively, with confidence intervals. P values are also produced. For categorical variables with 3+ levels overall Type 3 p values are calculated, in addition to p values comparing to the first level (reference).

Usage

1
2
3
4
pretty_model_output(fit, model_data, overall_p_test_stat = c("Wald",
  "LR"), title_name = NULL, conf_level = 0.95, est_digits = 3,
  p_digits = 4, output_type = NULL, sig_alpha = 0.05,
  background = "yellow", ...)

Arguments

fit

lm, glm, or coxph fit (currently only tested on logistic glm fit)

model_data

data.frame or tibble used to create model fits. Used for capturing variable labels, if they exist

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.

title_name

title to use (will be repeated in first column)

conf_level

the confidence level required (default is 0.95).

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 is not NULL)

background

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

...

other params to pass to pretty_pvalues (i.e. bold or italic) (Only used if output_type is not NULL)

Details

Model type is determined by fit class, and also family if glm class. If the class is glm and binomial or quasibinomial family, then the output is designed for a Logistic model (i.e. Odd Ratios), if the class is coxph the output is designed for a Cox model (i.e. Harzard Ratios), otherwise the output is designed for a linear model or other model where normal coefficient estimates are displayed.

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).

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
# Basic linear model example
set.seed(542542522)
ybin <- sample(0:1, 100, replace = TRUE)
y <- rexp(100,.1)
x1 <- rnorm(100)
x2 <- y + rnorm(100)
x3 <- factor(sample(letters[1:4],100,replace = TRUE))
my_data <- data.frame(y, ybin, x1, x2, x3)

# Linear Regression
my_fit <- lm(y ~ x1 + x2 + x3, data = my_data)
pretty_model_output(fit = my_fit, model_data = my_data)

# Logistic Regression
my_fit <- glm(ybin ~ x1 + x2 + x3, data = my_data, family = binomial(link = "logit"))
pretty_model_output(fit = my_fit, model_data = my_data)

# Coxph Regression
my_fit <- survival::coxph(survival::Surv(y, ybin) ~ x1 + x2 + x3, data = my_data)
my_pretty_model_output <- pretty_model_output(fit = my_fit, model_data = my_data)

# Printing of Fancy table in HTML
library(dplyr)
kableExtra::kable(my_pretty_model_output, 'html', caption = 'My Table') %>% 
   kableExtra::collapse_rows(c(1:2), row_group_label_position = 'stack')
  
# Real World Examples
data(Bladder_Cancer)
surv_obj <- survival::Surv(Bladder_Cancer$Survival_Months, Bladder_Cancer$Vital_Status == 'Dead')  
my_fit <- survival::coxph(surv_obj ~ Gender + Clinical_Stage_Grouped + PT0N0, data = Bladder_Cancer)
my_output <- pretty_model_output(fit = my_fit, model_data = Bladder_Cancer)
kableExtra::kable(my_output, 'html') %>% 
    kableExtra::collapse_rows(c(1:2), row_group_label_position = 'stack')
  

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