0

所以我试图在我的 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.

如何包括优势比?

常规模型(正如我上面所说的 logit)显示对数赔率/赔率的对数是否正确?

4

1 回答 1

2

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

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

override.coef参数只是用您提供的向量替换系数。如果您需要它们,标准误差、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对象中,操作此对象,然后将其交给screenreg函数来执行此操作,如下所示:

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
于 2020-05-16T16:05:35.653 回答