【问题标题】:Bayesian regression for proportions or rates response variable (0,1) in RR中比例或比率响应变量(0,1)的贝叶斯回归
【发布时间】:2021-02-02 00:21:20
【问题描述】:

我的响应变量为比例,其值介于 0 和 1 之间,不包括 0 和 1。我想执行贝叶斯 logit 回归。我在 R 中使用包 arm,并按照 Jon Starkweather 博士发布的 Bayesian Generalized Linear Models in R 中的示例进行操作。我想到的困难或困惑是,使用常客 glm 方法,我可以进行 beta 回归(并指定 logit 链接)。但是当谈到贝叶斯 glm 时,我不确定如何为这个比例数据指定链接函数,尤其是使用 arm 包中提供的例程以及上面引用的关于 Bayesglm 函数的论文中使用的例程。 我正在使用的改编代码如下:

#install.packages("arm")
library(arm)

Model<-bayesglm(y ~x1 + I(x1^2) + x2 + x3 + x4 + x5 + x6 
              + x7 + x8 + x9,family = gaussian, data=mydata,prior.mean=0, prior.scale=Inf, prior.df=Inf)
summary(Model)

Call:
bayesglm(formula = y ~x1 + I(x1^2) + x2 + x3 + x4 + x5 + x6 
              + x7 + x8 + x9, family = gaussian, data = panel1_neg, prior.mean = 0, 
             prior.scale = Inf, prior.df = Inf)

Deviance Residuals: 
      Min         1Q     Median         3Q        Max  
-0.024267  -0.006407  -0.001379   0.006257   0.042012  

Coefficients:
               Estimate Std. Error t value Pr(>|t|)    
(Intercept)    0.046806   0.011057   4.233 5.16e-05 ***
       x1      0.327205   0.084408   3.876 0.000191 ***
   I(x1^2)     -1.351503   0.395559  -3.417 0.000921 ***
      x2      -0.333285   0.056133  -5.937 4.30e-08 ***
      x3       0.074882   0.029916   2.503 0.013949 *  
      x4       0.012951   0.003231   4.009 0.000119 ***
      x5      -0.053934   0.059021  -0.914 0.363042    
      x6      -0.082908   0.051511  -1.610 0.110690    
      x7      -0.019248   0.068604  -0.281 0.779623    
      x8      -0.012700   0.002549  -4.981 2.68e-06 ***
      x9       0.006289   0.002575   2.442 0.016382 *  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for gaussian family taken to be 0.0001288981)

    Null deviance: 0.032699  on 109  degrees of freedom
Residual deviance: 0.012761  on  99  degrees of freedom
AIC: -660.64

Number of Fisher Scoring iterations: 7

所以我的问题是,如何在 Bayesglm 函数中指定一个 logit 链接?如果响应变量是二进制的,我可以指定family=binomial(link=logit)

非常感谢任何帮助。

【问题讨论】:

标签: r glm bayesian bayesglm


【解决方案1】:

常客/贝叶斯术语有点太混乱了。基本上问题是如何使用glm(来自stats)或bayesglm(来自arm)运行二项式回归

假设我们的数据集是这样的,不同的成功级别与不同的 x 相关联,并且 n = 10:

set.seed(111)
df = data.frame(success = c(rbinom(20,10,0.6),rbinom(20,10,0.6)),
x = rep(0:1,each=20))

df$n = 10

我们计算比例:

df$p = df$success / df$n

然后你使用权重回归:

glm(p ~ x,weights=n,family=binomial(link=logit),data=df)

Call:  glm(formula = p ~ x, family = binomial, data = df, weights = n)

Coefficients:
(Intercept)            x  
     0.6411      -0.2356  

Degrees of Freedom: 39 Total (i.e. Null);  38 Residual
Null Deviance:      28.33 
Residual Deviance: 27.04    AIC: 137.5

bayesglm 也一样:

bayesglm(p ~ x,weights=n,family=binomial(link=logit),data=df)

Call:  bayesglm(formula = p ~ x, family = binomial(link = logit), data = df, 
    weights = n)

Coefficients:
(Intercept)            x  
     0.6394      -0.2325  

Degrees of Freedom: 39 Total (i.e. Null);  38 Residual
Null Deviance:      28.33 
Residual Deviance: 27.04    AIC: 71.04

还可以查看accepted answer for this post

【讨论】:

  • 嗨@StupidWolf,感谢您的建议。但我不确定这是否能解决我的问题。我没有为二项式分布因变量运行贝叶斯 logit 模型。我的因变量是rates 变量,例如计算为a/b ,其中ab 上的数据不可用。所以我不确定在这种情况下什么会构成weights,以及我将如何使用它。我的理解是这样的利率变量是贝塔分布的。简而言之,我正在寻找一种方法来指定家庭为 beta,linklogit
猜你喜欢
  • 2012-10-28
  • 1970-01-01
  • 2016-08-21
  • 2013-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多