regTable: Create a matrix of regression output from a list of...

regTableR Documentation

Create a matrix of regression output from a list of regression models.

Description

regTable() takes a list of regression objects, such as those created by lm(). It returns a matrix in which the columns are estimates and standard errors – two columns for each model. Together, the two columns that represent a regression are a column-pair or a column-tier.

Usage

regTable(
  objList,
  colNames = NULL,
  rowsToRemove = NULL,
  rowsToKeep = NULL,
  clusterVar = NULL
)

Arguments

objList

List of regression objects. This is the only required argument. regTable() has been tested with objects of classes ivreg, glm, lm, and plm, and with the objects produced by the estimatr package. It should work with other regression objects, too – that is, with any regression objects for which the coef() and vcov() functions can be used.

colNames

A vector of strings as long as length(objList).

rowsToRemove

A vector of strings, which may specify regular expressions. Variables in the regressions whose names match the strings will be omitted from the regTable output. This argument overrides rowsToKeep.

rowsToKeep

A vector of strings, which may specify regular expressions. Variables in the regressions whose names match the strings will be kept in the regTable output. All other variables will be omitted. If rowsToRemove is specified, this argument has no effect.

clusterVar

Either NULL, a list of length\NB1, or a list of length length(objList). If NULL (the default), regTable() will report the standard errors indicated by your regression objects. Otherwise, the argument to clusterVar should indicate the clusters for the corresponding regression objects in objList. Clustered SEs for "lm" objects will be produced by multiwayvcov::cluster.vcov, and clustered SEs for "ivreg" objects will be produced by ivpack::cluster.robust.se. regTable() does not support clustering for other kinds of regression objects.

Value

A matrix in which the columns are estimates and standard errors – two columns for each model. The matrix has an "N" attribute that indicates the number of observations for each regression. If all regressions were of class lm (but not also class glm), it also has the "r.squared" and "SER" attributes. (The "SER" attribute indicates the standard error of regression – AKA σ or the "residual standard error" — for each model.)

Subsetting regTable objects with the [ operator

You can take subsets of regTable objects with the [ operator. It subsets intelligently. That is, it knows whether the subsetted object contains only intact column tiers, and it modifies the class and attributes of the subsetted object accordingly. To wit:

  • If you remove only certain column-pairs from your original regTable object, such that the remaining columns all form intact column-pairs, all attributes for the remaining column-tiers are preserved. For example, the N and r.squared attributes are preserved. In other words, the [ operator knows which regressions you have removed from the table, and it removes attribute information for only those regressions.

  • If you remove only rows from your original regTable object, all attributes are preserved. This result has the potential to be misleading: for example, you may remove a row that reports information for a given predictor, but the N, r.squared, and SER attributes were all computed from regressions that included that predictor. Consequently, a message will be printed to remind you that the attributes have been preserved.

  • If you remove columns from your original regTable object such that the remaining columns do not all form intact column-pairs, the N, r.squared, and SER attributes are stripped, and the returned object is a matrix without the "regTable" class.

See the examples for an illustration.

Change from the pre-publication version

Before regTable() was incorporated into this package, it used the rowsToKeep argument differently: variables were kept only if the beginnings of their names matched the strings in rowsToKeep.

See Also

Other functions for making tables: \linkIntlatexTable, \linkIntlatexTablePDF. See also the Building better tables in less time vignette.

Examples

data(iris)
lm1 <- lm(Sepal.Length ~ Petal.Length,               data = iris)
lm2 <- lm(Sepal.Length ~ Petal.Length + Petal.Width, data = iris)
regTable(list(lm1, lm2))
regTable(list(lm1, lm2), colNames = c("Sepal length", "Sepal width"))
regTable(list(lm1, lm2), rowsToKeep = 'Length')
regTable(list(lm1, lm2), rowsToKeep = c('Intercept', 'Length'))
regTable(list(lm1, lm2), clusterVar = list(iris$Species))

# illustrate subsetting
rT <- regTable(list(lm1, lm2))
ncol(rT)           # 4
attributes(rT)$N   # 150 150
rT2 <- rT[1:2, ] 
attributes(rT2)$N  # 150 150
rT3 <- rT[, 3:4]
attributes(rT3)$N  # 150
rT4 <- rT[, 2:3]
attributes(rT4)$N  # NULL
class(rT4)         # "matrix"

jbullock35/Bullock documentation built on April 1, 2022, 6:21 p.m.