简体   繁体   English

通过texreg的广义线性模型输出

[英]Generalized Linear Model output through texreg

I can use texreg to get beautiful output of glm to be used for knitr . 我可以用texreg获得用于GLM的美丽输出knitr Sometimes we need to convert the output of glm back to response using inverse link. 有时我们需要使用反向链接将glm的输出转换回响应。 I wonder how to get inverse link output with texreg . 我想知道如何使用texreg获得反向链接输出。 Something like texreg(exp(glm.D93)) . texreg(exp(glm.D93))

counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
d.AD <- data.frame(treatment, outcome, counts)
glm.D93 <- glm(counts ~ outcome + treatment, family = poisson())

library(texreg)
texreg(glm.D93)

which produces 产生

\begin{table}
\begin{center}
\begin{tabular}{l c }
\hline
               & Model 1 \\
\hline
(Intercept)    & $3.04^{***}$ \\
               & $(0.17)$     \\
outcome2       & $-0.45^{*}$  \\
               & $(0.20)$     \\
outcome3       & $-0.29$      \\
               & $(0.19)$     \\
treatment2     & $0.00$       \\
               & $(0.20)$     \\
treatment3     & $0.00$       \\
               & $(0.20)$     \\
\hline
AIC            & 56.76        \\
BIC            & 57.75        \\
Log Likelihood & -23.38       \\
Deviance       & 5.13         \\
Num. obs.      & 9            \\
\hline
\multicolumn{2}{l}{\scriptsize{$^{***}p<0.001$, $^{**}p<0.01$, $^*p<0.05$}}
\end{tabular}
\caption{Statistical models}
\label{table:coefficients}
\end{center}
\end{table}

But texreg(exp(glm.D93)) say 但是texreg(exp(glm.D93))

Error in exp(glm.D93) : non-numeric argument to mathematical function

Edited 编辑

glm uses some link function and provides the coefficients , standard errors and confidence intervals on link scale . glm使用一些link函数,并提供链接范围 系数标准误差置信区间 But sometimes we also need coefficients , standard errors and confidence intervals on the response scale . 但是有时我们还需要响应量表上的系数标准误差置信区间 texreg directly provides coefficients , standard errors and confidence intervals on link scale , I wonder if it is possible to get coefficients , standard errors and confidence intervals on response scale directly. texreg直接在链接规模上提供系数标准误差置信区间 ,我想知道是否有可能直接在响应规模上获得系数标准误差置信区间

I found a way to do this with stargazer but still the standard errors and confidence intervals are not the correct one. 我找到了一种使用stargazer执行此操作的方法,但标准错误和置信区间仍然不是正确的方法。 Looking the solution to this one. 寻找解决方案。

library(stargazer)

stargazer(glm.D93, coef=list(exp(glm.D93$coefficients)), type="text")

=============================================
                      Dependent variable:    
                  ---------------------------
                            counts           
---------------------------------------------
outcome2                   0.635***          
                            (0.202)          

outcome3                   0.746***          
                            (0.193)          

treatment2                 1.000***          
                            (0.200)          

treatment3                 1.000***          
                            (0.200)          

Constant                   21.000***         
                            (0.171)          

---------------------------------------------
Observations                   9             
Log Likelihood              -23.381          
Akaike Inf. Crit.           56.761           
=============================================
Note:             *p<0.1; **p<0.05; ***p<0.01

Either use override arguments to accomplish this or manipulate an intermediate texreg object: 使用覆盖参数来完成此操作,或操纵中间texreg对象:

# solution 1
tr <- extract(glm.D93)
texreg(glm.D93, override.coef = exp(tr@coef), override.se = exp(tr@se))

# solution 2
tr <- extract(glm.D93)
tr@coef <- exp(tr@coef)
tr@se <- exp(tr@se)
texreg(tr)

Or extract the values directly from the model object or its summary (if you don't want to use texreg's extract function) and hand over the exponentiated values to the override arguments. 或者直接从模型对象或其摘要中提取值(如果您不想使用texreg的extract函数),然后将指数值移交给重写参数。

Any of these solutions produces the following output (in conjunction with screenreg): 这些解决方案中的任何一个都会产生以下输出(与screenreg结合使用):

==========================
                Model 1   
--------------------------
(Intercept)      21.00 ***
                 (1.19)   
outcome2          0.63 *  
                 (1.22)   
outcome3          0.75    
                 (1.21)   
treatment2        1.00    
                 (1.22)   
treatment3        1.00    
                 (1.22)   
--------------------------
AIC              56.76    
BIC              57.75    
Log Likelihood  -23.38    
Deviance          5.13    
Num. obs.         9       
==========================
*** p < 0.001, ** p < 0.01, * p < 0.05

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

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