Learn R Programming

texreg (version 1.22)

texreg: Convert regression output to LaTeX or HTML tables

Description

Conversion of R regression output to LaTeX or HTML tables.

Usage

texreg(l, single.row=FALSE, no.margin=TRUE, leading.zero=TRUE, 
    table=TRUE, sideways=FALSE, float.pos="", 
    stars=c(0.001, 0.01, 0.05, 0.1), symbol="\\cdot", 
    use.packages=TRUE, caption="Statistical models", 
    label="table:coefficients", dcolumn=TRUE, booktabs=TRUE, 
    scriptsize=FALSE, custom.names=NULL, custom.gof.names=NULL, 
    model.names=NULL, digits=2, center=TRUE, override.coef=0, 
    override.se=0, override.pval=0, omit.coef=NA, 
    reorder.coef=NULL, reorder.gof=NULL, file=NA, 
    return.string=FALSE, caption.above=FALSE, bold=0.00, 
    custom.note=NULL, ...)
htmlreg(l, single.row=FALSE, leading.zero=TRUE, 
    stars=c(0.001, 0.01, 0.05, 0.1), symbol="·", 
    caption="", custom.names=NULL, custom.gof.names=NULL, 
    model.names=NULL, digits=2, doctype=TRUE, star.symbol="*", 
    center=FALSE, override.coef=0, override.se=0, override.pval=0, 
    omit.coef=NA, reorder.coef=NULL, reorder.gof=NULL, file=NA, 
    return.string=FALSE, caption.above=FALSE, bold=0.00, 
    custom.note=NULL, ...)
screenreg(l, single.row=FALSE, leading.zero=TRUE, 
    stars=c(0.001, 0.01, 0.05, 0.1), symbol=".", 
    custom.names=NULL, custom.gof.names=NULL, model.names=NULL, 
    digits=2, outer.rule="=", inner.rule="-", column.spacing=2, 
    override.coef=0, override.se=0, override.pval=0, omit.coef=NA, 
    reorder.coef=NULL, reorder.gof=NULL, file=NA, 
    return.string=FALSE, custom.note=NULL, ...)

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.
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
no.margin
In order to save space, inner margins of tables are switched off by default. To reactivate the default table spacing, set no.margin=FALSE.
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
table
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.
sideways
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 only has an effect if table=TRUE
float.pos
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 h (here), p (pag
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 tab
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.
symbol
By default, p values smaller than 0.1 and larger than 0.05 are reported as centered dots (symbol="\\cdot" for the LaTeX dot or symbol="·" for the HTML dot) when strong.signif=TRUE is set. Any other mathematica
use.packages
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.
caption
Set the caption of the table.
label
Set the label of the table environment.
dcolumn
Use the dcolumn LaTeX package to get a nice alignment of the coefficients.
booktabs
Use the booktabs LaTeX package to get thick horizontal rules in the output table.
scriptsize
To save horizontal space on the page, the table can be set in script size instead of normal text size by setting scriptsize=TRUE.
custom.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.names
model.names
A string 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.
digits
Set the number of decimal places for coefficients, standard errors and goodness-of-fit statistics. Do not use negative values!
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 the
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)
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, an HTML table
return.string
Should the table be returned as a character object, which can later be printed again using the cat() function?
outer.rule
The character which is used to draw the outer horizontal line above and below a table (only for the screenreg() function). If an empty character object is provided (i.e., outer.rule=""), there will be no outer horizontal lines. R
inner.rule
The character which is used to draw the inner horizontal line above and below a table (only for the screenreg() function). If an empty character object is provided (i.e., outer.rule=""), there will be no inner horizontal lines. R
doctype
For the htmlreg() function: should the first line of the HTML code contain the DOCTYPE definition? If TRUE, the HTML 5 version is used. If FALSE, no DOCTYPE will be included. Omitting the DOCTYPE can be helpful when
star.symbol
For 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 ch
center
Should the table be horizontally aligned at the center of the page?
column.spacing
The amount of space between any two columns of a table (only for the screenreg() function). 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.
caption.above
Should the caption of the table be placed above the table? By default, it is placed underneath the table.
bold
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% level to be formatted in bold. Note that this is not compatible with the
...
Custom options to be passed on to the extract function.

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.

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)
table.string <- texreg(list(model.1, model.2))
cat(table.string)

#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)
cat(table.string)

#Create a 'fake' Office document containing a regression table
table.string <- htmlreg(list(model.1, model.2), file="texreg.doc")
unlink("texreg.doc")

Run the code above in your browser using DataLab