texreg - 创建空列

texreg - create empty column

我使用 texreg 从 R 创建 LaTeX table。我想在输出中插入一个空列(出于风格原因)。我当然可以手动执行此操作,但是能够自动创建它会很棒。这是一个例子:

library(texreg)

x1  <- rnorm(n=100,m=1,s=1)
x2  <- rnorm(n=100,m=1,s=1)
e  <- rnorm(n=100,m=0,s=1)

y <- 0.1 + 0.3 * x1 + 0.4 * x2 + e

reg1 <- lm(y~x1)
reg2 <- lm(y~x2)
reg3 <- lm(y~x1+x2)

texreg(list(reg1,reg2,reg3)
       ,stars=c(0.01,0.05,0.1)
       ,digits=2
       ,dcolumn=T
       ,use.packages=F 
       ,file="tabfile.tex")

这给了我输出:

\begin{table}
\begin{center}
\begin{tabular}{l D{.}{.}{3.5} D{.}{.}{3.5} D{.}{.}{3.5} }
\hline
 & \multicolumn{1}{c}{Model 1} & \multicolumn{1}{c}{Model 2} & \multicolumn{1}{c}{Model 3} \
\hline
(Intercept) & 0.59^{***} & 0.53^{***} & 0.05       \
            & (0.16)     & (0.16)     & (0.19)     \
x1          & 0.36^{***} &            & 0.40^{***} \
            & (0.11)     &            & (0.10)     \
x2          &            & 0.43^{***} & 0.48^{***} \
            &            & (0.11)     & (0.11)     \
\hline
R$^2$       & 0.10       & 0.13       & 0.25       \
Adj. R$^2$  & 0.09       & 0.12       & 0.23       \
Num. obs.   & 100        & 100        & 100        \
RMSE        & 1.05       & 1.03       & 0.96       \
\hline
\multicolumn{4}{l}{\scriptsize{$^{***}p<0.01$, $^{**}p<0.05$, $^*p<0.1$}}
\end{tabular}
\caption{Statistical models}
\label{table:coefficients}
\end{center}
\end{table}

我想要的是:

\begin{table}
\begin{center}
\begin{tabular}{lc D{.}{.}{3.5} D{.}{.}{3.5} D{.}{.}{3.5} }
\hline
 && \multicolumn{1}{c}{Model 1} & \multicolumn{1}{c}{Model 2} & \multicolumn{1}{c}{Model 3} \
\hline
(Intercept) && 0.59^{***} & 0.53^{***} & 0.05       \
            && (0.16)     & (0.16)     & (0.19)     \
x1          && 0.36^{***} &            & 0.40^{***} \
            && (0.11)     &            & (0.10)     \
x2          &&            & 0.43^{***} & 0.48^{***} \
            &&            & (0.11)     & (0.11)     \
\hline
R$^2$       && 0.10       & 0.13       & 0.25       \
Adj. R$^2$  && 0.09       & 0.12       & 0.23       \
Num. obs.   && 100        & 100        & 100        \
RMSE        && 1.05       & 1.03       & 0.96       \
\hline
\multicolumn{5}{l}{\scriptsize{$^{***}p<0.01$, $^{**}p<0.05$, $^*p<0.1$}}
\end{tabular}
\caption{Statistical models}
\label{table:coefficients}
\end{center}
\end{table}

当然,如果有办法插入任意空列就更好了。

您可以使用 texregcustom.columns 参数插入新列。新列应作为命名列表移交。 custom.col.pos 参数可用于指示列的位置。例如,您可以通过添加参数 custom.columns = list("new column" = rep("", 3)).

来插入一个新的空列