【问题标题】:Generalized Linear Model output through texreg通过 texreg 输出的广义线性模型
【发布时间】:2015-10-06 05:22:29
【问题描述】:

我可以使用texreg 获得漂亮的 glm 输出,用于knitr。有时我们需要使用反向链接将 glm 的输出转换回响应。我想知道如何使用texreg 获得反向链接输出。像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 函数并提供链接尺度系数标准误差置信区间 /强>。但有时我们还需要响应量表上的系数标准误差置信区间texreglink scale上直接提供系数标准误置信区间,不知是否可以直接获取响应量表上的系数标准误差置信区间

我找到了一种使用stargazer 的方法,但标准错误和置信区间仍然不是正确的。寻找解决方案。

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

【问题讨论】:

  • “反向链接输出”究竟是什么意思。 glm.D93 是一个拟合模型对象,因此您不能只使用它的 exp()。是否要修改所有系数值?期望的输出是什么?
  • glm 使用一些link 函数并提供系数标准误差置信区间 b>链接规模。但有时我们还需要响应量表上的系数标准误差置信区间texreglink scale上直接提供系数标准误置信区间,不知是否可以直接获取响应量表上的系数标准误差置信区间
  • 这里是solution

标签: r knitr glm stargazer texreg


【解决方案1】:

要么使用覆盖参数来完成此操作,要么操作中间 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)

或者直接从模型对象或其摘要中提取值(如果您不想使用 texreg 的提取函数)并将取幂后的值交给覆盖参数。

任何这些解决方案都会产生以下输出(与 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

【讨论】:

  • 我不确定您是否应该对此处的 p 值取幂。对于优势比量表和对数优势量表,检验的 p 值不应该相同吗?
  • 完全正确。抱歉疏忽。我已经编辑了我的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-06
  • 2015-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-21
  • 1970-01-01
相关资源
最近更新 更多