R 中是否有可用的工具来生成发布就绪回归表?我正在编写一份课程论文,其中我需要比较几个回归模型,如果我能从estout
Stata包中将它们嵌套在this one这样的单个表中,我将非常高兴。 / p>
我已查看xtable
,但无法达到相同的结果。任何提示将不胜感激。
以下是我的想法:
答案 0 :(得分:2)
你可能想要'memisc'包中的mtable
功能。它具有关联的LaTeX输出参数:
==========================================================================
Model 1 Model 2 Model 3
--------------------------------------------------------------------------
Constant 30.628*** 6.360*** 28.566***
(7.409) (1.252) (7.355)
Percentage of population under 15 -0.471** -0.461**
(0.147) (0.145)
Percentage of population over 75 -1.934 -1.691
(1.041) (1.084)
Real per-capita disposable income 0.001 -0.000
(0.001) (0.001)
Growth rate of real per-capita disp. income 0.529* 0.410*
(0.210) (0.196)
--------------------------------------------------------------------------
sigma 3.931 4.189 3.803
R-squared 0.262 0.162 0.338
F 8.332 4.528 5.756
p 0.001 0.016 0.001
N 50 50 50
==========================================================================
这是你得到的LaTeX代码:
texfile123 <- "mtable123.tex"
write.mtable(mtable123,forLaTeX=TRUE,file=texfile123)
file.show(texfile123)
#------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Calls:
% Model 1: lm(formula = sr ~ pop15 + pop75, data = LifeCycleSavings)
% Model 2: lm(formula = sr ~ dpi + ddpi, data = LifeCycleSavings)
% Model 3: lm(formula = sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{tabular}{lcD{.}{.}{7}cD{.}{.}{7}cD{.}{.}{7}}
\toprule
&&\multicolumn{1}{c}{Model 1} && \multicolumn{1}{c}{Model 2} && \multicolumn{1}{c}{Model 3}\\
\midrule
Constant & & 30.628^{***} && 6.360^{***} && 28.566^{***}\\
& & (7.409) && (1.252) && (7.355) \\
Percentage of population under 15 & & -0.471^{**} && && -0.461^{**} \\
& & (0.147) && && (0.145) \\
Percentage of population over 75 & & -1.934 && && -1.691 \\
& & (1.041) && && (1.084) \\
Real per-capita disposable income & & && 0.001 && -0.000 \\
& & && (0.001) && (0.001) \\
Growth rate of real per-capita disp. income & & && 0.529^{*} && 0.410^{*} \\
& & && (0.210) && (0.196) \\
\midrule
sigma & & 3.931 && 4.189 && 3.803 \\
R-squared & & 0.262 && 0.162 && 0.338 \\
F & & 8.332 && 4.528 && 5.756 \\
p & & 0.001 && 0.016 && 0.001 \\
N & & 50 && 50 && 50 \\
\bottomrule
\end{tabular}
答案 1 :(得分:2)
R wikibook在R的生产质量输出方面有一些很好的资源。
我认为wikibook中列出的Paul Johnson的这个功能正是您所需要的:
http://pj.freefaculty.org/R/WorkingExamples/outreg-worked.R
我编辑了我自己使用的函数来处理booktabs格式,并允许具有额外属性的模型:
答案 2 :(得分:1)
xtable
可以做到这一点,但它有点像黑客。
选择两个名为lm.x和lm.y的线性模型。
如果您使用以下代码:
myregtables <- rbind(xtable(summary(lm.x)), xtable(summary(lm.y)))
xtable
将生成一个包含两个回归模型的表。如果你在LaTeX中添加\hline
(或者两个),那么看起来应该没问题。您仍然只有两个模型的标签和标题。正如我所说,它有点像一个hacky解决方案。