HNSKD
HNSKD

Reputation: 1644

bayestestR for Bayesian Logistic Regression

I would like to perform Bayesian Logistic Regression using the bayestestR and rstanarm in R. The output, I believe, is in the log(odds ratio). Do you know of a way in which I can convert everything, i.e. the centrality, uncertainty, existence and significance indices into odds ratio instead. I know tbl_summary function from gtsummary package has an argument, exponentiate = TRUE that returns everything in OR.

Code:

library(rstanarm)
library(bayestestR)

data <- iris %>%
  filter(Species != "setosa") %>%
  droplevels()

model <- stan_glm(Species ~ Sepal.Width, data = data, family = "binomial", refresh = 0)

describe_posterior(model)
# Summary of Posterior Distribution 
# 
# Parameter   | Median |          95% CI |     pd |          ROPE | % in ROPE |  Rhat |     ESS
# ---------------------------------------------------------------------------------------------
# (Intercept) |  -6.16 | [-10.46, -2.30] | 99.95% | [-0.18, 0.18] |        0% | 1.001 | 2842.00
# Sepal.Width |   2.15 | [  0.83,  3.64] | 99.92% | [-0.18, 0.18] |        0% | 1.001 | 2799.00

Upvotes: 1

Views: 387

Answers (1)

Dominique Makowski
Dominique Makowski

Reputation: 1673

I'd recommend using the parameters package which uses bayestestR internally but is more flexible:

library(rstanarm)
library(bayestestR)
library(dplyr)

data <- iris %>%
  filter(Species != "setosa") %>%
  droplevels()

model <- stan_glm(Species ~ Sepal.Width, data = data, family = "binomial", refresh = 0)


parameters::parameters(model, exponentiate = TRUE)
#> # Fixed effects
#> 
#> Parameter   |   Median |        89% CI |     pd | % in ROPE |  Rhat |     ESS |              Prior
#> --------------------------------------------------------------------------------------------------
#> (Intercept) | 2.20e-03 | [0.00,  0.06] | 99.90% |     0.02% | 1.000 | 2763.00 | Normal (0 +- 2.50)
#> Sepal.Width |     8.52 | [2.60, 25.63] | 99.90% |     0.12% | 1.000 | 2801.00 | Normal (0 +- 7.51)
#> 
#> Using highest density intervals as credible intervals.

Created on 2021-06-29 by the reprex package (v2.0.0)

Upvotes: 2

Related Questions