我一直在运行一堆不同的回归模型,现在想将他们的估计值放入 LaTeX 表中。为了使不同的规格具有可比性,我想使用包装或产品中的那种表,即不同模型显示在列中,这些模型的参数估计显示在适当的行中outreg
。这就是我所拥有的:rockchalk
mtable
memisc
df <- data.frame(x=rnorm(20),
z=rnorm(20),
group=gl(5,4,20,labels=paste('group',rep(1:5))))
df$y = 5 + 2*df$x + 5*df$z + rep(c(3.2,5,6.2,8.2,5),each=4) + rnorm(20)
model1 <- lm(y ~ x + z + factor(group),data=df)
model2 <- lm(y ~ x + factor(group),data=df)
model3 <- lm(y ~ x + z,data=df)
library(memisc)
reg.table <- mtable("Model 1"=model1,"Model 2"=model2,"Model 3"=model3,
summary.stats=c("sigma","R-squared","F","p","N"))
toLatex(reg.table)
这工作得很好,但我有一个大约有 200 个级别和相应大量系数的因子。我想做的是要么从表中省略与该因子相关的系数,要么(为了奖励积分!)以简单的“是”或“否”表明该因子在模型中使用。所以,我理想的输出是这样的:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
%
% Calls:
% Model 1: lm(formula = y ~ x + z + factor(group), data = df)
% Model 2: lm(formula = y ~ x + factor(group), data = df)
% Model 3: lm(formula = y ~ x + z, data = df)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %
\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
(Intercept) & & 8.315^{***} && 4.235 && 10.338^{***}\\
& & (0.537) && (3.276) && (0.468) \\
x & & 1.976^{***} && 2.398 && 1.858^{***}\\
& & (0.238) && (1.530) && (0.443) \\
z & & 5.389^{***} && && 5.359^{***}\\
& & (0.226) && && (0.463) \\
group & & yes && yes && no \\
\midrule
sigma & & 0.929 && 5.981 && 2.092 \\
R-squared & & 0.984 && 0.265 && 0.891 \\
F & & 129.485 && 1.009 && 69.306 \\
p & & 0.000 && 0.448 && 0.000 \\
N & & 20 && 20 && 20 \\
\bottomrule
\end{tabular}
这可能吗?