R markdown"texreg" [英] R markdown "texreg"

查看:286
本文介绍了R markdown"texreg"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过使用以下注释来获取回归结果的乳胶表;

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")

但是,此"texreg"命令给出的是原始输出,而不是干净的表;

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}

能否请您帮我如何在R中使用texreg命令获得干净的回归结果表?

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

推荐答案

您没有提供一个简单的独立示例.但是,如果我使用glm帮助页面上提供的示例,它似乎确实可以工作.请参阅以下结果.

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}

如果使用相同的代码获得不同的输出,请报告所使用的texreg版本.如果您使用的是相同版本,但是您自己的示例所产生的结果看上去有所不同,请提供一个最小的独立示例.

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.

这篇关于R markdown"texreg"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆