转换texreg输出中的系数和置信区间

时间:2015-12-23 03:40:19

标签: r texreg

我正在拟合几个逻辑回归模型,并尝试使用包texreg创建一个很好看的表来呈现所有模型。

据我所知,texreg::screenreg只能报告系数(beta)和相应的CI,但对于逻辑回归,但更常见的是报告系数的指数(优势比)。

我知道我可以使用override.coefoverride.ci.lowoverride.ci.up来获取我想要的内容,但输出表是不可取的,如果CI覆盖0,它会给出一个星号改造后应为1。

有没有更好更简单的方法来转换系数和CI?另外,我是否可以覆盖星号,我想提供星号来表示p值(*** p < 0.001, ** p < 0.01, * p < 0.05)的大小?谢谢!

这是我试过的

> set.seed(123)
> x1 <- rnorm(1000)
> x2 <- rnorm(1000)
> y <- runif(1000) < (1 / (1 + exp(-(0.3 + 0.5*x1))))
> mod1 <- glm(y~x1, binomial())
> mod2 <- glm(y~x2, binomial())
> mod3 <- glm(y~x1+x2, binomial())
> 
> tex1 <- extract(mod1)
> tex2 <- extract(mod2)
> tex3 <- extract(mod3)
> 
> screenreg(list(tex1, tex2, tex3), ci.force=T)

==========================================================
                Model 1       Model 2        Model 3      
----------------------------------------------------------
(Intercept)        0.30 *        0.28 *         0.30 *    
                [0.17; 0.43]  [ 0.15; 0.41]  [ 0.17; 0.43]
x1                 0.60 *                       0.60 *    
                [0.45; 0.74]                 [ 0.45; 0.74]
x2                               0.05           0.01      
                              [-0.07; 0.18]  [-0.12; 0.14]
----------------------------------------------------------
AIC             1294.48       1369.92        1296.47      
BIC             1304.30       1379.74        1311.19      
Log Likelihood  -645.24       -682.96        -645.23      
Deviance        1290.48       1365.92        1290.47      
Num. obs.       1000          1000           1000         
==========================================================
* 0 outside the confidence interval

重写后,

> tex1@coef <- exp(tex1@coef)
> tex2@coef <- exp(tex2@coef)
> tex3@coef <- exp(tex3@coef)
> 
> ci1 <- confint(mod1)
Waiting for profiling to be done...
> ci2 <- confint(mod2)
Waiting for profiling to be done...
> ci3 <- confint(mod3)
Waiting for profiling to be done...
> 
> tex1@ci.low <- exp(ci1[, 1])
> tex2@ci.low <- exp(ci2[, 1])
> tex3@ci.low <- exp(ci3[, 1])
> tex1@ci.up <- exp(ci1[, 2])
> tex2@ci.up <- exp(ci2[, 2])
> tex3@ci.up <- exp(ci3[, 2])
> 
> screenreg(list(tex1, tex2, tex3))

========================================================
            Model 1       Model 2       Model 3     
--------------------------------------------------------
(Intercept)        1.34 *        1.32 *        1.34 *   
                [1.18; 1.53]  [1.17; 1.50]  [1.18; 1.53]
x1                 1.81 *                      1.81 *   
                [1.58; 2.10]                [1.58; 2.10]
x2                               1.05 *        1.01 *   
                              [0.93; 1.19]  [0.89; 1.15]
--------------------------------------------------------
AIC             1294.48       1369.92       1296.47     
BIC             1304.30       1379.74       1311.19     
Log Likelihood  -645.24       -682.96       -645.23     
Deviance        1290.48       1365.92       1290.47     
Num. obs.       1000          1000          1000        
========================================================
* 0 outside the confidence interval

1 个答案:

答案 0 :(得分:3)

在这种情况下,有一个ci.test参数可以设置为“空值”,适用于转换后的参数。它应该设置为1.0而不是0.所以这成功了:

  screenreg(list(tex1, tex2, tex3), ci.test=1)

#------output--------
========================================================
                Model 1       Model 2       Model 3     
--------------------------------------------------------
(Intercept)        1.34 *        1.32 *        1.34 *   
                [1.18; 1.53]  [1.17; 1.50]  [1.18; 1.53]
x1                 1.81 *                      1.81 *   
                [1.58; 2.10]                [1.58; 2.10]
x2                               1.05          1.01     
                              [0.93; 1.19]  [0.89; 1.15]
--------------------------------------------------------
AIC             1294.48       1369.92       1296.47     
BIC             1304.30       1379.74       1311.19     
Log Likelihood  -645.24       -682.96       -645.23     
Deviance        1290.48       1365.92       1290.47     
Num. obs.       1000          1000          1000        
========================================================
* 1 outside the confidence interval

请注意,6个参数估算中有2个不再加星标。