通过texreg的广义线性模型输出 [英] Generalized Linear Model output through texreg
问题描述
我可以使用texreg
获得用于knitr
的glm的漂亮输出.有时我们需要使用反向链接将glm的输出转换回响应.我想知道如何使用texreg
获得反向链接输出. texreg(exp(glm.D93))
之类的东西.
I can use texreg
to get beautiful output of glm to be used for knitr
. Sometimes we need to convert the output of glm back to response using inverse link. I wonder how to get inverse link output with texreg
. Something like 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)
产生
\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}
但是texreg(exp(glm.D93))
说
Error in exp(glm.D93) : non-numeric argument to mathematical function
已编辑
glm
使用某些link
功能,并以链接等级提供系数,标准误差和置信区间 .但是有时我们还需要响应量的系数,标准误差和置信区间. texreg
直接以链接等级提供系数,标准误差和置信区间,我想知道是否有可能直接以响应量表获得系数,标准误差和置信区间.
glm
uses some link
function and provides the coefficients, standard errors and confidence intervals on link scale. 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.
我找到了一种使用stargazer
进行此操作的方法,但是标准错误和置信区间仍然不是正确的方法.寻找解决方案.
I found a way to do this with stargazer
but still the standard errors and confidence intervals are not the correct one. 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
推荐答案
使用覆盖参数来完成此操作或操纵中间texreg对象:
Either use override arguments to accomplish this or manipulate an intermediate texreg object:
# 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)
或者直接从模型对象或其摘要中提取值(如果您不想使用texreg的extract函数),然后将指数值移交给重写参数.
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.
这些解决方案中的任何一个都会产生以下输出(与screenreg结合使用):
Any of these solutions produces the following output (in conjunction with 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
这篇关于通过texreg的广义线性模型输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!