简体   繁体   English

R 中比例或比率响应变量 (0,1) 的贝叶斯回归

[英]Bayesian regression for proportions or rates response variable (0,1) in R

I have my response variable as proportions with values between 0 and 1, 0 and 1 not included.我将我的响应变量作为比例值在 0 和 1 之间,不包括 0 和 1。 I would like to perform Bayesian logit regression.我想执行贝叶斯 logit 回归。 I am using the package arm in R and I followed the example inBayesian Generalized Linear Models in R as published by Jon Starkweather, PhD. I am using the package arm in R and I followed the example inBayesian Generalized Linear Models in R as published by Jon Starkweather, PhD. The difficulty or the confusion I have in mind is that with the frequentist glm approach, I could do beta regression (and specify logit link).我想到的困难或困惑是,使用常客 glm 方法,我可以进行 beta 回归(并指定 logit 链接)。 But when it comes to the Bayesian glm, I am unsure how to specify the link function for this proportions data, especially using the routine provided in the arm package and as used in the above cited paper regarding the Bayesglm function. But when it comes to the Bayesian glm, I am unsure how to specify the link function for this proportions data, especially using the routine provided in the arm package and as used in the above cited paper regarding the Bayesglm function. The adapted code I am using is as below:我正在使用的改编代码如下:

#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

So my question is, how do I specify a logit link in Bayesglm function?所以我的问题是,如何在Bayesglm function 中指定 logit 链接? If the response variable were binary, I could specify family=binomial(link=logit) .如果响应变量是二进制的,我可以指定family=binomial(link=logit)

Any assistance is highly appreciated.非常感谢任何帮助。

The frequentist / bayesian terminology is a bit too confusing.常客/贝叶斯术语有点太混乱了。 Basically the question is how to run a binomial regression with either glm (from stats ) or bayesglm (from arm )基本上问题是如何使用glm (来自stats )或bayesglm (来自arm )运行二项式回归

Suppose our dataset is this, different levels of successes associated with different x, and n = 10:假设我们的数据集是这样的,不同的成功级别与不同的 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

We calculate the proportion:我们计算比例:

df$p = df$success / df$n

And you regress by using weights:你使用权重回归:

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

Same for bayesglm:与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

Also check out the accepted answer for this post另请查看此帖子的已接受答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM