0

我想使用 R 中的bayestestRand执行贝叶斯逻辑回归rstanarm。我相信输出在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
4

1 回答 1

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 包(v2.0.0)于 2021-06-29 创建

于 2021-06-29T12:23:52.673 回答