使用带有RMardkown的stargazer生成带有模型列表的LaTex表

时间:2016-02-01 13:51:56

标签: r pdf latex r-markdown stargazer

我想介绍一个表格,其中包含通过stargazer包生成的回归模型输出到 RMarkdown 文档中。

RMarkdown

有关RMarkdown文档的代码如下:

---
title: "Text"
author: "Author"
date: "1 February 2016"
output: 
  pdf_document: 
    highlight: kate
    latex_engine: lualatex
    number_sections: yes
    toc: yes
---


```{r models, eval=TRUE, echo=FALSE}
# Data / Libs
data(mtcars)
lstModels <- list()
require(stargazer)

# Models
lstModels$mod1 <- lm(mpg ~ cyl + drat, data = mtcars)
lstModels$mod2 <- lm(gear ~ cyl + drat, data = mtcars)
```

Summary

```{r summaryModels, eval=TRUE, results="asis", echo=FALSE}
stargazer(lstModels,
          title = "Regression Results", type = "latex", 
          multicolumn = TRUE, no.space = TRUE,
          out.header = FALSE, header = FALSE)
```

问题

执行 RMarkdown 文件失败:

output file: mod_example.knit.md

!LuaTeX error (file lmmi10): Font lmmi10 at 600 not found
 ==> Fatal error occurred, no output PDF file produced!

Sorry, but miktex-makemf did not succeed for the following reason:

  The lmmi source file could not be found.

The log file hopefully contains the information to get MiKTeX going again:

  C:/Users/me/AppData/Local/MiKTeX/2.9/miktex/log/miktex-makemf.log

You may want to visit the MiKTeX project page, if you need help.

Sorry, but miktex-makepk did not succeed for the following reason:

  PK font lmmi10 could not be created.

The log file hopefully contains the information to get MiKTeX going again:

  C:/Users/me/AppData/Local/MiKTeX/2.9/miktex/log/miktex-makepk.log

You may want to visit the MiKTeX project page, if you need help.

pandoc.exe: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
In addition: Warning message:
running command '"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS mod_example.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash-implicit_figures --output mod_example.pdf --table-of-contents --toc-depth 2 --template "C:\Users\Zdeb.Konrad\Documents\R\win-library\3.2\rmarkdown\rmd\latex\default.tex" --number-sections --highlight-style kate --latex-engine lualatex --variable graphics=yes --variable "geometry:margin=1in"' had status 43 
Execution halted

备注

似乎stargazer生成了所需的代码:

> stargazer(lstModels,
+           title = "Regression Results", type = "latex", 
+           multicolumn = TRUE, no.space = TRUE,
+           out.header = FALSE, header = FALSE)

\begin{table}[!htbp] \centering 
  \caption{Regression Results} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}}lcc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & \multicolumn{2}{c}{\textit{Dependent variable:}} \\ 
\cline{2-3} 
\\[-1.8ex] & mpg & gear \\ 
\\[-1.8ex] & (1) & (2)\\ 
\hline \\[-1.8ex] 
 cyl & $-$2.484$^{***}$ & $-$0.002 \\ 
  & (0.447) & (0.077) \\ 
  drat & 1.872 & 0.960$^{***}$ \\ 
  & (1.494) & (0.256) \\ 
  Constant & 28.725$^{***}$ & 0.251 \\ 
  & (7.592) & (1.303) \\ 
 \hline \\[-1.8ex] 
Observations & 32 & 32 \\ 
R$^{2}$ & 0.740 & 0.489 \\ 
Adjusted R$^{2}$ & 0.722 & 0.454 \\ 
Residual Std. Error (df = 29) & 3.176 & 0.545 \\ 
F Statistic (df = 2; 29) & 41.323$^{***}$ & 13.902$^{***}$ \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{2}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
\end{tabular}
\end{table} 

并关注this discussion它应该没有任何问题。有没有什么可以改变乳胶输出?

0 个答案:

没有答案