0
私はtexregを使ってRからLaTeXテーブルを作成します。出力に空文字列を挿入したいと思います。私はもちろん、これを手動で行うことはできますが、これを自動的に作成できることは素晴らしいことです。次に例を示します。texreg - 空の列を作成する
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}
場合、それはもちろん、さらに良いでしょう任意の空の列を挿入する方法がありました。
'' texreg''は '' lm''オブジェクトに対して作られたもので、これだけを受け入れます。 [この記事で説明した](http://stackoverflow.com/questions/21955145/create-a-new-lm-object-using-r)のように、既存のlmオブジェクトを取って個々のlmオブジェクトを作成することができますその数字を文字に操作します。多分 'textreg'がこれを受け入れるでしょう。 '' emptyLM < - reg1; emptyLM $ coefficients [1:2] < - as.character(rep( ""、2)) 'などです。それでは、 '' texreg(list(reg1、reg2、emptyLM、reg3) '')を呼び出してください。幸運なことに – nilsole
あなたの必要に応じて '' textreg''関数自体を操作するのが最後の可能性です。 – nilsole
@nilsole:これ'' texreg''はすべての種類のモデル型に対して作られました。現在70種類以上がサポートされており、カスタマイズ可能です。カスタマイズ可能とは、一般的な '' extract''関数のメソッドを提供することで新しい拡張機能を簡単に書くことができるということです。私の答えはここに記載されています:http://stackoverflow.com/questions/38894044/print-beautiful-tables-for-h2o-models-in-r。 '' lm''コンテナに係数を強制的に書き込むか、 '' texreg''を変更する'関数は絶対に間違った方法です。 –