2

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)

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

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. 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.

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
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
  • What precisely do you mean by "inverse link output." The `glm.D93` is a fitted model object so you can't just take the `exp()` of it. Did you want to modify all the coefficient values? What's the desired output? – MrFlick Jul 16 '15 at 17:08
  • `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. – MYaseen208 Jul 16 '15 at 17:26
  • Here is the [solution](http://stackoverflow.com/a/19701562/707145). – MYaseen208 Jul 16 '15 at 19:10

1 Answers1

4

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)

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.

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
Philip Leifeld
  • 2,253
  • 15
  • 24
  • I am not sure you should exponentiate the p-values here. Shouldn't the p-value for the test be the same for odds ratio scale and log-odds scale? – Seth Aug 01 '16 at 17:52
  • That's absolutely right. Sorry for the oversight. I have edited my answer. – Philip Leifeld Aug 01 '16 at 21:48