繁体   English   中英

如何在 texreg 表中包含优势比?

[英]How to include odds ratio in texreg table?

所以我试图在我的 texreg 表中显示优势比:

library(texreg)

df <- mtcars

logit <- glm(
  formula = am ~ cyl,
  data = df,
  family = binomial(link = "logit")
)

odds_ratio <- exp(coef(logit))

screenreg(logit, odds_ratio)

不幸的是,这会产生以下错误:

Error in screenreg(logit, odds_ratio) : 
  The 'file' argument must be a character string.

如何包括优势比?

常规的 model(我在上面称之为 logit)显示对数赔率/赔率的对数是否正确?

要用赔率比替换对数赔率,您可以这样做:

library("texreg")
logit <- glm(formula = am ~ cyl,
             data = mtcars,
             family = binomial(link = "logit"))
screenreg(logit, override.coef = exp(coef(logit)))

override.coef参数只是用您提供的向量替换系数。 有类似的 arguments 用于标准误差、p 值等,以备不时之需。

结果:

=========================
                Model 1  
-------------------------
(Intercept)      43.71 * 
                 (1.55)  
cyl               0.50 **
                 (0.25)  
-------------------------
AIC              37.95   
BIC              40.88   
Log Likelihood  -16.98   
Deviance         33.95   
Num. obs.        32      
=========================
*** p < 0.001; ** p < 0.01; * p < 0.05

请注意,上面的示例中没有转换标准错误。 首先转换它们是没有意义的,因为它们需要是不对称的。 所以你不妨把它们从桌子上扔掉。 为此,您可以将结果保存到中间texreg object,操作此 object,然后将其交给screenreg function,如下所示:

tr <- extract(logit)
tr@coef <- exp(tr@coef)
tr@se <- numeric()
screenreg(tr)

结果:

=========================
                Model 1  
-------------------------
(Intercept)      43.71 * 
cyl               0.50 **
-------------------------
AIC              37.95   
BIC              40.88   
Log Likelihood  -16.98   
Deviance         33.95   
Num. obs.        32      
=========================
*** p < 0.001; ** p < 0.01; * p < 0.05

暂无
暂无

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

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