Learn R Programming

texreg (version 1.25)

texreg: Convert regression output to LaTeX or HTML tables

Description

Conversion of R regression output to LaTeX or HTML tables.

Usage

texreg(l, file = NA, 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.pval = 0, omit.coef = NA, reorder.coef = NULL, 
    reorder.gof = NULL, return.string = FALSE, bold = 0.00, 
    center = TRUE, caption = "Statistical models", 
    caption.above = FALSE, label = "table:coefficients", 
    booktabs = FALSE, dcolumn = FALSE, sideways = FALSE, 
    use.packages = TRUE, table = TRUE, no.margin = TRUE, 
    scriptsize = FALSE, float.pos = "", ...)

htmlreg(l, file = NA, 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.pval = 0, omit.coef = NA, reorder.coef = NULL, reorder.gof = NULL, return.string = FALSE, 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, ...)

screenreg(l, file = NA, 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.pval = 0, omit.coef = NA, reorder.coef = NULL, reorder.gof = NULL, return.string = FALSE, column.spacing = 2, outer.rule = "=", inner.rule = "-", ...)

Arguments

l
A statistical model or a list of statistical models. Lists of models can be specified as l = list(model.1, model.2, ...). Different object types can also be mixed.
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 single.r
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, stars = numeric(0) will not print any stars and will not print any note about significance levels below the t
custom.model.names
A character vector of labels for the models. By default, the models are named Model 1, Model 2, etc. Specifying model.names = c("My name 1", "My name 2") etc. overrides the default behavior.
custom.coef.names
By default, texreg uses the coefficient names which are stored in the models. The custom.names argument can be used to replace them by other character strings in the order of appearance. For example, if a table shows a total of three differen
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.coef.name
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 (custom.note = ""), the note will be omitted completely.
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 digits argument in the round function of the base package.
leading.zero
Most journals require leading zeros of coefficients and standard errors (for example, 0.35). This is also the default texreg behavior. Some journals, however, require omission of leading zeros (for example, .35). This can be achi
symbol
If four threshold values are handed over to the stars argument, p values smaller than the largest threshold value but larger than the second-largest threshold value are denoted by this symbol. The default symbol is "\\cdot" for t
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
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 th
override.pval
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 thre
omit.coef
A character string which is used as a regular expression to remove coefficient rows from the table. For example, omit.coef = "group" deletes all coefficient rows from the table where the name of the coefficient contains the character sequence
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.coef = c(3, 2, 1) will put t
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, reorder.gof = c(3, 2, 1)
return.string
Should the table be returned as a character object, which can later be printed again using the cat() function?
bold
[only in the texreg and htmlreg functions] The p value threshold below which the coefficient shall be formatted in a bold font. For example, bold = 0.05 will cause all coefficients which are significant at the 95% le
center
[only in the texreg and htmlreg functions] Should the table be horizontally aligned at the center of the page?
caption
[only in the texreg and htmlreg functions] Set the caption of the table.
caption.above
[only in the texreg and htmlreg functions] Should the caption of the table be placed above the table? By default, it is placed below the table.
label
[only in the texreg function] Set the label of the table environment.
booktabs
[only in the texreg function] Use the booktabs LaTeX package to get thick horizontal rules in the output table (recommended).
dcolumn
[only in the texreg function] Use the dcolumn LaTeX package to get a nice alignment of the coefficients (recommended).
sideways
[only in the texreg function] If sideways = TRUE is set, the table floating environment is replaced by a sidewaystable float, and the rotating package is loaded in the preamble. The argument
use.packages
[only in the texreg function] If this argument is set to TRUE (= the default behavior), the required LaTeX packages are loaded in the beginning. If set to FALSE, the use package statements are omitted from the output
table
[only in the texreg function] By default, texreg puts the actual tabular object in a table floating environment. To get only the tabular object without the whole table header, set table = FALSE
no.margin
[only in the texreg function] In order to save space, inner margins of tables are switched off by default. To reactivate the default table spacing, set no.margin = FALSE.
scriptsize
[only in the texreg function] To save horizontal space on the page, the table can be set in script size instead of normal text size by setting scriptsize = TRUE.
float.pos
[only in the texreg function] This argument specifies where the table should be located on the page or in the document. By default, no floating position is specified, and LaTeX takes care of the position automatically. Possible values include
star.symbol
[only in the htmlreg function] Alternative characters for the significance stars can be specified. This is useful if knitr and Markdown are used for HTML report generation. In Markdown, asterisks or stars are interpreted as special
inline.css
[only in the htmlreg function] Should the CSS stylesheets be embedded directly in the code of the table (inline.css = TRUE), or should the CSS stylesheets be enclosed in the tag, that is, separated from the table code (
doctype
[only in the htmlreg function] Should the first line of the HTML code contain the DOCTYPE definition? If TRUE, the HTML 4 TRANSITIONAL version is used. If FALSE, no DOCTYPE will be included. Omitting the DOCTYPE can
html.tag
[only in the htmlreg function] Should the table code (and possibly the and tags) be enclosed in an tag? Suppressing this tag is recommended when knitr is used for dynamic HTML or Markdown report generation. Inc
head.tag
[only in the htmlreg function] Should the tag (including CSS definitions and title/caption) be included in the HTML code? Suppressing this tag is recommended when knitr is used for dynamic HTML or Markdown report generation.
body.tag
[only in the htmlreg function] Should the table code be enclosed in a HTML tag? Suppressing this tag is recommended when knitr is used for dynamic HTML or Markdown report generation. Including this tag is recommended when th
column.spacing
[only in the screenreg function] The amount of space between any two columns of a table. By default, two spaces are used. If the tables do not fit on a single page horizontally, the value can be set to 1 or 0.
outer.rule
[only in the screenreg function] The character which is used to draw the outer horizontal line above and below a table. If an empty character object is provided (i.e., outer.rule = ""), there will be no outer horizontal lines. Re
inner.rule
[only in the screenreg function] The character which is used to draw the inner horizontal line above and below a table. If an empty character object is provided (i.e., outer.rule = ""), there will be no inner horizontal lines. Re
...
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, or for naive versus MCMC-based computation of p values. See the help en

Details

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.

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.

See Also

texreg-package extract extract-methods

Examples

Run this code
#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")

Run the code above in your browser using DataLab