用于贝叶斯逻辑回归的 bayestestR

时间:2021-06-29 09:47:52

标签: r logistic-regression bayesian rstanarm

我想使用 R 中的 bayestestRrstanarm 执行贝叶斯逻辑回归。我相信输出是 log(odds ratio)。你知道我可以用什么方法将所有东西,即中心性、不确定性、存在性和重要性指数转换成优势比。我知道 tbl_summary 包中的 gtsummary 函数有一个参数 exponentiate = TRUE 返回 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

1 个答案:

答案 0 :(得分:1)

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

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 年 6 月 29 日创建