R统计表格输出为latex:stargazer及其它
stargazer
这个名字很炫的包是用来生成统计模型摘要的latex代码的。这样把生成的代码放到latex里边编译,就可以生成出版级的效果(显然这针对的是R输出的苍白无力)。
library(stargazer)
prostate <- read.csv("E:/RB/prostate.csv")
# 生成prostate的摘要
stargazer(prostate)
## \begin{table}[!htbp] \centering
## \caption{}
## \label{}
## \begin{tabular}{@{\extracolsep{5pt}}lccccc}
## \\[-1.8ex]\hline
## \hline \\[-1.8ex]
## Statistic & \multicolumn{1}{c}{N} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Max} \\
## \hline \\[-1.8ex]
## lcavol & 97 & 1.350 & 1.179 & $-$1.347 & 3.821 \\
## age & 97 & 63.870 & 7.445 & 41 & 79 \\
## lbph & 97 & 0.100 & 1.451 & $-$1.386 & 2.326 \\
## lcp & 97 & $-$0.179 & 1.398 & $-$1.386 & 2.904 \\
## gleason & 97 & 6.753 & 0.722 & 6 & 9 \\
## lpsa & 97 & 2.478 & 1.154 & $-$0.431 & 5.583 \\
## \hline \\[-1.8ex]
## \normalsize
## \end{tabular}
## \end{table}
line1 <- lm(lcavol ~ ., data = prostate)
# 生成回归的摘要
stargazer(line1)
(略)
latex编译的效果是这样的:
除了这个占星师的包,还有好几个类似的可以把R输出转换为latex代码的包,比如texreg。
细节请参考: [1]stargazer:beautiful LATEX and ASCII tables from R statistical output http://cran.r-project.org/web/packages/stargazer/vignettes/stargazer.pdf
[2]texreg: Conversion of Statistical Model Output in R to LATEX and HTML Tables http://cran.r-project.org/web/packages/texreg/vignettes/jss1020.pdf
这个名字很炫的包是用来生成统计模型摘要的latex代码的。这样把生成的代码放到latex里边编译,就可以生成出版级的效果(显然这针对的是R输出的苍白无力)。
library(stargazer)
prostate <- read.csv("E:/RB/prostate.csv")
# 生成prostate的摘要
stargazer(prostate)
## \begin{table}[!htbp] \centering
## \caption{}
## \label{}
## \begin{tabular}{@{\extracolsep{5pt}}lccccc}
## \\[-1.8ex]\hline
## \hline \\[-1.8ex]
## Statistic & \multicolumn{1}{c}{N} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Max} \\
## \hline \\[-1.8ex]
## lcavol & 97 & 1.350 & 1.179 & $-$1.347 & 3.821 \\
## age & 97 & 63.870 & 7.445 & 41 & 79 \\
## lbph & 97 & 0.100 & 1.451 & $-$1.386 & 2.326 \\
## lcp & 97 & $-$0.179 & 1.398 & $-$1.386 & 2.904 \\
## gleason & 97 & 6.753 & 0.722 & 6 & 9 \\
## lpsa & 97 & 2.478 & 1.154 & $-$0.431 & 5.583 \\
## \hline \\[-1.8ex]
## \normalsize
## \end{tabular}
## \end{table}
line1 <- lm(lcavol ~ ., data = prostate)
# 生成回归的摘要
stargazer(line1)
(略)
latex编译的效果是这样的:
除了这个占星师的包,还有好几个类似的可以把R输出转换为latex代码的包,比如texreg。
细节请参考: [1]stargazer:beautiful LATEX and ASCII tables from R statistical output http://cran.r-project.org/web/packages/stargazer/vignettes/stargazer.pdf
[2]texreg: Conversion of Statistical Model Output in R to LATEX and HTML Tables http://cran.r-project.org/web/packages/texreg/vignettes/jss1020.pdf
马上就开始写毕业论文了!
可以研究下,应该用的上
嗯嗯!
> 我来回应