Debian Codegraph @

inst/doc/mtable-html.Rmd

raw
1 ---
2 title: Tables of model estimates
3 output: rmarkdown::html_vignette
4 vignette: >
5 % \VignetteEngine{knitr::rmarkdown}
6 % \VignetteIndexEntry{Tables of model estimates}
7 ---
8
9 ```{r,echo=FALSE,message=FALSE}
10 knitr::opts_chunk$set(comment=NA,
11 fig.align="center",
12 results="markup")
13 ```
14
15 First, we load the package and estimate some regression models.
16
17 ```{r, message=FALSE}
18 library(memisc)
19 lm0 <- lm(sr ~ pop15 + pop75, data = LifeCycleSavings)
20 lm1 <- lm(sr ~ dpi + ddpi, data = LifeCycleSavings)
21 lm2 <- lm(sr ~ pop15 + pop75 + dpi + ddpi, data = LifeCycleSavings)
22 ```
23
24 Next, we put them together into a table with `mtable()`.
25
26 ```{r}
27 mtable123 <- mtable("Model 1"=lm0,"Model 2"=lm1,"Model 3"=lm2,
28 summary.stats=c("sigma","R-squared","F","p","N"))
29 ```
30 Third, we improve the appearance of the results by relabeling the `mtable` object.
31 ```{r, comment=NA}
32 mtable123 <- relabel(mtable123,
33 "(Intercept)" = "Constant",
34 pop15 = "Percentage of population under 15",
35 pop75 = "Percentage of population over 75",
36 dpi = "Real per-capita disposable income",
37 ddpi = "Growth rate of real per-capita disp. income"
38 )
39 ```
40 Finally we view the results in HTML format.
41 ```{r, results='asis'}
42 show_html(mtable123)
43 ```
44 The results can be written into an HTML file using
45 `write_html(mtable123,file="mtable123.html")` or the like. MS Word or LibreOffice can import such a file.
46
47 [^1]: Unfortunately, LibreOffice currently seems to do a less than perfect job in
48 importing HTML tables. The columns are a bit too wide and need to be
49 adjusted by hand as do the skips after paragraphs. The example you find at
50 the link mentioned above is thus manually adjusted.
51