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 = list(model.1, model.2, ...)
. Different object types can also be mixed.htmlreg
function, an HTML table can be written to a file with the extension .doc
and opened with MS Word. The table can then be simply copied into any Word document, retaining the formatting of the table. Note that LibreOffice can import only plain HTML; CSS decorations are not supported; the resulting tables do not retain the full formatting in LibreOffice.single.row = TRUE
is activated, however, both coefficient and standard error are placed in a single table cell in the same line.stars = numeric(0)
will not print any stars and will not print any note about significance levels below the table. stars = 0.05
will attach one single star to all coefficients where the p value is below 0.05. stars = c(0.001, 0.01, 0.05, 0.1)
will print one, two, or three stars, or a symbol as specified by the symbol
argument depending on the p values.model.names = c("My name 1", "My name 2")
etc. overrides the default behavior.custom.coef.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 different coefficients (including the intercept), the argument custom.coef.names = c("Intercept", "variable 1", "variable 2")
will replace their names in this order.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 NA
value, the original name of the coefficient is kept. For example, custom.coef.names = c(NA, "age", NA)
will only replace the second coef name and leave the first and third name as they are in the original model.
custom.coef.names
argument, but for the GOF values. NA
values can be included where the original GOF name should be kept.custom.note = ""
), the note will be omitted completely. If some character string is provided (e.g., custom.note = "My note"
), the significance legend is replaced by My note
. The original significance legend can be included by inserting the %stars
wildcard. For example, a custom note can be added right after the significance legend by providing custom.note = "%stars. My note"
.digits
argument in the round
function of the base package.0.35
). This is also the default texreg behavior. Some journals, however, require omission of leading zeros (for example, .35
). This can be achieved by setting leading.zero = FALSE
.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 the LaTeX dot, "·"
for the HTML dot, or simply "."
for the ASCII dot. If the texreg
function is used, any other mathematical LaTeX symbol or plain text symbol can be used, for example symbol = "\\circ"
for a small circle (note that backslashes must be escaped). If the htmlreg
function is used, any other HTML character or symbol can be used. For the screenreg
function, only plain text characters can be used.override.coef = list(c(0.1, 0.2, 0.3), c(0.05, 0.06, 0.07))
. If there is only one model, custom values can be provided as a plain vector (not embedded in a list). For example: override.coef = c(0.05, 0.06, 0.07)
.override.se = list(c(0.1, 0.2, 0.3), c(0.05, 0.06, 0.07))
. If there is only one model, custom values can be provided as a plain vector (not embedded in a list). For example: override.se = c(0.05, 0.06, 0.07)
. Overriding standard errors can be useful for the implementation of robust SEs, for example.override.pvalues = list(c(0.1, 0.2, 0.3), c(0.05, 0.06, 0.07))
. If there is only one model, custom values can be provided as a plain vector (not embedded in a list). For example: override.pvalues = c(0.05, 0.06, 0.07)
. Overriding p values can be useful for the implementation of robust SEs and p values, for example.override.ci.up
argument, the standard errors and p values as well as the ci.force
argument are ignored.override.ci.low
argument, the standard errors and p values as well as the ci.force
argument are ignored.omit.coef = "group"
deletes all coefficient rows from the table where the name of the coefficient contains the character sequence "group". More complex regular expressions can be used to filter out several kinds of model terms, for example omit.coef = "(thresh)|(ranef)"
to remove all model terms matching either "thresh" or "ranef".The omit.coef
argument is processed after the custom.coef.names
argument, so the regular expression should refer to the custom coefficient names. To omit GOF entries instead of coefficient entries, use the custom arguments of the extract functions instead (see the help entry of the extract function or extract-methods.reorder.coef = c(3, 2, 1)
will put the third coefficient in the first row and the first coefficient in the third row. Reordering can be sensible because interaction effects are often added to the end of the model output although they were specified earlier in the model formula. Note: Reordering takes place after processing custom coefficient names and after omitting coefficients, so the custom.coef.names
and omit.coef
arguments should follow the original order.reorder.gof = c(3, 2, 1)
will exchange the first and the third row. Note: Reordering takes place after processing custom GOF names, so the custom.gof.names
argument should follow the original order.ci.force
argument accepts either a logical value indicating whether all models or none of the models should be forced to report confidence intervals (ci.force = TRUE
for all and ci.force = FALSE
for none) or a vector of logical values indicating for each model separately whether the model should be forced to report confidence intervals (e.g., ci.force = c(FALSE, TRUE, FALSE)
). Confidence intervals are computed using the standard normal distribution (z values based on the qnorm
function).ci.force
argument is used to convert standard errors to confidence intervals, what confidence level should be used? By default, 0.95
is used (i.e., an alpha value of 0.05).ci.test
argument specifies the reference value to establish whether a coefficient/CI is significant. The default value ci.test = 0
, for example, will attach a significance star to coefficients if the confidence interval does not contain 0
. If no star should be printed at all, ci.test = NULL
can be used. The ci.test
argument works both for models with native support for confidence intervals and in cases where the ci.force
argument is used.groups = list("first group" = 1:4, "second group" = 7:8)
.custom.columns = list(type = c("a", "b", "c"), 1:3)
will add two columns; the first one is labeled while the second one is not. Note that the numeric elements of the second column will be converted to character objects in this example. The consequence is that decimal alignment with the dcolumn package is switched off in these columns. Note that this argument is processed after any arguments that affect the number of rows.custom columns
argument. For example, if there are three custom columns, custom.col.pos = c(1, 3, 3)
will insert the first custom column before the first column of the original table and the remaining two custom columns after the second column of the original table. By default, all custom columns are placed after the first column, which usually contains the coefficient names.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% level to be formatted in bold. Note that this is not compatible with the dcolumn argument in the texreg
function. If both are TRUE
, dcolumn is switched off and a warning message appears. Note also that it is advisable to use stars = FALSE
together with the bold
argument because having both bolded coefficients and significance stars usually does not make any sense.texreg
and htmlreg
functions] Should the table be horizontally aligned at the center of the page?texreg
and htmlreg
functions] Set the caption of the table. texreg
and htmlreg
functions] Should the caption of the table be placed above the table? By default, it is placed below the table.texreg
function] Set the label of the table
environment.texreg
function] Use the booktabs
LaTeX package to get thick horizontal rules in the output table (recommended).texreg
function] Use the dcolumn
LaTeX package to get a nice alignment of the coefficients (recommended).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 only has an effect if table = TRUE
is also set.texreg
function] If longtable = TRUE
is set, the longtable
environment from the longtable
LaTeX package is used to set tables across multiple pages. Note that this argument is not compatible with the sideways
and scalebox
arguments. These arguments will be automatically switched off when longtable = TRUE
is set. 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.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
.texreg
function] In order to save space, inner margins of tables can be switched off.texreg
function] The fontsize
argument serves to change the font size used in the table. Valid values are "tiny"
, "scriptsize"
, "footnotesize"
, "small"
, "normalsize"
, "large"
, "Large"
, "LARGE"
, "huge"
, and "Huge"
. Note that the scalebox
argument often achieves better results when the goal is to change the size of the table. texreg
function] The scalebox
argument serves to resize the table. For example, scalebox = 1.0
is equivalent to the normal size, scalebox = 0.5
decreases the size of the table by one half, and scalebox = 2.0
doubles the space occupied by the table. Note that the scalebox
argument does not work when the longtable
argument is used. 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 h
(here), p
(page), t
(top), b
(bottom), any combination thereof, e.g. tb
, or any of these values followed by an exclamation mark, e.g. t!
, in order to enforce this position. The square brackets do not have to be specified.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 characters, so they have to be escaped. To make htmlreg
compatible with Markdown, specify star.symbol = "\*"
. Note that some other modifications are recommended for usage with knitr in combination with Markdown or HTML (see the inline.css
, doctype
, html.tag
, head.tag
, and body.tag
arguments).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 (inline.css = FALSE
)? Having inline CSS code makes the code of the table more complex, but sometimes it may be helpful when only the table shall be printed, without the head of the HTML file (for example when the table is embedded in a knitr report). As a rule of thumb: use inline CSS if the table is not saved to a file.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 be helpful when the knitr package is used to generate HTML code because knitr requires only the plain table, not the whole HTML document including the document type declaration. Including the DOCTYPE can be helpful when the code is saved to a file, for example as an MS Word document.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. Including this tag is recommended when the code is saved to a file, for example as an MS Word document.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. Including this tag is recommended when the code is saved to a file, for example as an MS Word document.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 the code is saved to a file, for example as an MS Word document.htmlreg
function] Characters used for indentation of the HTML code. By default, indentation = ""
uses no indentation. Any number of spaces or characters can be used instead. For example, indentation = " "
uses two spaces of (additional) indentation for each subelement.htmlreg
function] Vertical alignment of significance stars. Browsers differ in their ways of displaying superscripted significance stars; in some browsers the stars are elevated by default, and in other browsers the stars are aligned vertically with the text, without any actual superscripting. This argument controls by how many additional pixels the stars are elevated. The default setting of 0 uses the defaults of the browser. In RStudio's internal browser, this looks OK, but in Firefox, this looks too low. A value of 4 looks OK in Firefox, for example, but is above the line in RStudio's internal browser. 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
.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. Recommended values are ""
, "="
, "-"
, "_"
, or "#"
.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. Recommended values are ""
, "-"
, or "_"
.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.
texreg-package extract extract-methods plotreg
#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 DataCamp Workspace