R markdown “texreg”

2019-08-07 05:02发布

I would like to get latex table of regression results by using following comments;

Analysis1 <- glm(y~x, data=data1, family=quasibinomial(link="logit"))    
summary(Analysis1)
texreg(list(Analysis1),dcolumn = TRUE, booktabs = TRUE,
       use.packages = TRUE, label = "tab:1", 
       caption = "Regression Estimation Results",float.pos = "hb")

However, this "texreg" commands gives raw output instead of clean table;

\begin{table}[ht]
\centering
\begin{tabular}{rrrrr}
  \hline
 & Estimate & Std. Error & t value & Pr($>$$|$t$|$) \\ 
  \hline
(Intercept) & 0.7686 & 0.0125 & 61.37 & 0.0000 \\ 
  x & -0.0166 & 0.0069 & -2.41 & 0.0170 \\ 
   \hline
\end{tabular}
\end{table}

Could you please help me how I can get clean regression results table by using texreg command in R?

标签: r texreg
1条回答
姐就是有狂的资本
2楼-- · 2019-08-07 05:44

You did not provide a minimal self-contained example. However, if I use the example provided on the glm help page, it does seem to work. See the following result.

library("texreg")  # tested with version 1.33.2

counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
Analysis1 <- glm(counts ~ outcome + treatment, family = poisson())

texreg(Analysis1, dcolumn = TRUE, booktabs = TRUE,
    use.packages = TRUE, label = "tab:1", 
    caption = "Regression Estimation Results", float.pos = "hb")

This gives the following output, which is, I believe, correct.

\usepackage{booktabs}
\usepackage{dcolumn}

\begin{table}[hb]
\begin{center}
\begin{tabular}{l D{.}{.}{3.5}@{} }
\toprule
               & \multicolumn{1}{c}{Model 1} \\
\midrule
(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)     \\
\midrule
AIC            & 56.76      \\
BIC            & 57.75      \\
Log Likelihood & -23.38     \\
Deviance       & 5.13       \\
Num. obs.      & 9          \\
\bottomrule
\multicolumn{2}{l}{\scriptsize{$^{***}p<0.001$, $^{**}p<0.01$, $^*p<0.05$}}
\end{tabular}
\caption{Regression Estimation Results}
\label{tab:1}
\end{center}
\end{table}

If you get a different output using the same code, please report back which texreg version you are using. If you are using the same version but your own example produces a result that looks different, please provide a minimal self-contained example.

查看更多
登录 后发表回答