gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 12:11:06 26 4
gpt4 key购买 nike

我正在拟合几个逻辑回归模型,并尝试使用包 texreg创建一个漂亮的表格来展示所有模型。

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

我知道我可以使用 override.coef , override.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

最佳答案

有一个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 个不再加星标。

关于r - 转换 texreg 输出中的系数和置信区间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34428271/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com