pretty_bayesian_output: Fancy Table Output Bayesian Linear and Logistic regression...

Description Usage Arguments Details Value Examples

View source: R/pretty_bayesian_output.R

Description

Fancy Table Output Bayesian Linear and Logistic regression pretty_bayesian_output takes a stanreg fit object ( family = binomial or guassian), and calculate estimates of regression coefficients or odds ratios.

Usage

1
pretty_bayesian_output(fit, model_data)

Arguments

fit

stanreg

model_data

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

Details

Model type is determined by fit class, and also family if. If family is binomial, then the output is designed for a Logistic model (i.e. Odd Ratios), otherwise the output is designed for a linear model.

Value

A tibble with: Variable, Level, Mean Est/OR , mcse (mcse monte carlo standard error), sd (standard deviation), 2.5 (percentile of posterior), 50 (percentile of posterior), 97.5 (percentile of posterior), n_eff (effective number of simulation draws), Rhat ( is essentially the ratio of between-chain variance to within-chain variance analogous to ANOVA.).

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
# 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)
library(rstanarm)
lm_fit <- stan_glm(y ~ x1+ x2 + x3, data = my_data )
pretty_bayesian_output(fit = lm_fit, model_data = my_data)

library(dplyr)
# Logistic Regression
my_fit <- stan_glm(ybin ~ x1 + x2 + x3, data = my_data, family = binomial)
my_pretty_model_output <-pretty_bayesian_output(fit = my_fit, model_data = my_data)

# Printing of Fancy table in HTML

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 + 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')
  

z2thet/MoffittFunctions documentation built on July 17, 2021, 9:51 a.m.