用于贝叶斯逻辑回归的 bayestestR

bayestestR for Bayesian Logistic Regression

我想使用 R 中的 bayestestRrstanarm 执行贝叶斯逻辑回归。我相信输出在 log(odds ratio)。您知道我可以将所有内容(即中心性、不确定性、存在性和显着性指标)转换为 优势比 的方法吗?我知道 gtsummary 包中的 tbl_summary 函数有一个参数,exponentiate = TRUE 即 returns OR 中的所有内容。

代码:

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

我建议使用 parameters 包,它在内部使用 bayetestR 但更灵活:

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.

reprex package (v2.0.0)

于 2021-06-29 创建