Description Usage Arguments Details Author(s) References See Also Examples
Conversion of R regression output to LaTeX or HTML tables.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | texreg(l, file = NULL, single.row = FALSE, stars = c(0.001,
0.01, 0.05), custom.model.names = NULL,
custom.coef.names = NULL, custom.gof.names = NULL,
custom.note = NULL, digits = 2, leading.zero = TRUE,
symbol = "\\cdot", override.coef = 0, override.se = 0,
override.pvalues = 0, override.ci.low = 0,
override.ci.up = 0, omit.coef = NULL, reorder.coef = NULL,
reorder.gof = NULL, ci.force = FALSE, ci.force.level = 0.95,
ci.test = 0, groups = NULL, custom.columns = NULL,
custom.col.pos = NULL, bold = 0.00, center = TRUE,
caption = "Statistical models", caption.above = FALSE,
label = "table:coefficients", booktabs = FALSE,
dcolumn = FALSE, sideways = FALSE, longtable = FALSE,
use.packages = TRUE, table = TRUE, no.margin = FALSE,
fontsize = NULL, scalebox = NULL, float.pos = "", ...)
htmlreg(l, file = NULL, single.row = FALSE, stars = c(0.001,
0.01, 0.05), custom.model.names = NULL,
custom.coef.names = NULL, custom.gof.names = NULL,
custom.note = NULL, digits = 2, leading.zero = TRUE,
symbol = "·", override.coef = 0, override.se = 0,
override.pvalues = 0, override.ci.low = 0,
override.ci.up = 0, omit.coef = NULL, reorder.coef = NULL,
reorder.gof = NULL, ci.force = FALSE, ci.force.level = 0.95,
ci.test = 0, groups = NULL, custom.columns = NULL,
custom.col.pos = NULL, bold = 0.00, center = TRUE,
caption = "Statistical models", caption.above = FALSE,
star.symbol = "*", inline.css = TRUE, doctype = TRUE,
html.tag = FALSE, head.tag = FALSE, body.tag = FALSE,
indentation = "", vertical.align.px = 0, ...)
screenreg(l, file = NULL, single.row = FALSE, stars = c(0.001,
0.01, 0.05), custom.model.names = NULL,
custom.coef.names = NULL, custom.gof.names = NULL,
custom.note = NULL, digits = 2, leading.zero = TRUE,
symbol = ".", override.coef = 0, override.se = 0,
override.pvalues = 0, override.ci.low = 0,
override.ci.up = 0, omit.coef = NULL, reorder.coef = NULL,
reorder.gof = NULL, ci.force = FALSE, ci.force.level = 0.95,
ci.test = 0, groups = NULL, custom.columns = NULL,
custom.col.pos = NULL, column.spacing = 2, outer.rule = "=",
inner.rule = "-", ...)
|
l |
A statistical model or a list of statistical models. Lists of models can be specified as |
file |
Using this argument, the resulting table is written to a file rather than to the R prompt. The file name can be specified as a character string. Writing a table to a file can be useful for working with MS Office or LibreOffice. For example, using the |
single.row |
By default, a model parameter takes up two lines of the table: the standard error is listed in parentheses under the coefficient. This saves a lot of horizontal space on the page and is the default table format in most academic journals. If |
stars |
The significance levels to be used to draw stars. Between 0 and 4 threshold values can be provided as a numeric vector. For example, |
custom.model.names |
A character vector of labels for the models. By default, the models are named Model 1, Model 2, etc. Specifying |
custom.coef.names |
By default, texreg uses the coefficient names which are stored in the models. The Sometimes it happens that the same variable has a different name in different models. In this case, the user can use this function to assign identical names. If possible, the rows will then be merged into a single row unless both rows contain values in the same column. Where the argument contains an |
custom.gof.names |
A character vector which is used to replace the names of the goodness-of-fit statistics at the bottom of the table. The vector must have the same length as the number of GOF statistics in the final table. The argument works like the |
custom.note |
With this argument, a replacement text for the significance note below the table can be provided. If an empty character object is provided ( |
digits |
Set the number of decimal places for coefficients, standard errors and goodness-of-fit statistics. Do not use negative values! The argument works like the |
leading.zero |
Most journals require leading zeros of coefficients and standard errors (for example, |
symbol |
If four threshold values are handed over to the |
override.coef |
Set custom values for the coefficients. New coefficients are provided as a list of numeric vectors. The list contains vectors of coefficients for each model. There must be as many vectors of coefficients as there are models. For example, if there are two models with three model terms each, the argument could be specified as |
override.se |
Set custom values for the standard errors. New standard errors are provided as a list of numeric vectors. The list contains vectors of standard errors for each model. There must be as many vectors of standard errors as there are models. For example, if there are two models with three coefficients each, the argument could be specified as |
override.pvalues |
Set custom values for the p values. New p values are provided as a list of numeric vectors. The list contains vectors of p values for each model. There must be as many vectors of p values as there are models. For example, if there are two models with three coefficients each, the argument could be specified as |
override.ci.low |
Set custom lower confidence interval bounds. This works like the other override arguments, with one exception: if confidence intervals are provided here and in the |
override.ci.up |
Set custom upper confidence interval bounds. This works like the other override arguments, with one exception: if confidence intervals are provided here and in the |
omit.coef |
A character string which is used as a regular expression to remove coefficient rows from the table. For example, |
reorder.coef |
Reorder the rows of the coefficient block of the resulting table in a custom way. The argument takes a vector of the same length as the number of coefficients. For example, if there are three coefficients, |
reorder.gof |
Reorder the rows of the goodness-of-fit block of the resulting table in a custom way. The argument takes a vector of the same length as the number of GOF statistics. For example, if there are three goodness-of-fit rows, |
ci.force |
Should confidence intervals be used instead of the default standard errors and p values? Most models implemented in the texreg package report standard errors and p values by default while few models report confidence intervals. However, the functions in the texreg package can convert standard errors and into confidence intervals if desired. To enforce confidence intervals instead of standard errors, the |
ci.force.level |
If the |
ci.test |
If confidence intervals are reported, the |
groups |
This argument can be used to group the rows of the table into blocks. For example, there could be one block for hypotheses and another block for control variables. Each group has a heading, and the row labels within a group are indented. The partitions must be handed over as a list of named numeric vectors, where each number is a row index and each name is the heading of the group. Example: |
custom.columns |
An optional list of additional text columns to be inserted into the table, for example coefficient types. The list should contain one or more character vectors with as many character or numeric elements as there are rows. If the vectors in the list are named, the names are used as labels in the table header. For example, |
custom.col.pos |
An optional integer vector of positions for the columns given in the |
bold |
[only in the |
center |
[only in the |
caption |
[only in the |
caption.above |
[only in the |
label |
[only in the |
booktabs |
[only in the |
dcolumn |
[only in the |
sideways |
[only in the |
longtable |
[only in the |
use.packages |
[only in the |
table |
[only in the |
no.margin |
[only in the |
fontsize |
[only in the |
scalebox |
[only in the |
float.pos |
[only in the |
star.symbol |
[only in the |
inline.css |
[only in the |
doctype |
[only in the |
html.tag |
[only in the |
head.tag |
[only in the |
body.tag |
[only in the |
indentation |
[only in the |
vertical.align.px |
[only in the |
column.spacing |
[only in the |
outer.rule |
[only in the |
inner.rule |
[only in the |
... |
Custom options to be passed on to the extract function. For example, most extract methods provide custom options for the inclusion or exclusion of specific goodness-of-fit statistics. See the help entries of extract and extract-methods for more information. |
texreg converts coefficients, standard errors, significance stars, and goodness-of-fit statistics of statistical models into LaTeX tables or HTML tables or into nicely formatted screen output for the R console. A list of several models can be combined in a single table. The output is customizable. New model types can be easily implemented. Confidence intervals can be used instead of standard errors and p values.
The texreg()
function creates LaTeX code for inclusion
in a LaTeX document or for usage with Sweave or knitr.
The htmlreg()
function creates HTML code. Tables in HTML
format can be saved with a ".html" extension and displayed in
a web browser. Alternatively, they can be saved with a ".doc"
extension and opened in MS Word for inclusion in office
documents. htmlreg()
also works with knitr and HTML
or Markdown. Note that the inline.css
, doctype
,
html.tag
, head.tag
, and body.tag
arguments
must be adjusted for the different purposes (see the description
of the arguments).
The screenreg()
function creates text representations of
tables and prints them to the R console. This is an alternative
to the summary
method and serves easy model comparison.
Moreover, once a table has been prepared in the R console, it
can be later exported to LaTeX or HTML with little extra effort
because the majority of arguments of the three functions is
identical.
Philip Leifeld (http://www.philipleifeld.com)
Leifeld, Philip (2013). texreg: Conversion of Statistical Model Output in R to LaTeX and HTML Tables. Journal of Statistical Software, 55(8), 1-24. http://www.jstatsoft.org/v55/i08/.
texreg-package extract extract-methods plotreg
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #Linear mixed-effects models
library(nlme)
model.1 <- lme(distance ~ age, data = Orthodont, random = ~ 1)
model.2 <- lme(distance ~ age + Sex, data = Orthodont, random = ~ 1)
texreg(list(model.1, model.2), booktabs = TRUE, dcolumn = TRUE)
#Ordinary least squares model (example from the 'lm' help file)
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2,10,20, labels = c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group)
table.string <- texreg(lm.D9, return.string = TRUE)
cat(table.string)
#Create a 'fake' Office document containing a regression table
htmlreg(list(model.1, model.2), file = "texreg.doc",
inline.css = FALSE, doctype = TRUE, html.tag = TRUE,
head.tag = TRUE, body.tag = TRUE)
unlink("texreg.doc")
|
Version: 1.36.23
Date: 2017-03-03
Author: Philip Leifeld (University of Glasgow)
Please cite the JSS article in your publications -- see citation("texreg").
\usepackage{booktabs}
\usepackage{dcolumn}
\begin{table}
\begin{center}
\begin{tabular}{l D{.}{.}{4.5} D{.}{.}{4.5} }
\toprule
& \multicolumn{1}{c}{Model 1} & \multicolumn{1}{c}{Model 2} \\
\midrule
(Intercept) & 16.76^{***} & 17.71^{***} \\
& (0.80) & (0.83) \\
age & 0.66^{***} & 0.66^{***} \\
& (0.06) & (0.06) \\
SexFemale & & -2.32^{**} \\
& & (0.76) \\
\midrule
AIC & 455.00 & 447.51 \\
BIC & 465.66 & 460.78 \\
Log Likelihood & -223.50 & -218.76 \\
Num. obs. & 108 & 108 \\
Num. groups & 27 & 27 \\
\bottomrule
\multicolumn{3}{l}{\scriptsize{$^{***}p<0.001$, $^{**}p<0.01$, $^*p<0.05$}}
\end{tabular}
\caption{Statistical models}
\label{table:coefficients}
\end{center}
\end{table}
\begin{table}
\begin{center}
\begin{tabular}{l c }
\hline
& Model 1 \\
\hline
(Intercept) & $5.03^{***}$ \\
& $(0.22)$ \\
groupTrt & $-0.37$ \\
& $(0.31)$ \\
\hline
R$^2$ & 0.07 \\
Adj. R$^2$ & 0.02 \\
Num. obs. & 20 \\
RMSE & 0.70 \\
\hline
\multicolumn{2}{l}{\scriptsize{$^{***}p<0.001$, $^{**}p<0.01$, $^*p<0.05$}}
\end{tabular}
\caption{Statistical models}
\label{table:coefficients}
\end{center}
\end{table}
The table was written to the file 'texreg.doc'.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.