reg.table: Create Regression Tables in LaTeX or HTML

View source: R/reg.table.R

reg.tableR Documentation

Create Regression Tables in LaTeX or HTML

Description

reg.table generates formatted regression tables in either LaTeX or HTML format for one or more linear regression models. The tables include coefficient estimates, standard errors, and various model statistics.

Usage

reg.table(models, type = c("latex", "html"), split.size = 4L, n.digits = 3L,
          big.mark = "", caption = "Regression Results", spacing = 5L,
          stats = c("AIC", "BIC", "CV", "r.squared", "adj.r.squared",
                    "fstatistic", "nobs"),
          ...)

Arguments

models

A list of linear regression models (objects of class lm or glm with gaussian family and identity link function).

type

A string specifying the output format. Must be one of "latex" or "html".

split.size

An integer specifying the number of models per table. Tables with more models than this number will be split.

n.digits

An integer specifying the number of decimal places for numerical values.

big.mark

A string to use for thousands separators in numeric formatting.

caption

A string for the table caption.

spacing

A numeric specifying the spacing between columns in the output table.

stats

A character vector specifying which model statistics to include in the table. Options include:

AIC

Akaike Information Criterion

BIC

Bayesian Information Criterion

CV

Cross-validation score

r.squared

R-squared

adj.r.squared

Adjusted R-squared

fstatistic

F-statistic

nobs

Number of observations

...

Additional arguments passed to cvLM.

Details

The function generates tables summarizing linear regression models, either in LaTeX or HTML format. The tables include coefficients, standard errors, and optional statistics such as AIC, BIC, cross-validation scores, and more. The output is formatted based on the specified type and options. The names of the models list will be used as column headers if provided.

Value

A character vector of length equal to the number of tables with each element containing the LaTeX or HTML code for a regression table.

Examples

data(mtcars)

# Create a list of 6 different linear regression models with names
# Names get used for column names of the table
models <- list(
  `Model 1` = lm(mpg ~ wt + hp, data = mtcars),
  `Model 2` = lm(mpg ~ wt + qsec, data = mtcars),
  `Model 3` = lm(mpg ~ wt + hp + qsec, data = mtcars),
  `Model 4` = lm(mpg ~ wt + cyl, data = mtcars),
  `Model 5` = lm(mpg ~ wt + hp + cyl, data = mtcars),
  `Model 6` = lm(mpg ~ hp + qsec + drat, data = mtcars)
)

# Example usage for LaTeX
reg.table(
  models,
  "latex",
  split.size = 3L,
  n.digits = 3L,
  big.mark = ",",
  caption = "My regression results",
  spacing = 7.5,
  stats = c("AIC", "BIC", "CV"),
  data = mtcars,
  K.vals = 5L,
  seed = 123L
)

# Example usage for HTML
reg.table(
  models,
  "html",
  split.size = 3L,
  n.digits = 3L,
  big.mark = ",",
  caption = "My regression results",
  spacing = 7.5,
  stats = c("AIC", "BIC", "CV"),
  data = mtcars,
  K.vals = 5L,
  seed = 123L
)

cvLM documentation built on Sept. 11, 2024, 5:28 p.m.