Learn R Programming

netCoin (version 2.1.49)

coefTable: Coefficient Table from Regression Graphs

Description

Builds a side-by-side coefficient table from one or several objects returned by glmCoin. It reads the coeffs list stored in them (one data frame of coefficients per equation) and the equations data frame (n and pseudo-R2 of each model). Note that it does not read links, which holds average marginal effects rather than coefficients: that is what marginsTable tabulates. Each column block corresponds to one combination of object, equation and Target, so the same function covers hierarchical regressions (one response, nested sets of predictors), several responses in a single object, multinomial responses (one block per category) and any combination of these.

Usage

coefTable(G, labels = NULL, columns = c("coef", "sig", "se"),
          stfactors = c("nostandard", "x", "long"),
          blocks = c("entry", "variable", "none"), intercept = FALSE,
          sig = c(0.05, 0.01, 0.001), digits = 3, digits.se = digits,
          footer = c("n_obs", "r2", "dr2"), note = FALSE,
          file = NULL, format = NULL)

Value

A character matrix of class coefTable, printed with grouped headers (one block of columns per model, response or category). The bottom rows show the statistics selected in footer. When exporting, the table is returned invisibly.

Arguments

G

A netCoin object created by glmCoin, or a list of them. A named list uses its names as column labels. Objects built with earlier versions have no coeffs and must be rebuilt.

labels

Optional character vector of column-block labels, one per model/target combination. If missing, labels are built automatically from the components that actually vary (model, response and, for multinomial responses, category), so that no redundant text is shown.

columns

Which columns form the block repeated for each model, shown in the order given: "coef" (estimate), "se" (standard error in parentheses), "sig" (significance stars), "sta" (standardized coefficient, see stfactors), "exp" (exponentiated coefficient), "ci" (confidence interval) and "p" (p value). At least one is required. The "exp" column is only filled for equations whose link is log (rate ratios) or logit (odds ratios); it is deliberately left empty for other links, so that a probit coefficient is never exponentiated.

stfactors

Convention used to standardize the coefficients shown in the "sta" column. In every case the estimate is multiplied by the weighted standard deviation of its term and divided by the scale of the response: sd(y) when the response is on its own scale (gaussian models), sd(y*) of the underlying latent variable when stfactors="long" and the link is logit or probit (Long's convention), and 1 otherwise. The three values differ in the treatment of qualitative terms: "nostandard" (default) leaves the dummies in their original metric, so their coefficient keeps reading as the effect of belonging to the category; "x" standardizes them as well, by the standard deviation of the dummy; and "long" standardizes them and divides by the latent scale.

blocks

How predictor rows are grouped. "entry" (default) groups them by the equation in which each predictor first appears, which reproduces the theoretical blocks of a hierarchical regression; "variable" groups the categories of each explanatory variable, whose name heads the block; "none" shows a flat list. A named list of predictor names may also be given to define the groups explicitly.

intercept

If TRUE, the constant of each equation is shown in a last row, after the predictor blocks. It is FALSE by default because the constant does not belong to any of them.

sig

Numeric vector with the significance thresholds of the stars, sorted internally in decreasing order: one star for p below the largest threshold, two for the next, and so on (any number of thresholds is allowed, e.g. sig=c(.1,.05,.01,.001) for a four-star scale).

digits

Number of decimals for the coefficients.

digits.se

Number of decimals for standard errors and confidence limits. Defaults to digits.

footer

Character vector with the statistics to show as bottom rows. Besides any column of G$equations (n, n_obs, r2, r2.mcfadden, r2.nagelkerke, logLik, aic, bic, deviance, null.deviance, df.residual), three are computed here: k (number of predictors), dr2 (increment in R2 over the reference model) and ref (the reference model itself). The reference is found automatically as the largest model strictly nested in each equation and fitted on the same response. Categories of a multinomial response share a single equation, so its statistics are shown once, under the first of its blocks. Use NULL to omit the footer.

note

If TRUE, a legend with the meaning of the stars (built from sig) and of the standardization in use is added below the table, both when printing and in the exported formats.

file

Optional file name to export the table. The format is inferred from the extension (.txt, .tex or .csv) unless format is given.

format

Export format: "text", "latex" or "csv" (the latter opens directly in Excel). If file is missing, a default name is used.

Author

Modesto Escobar, Department of Sociology and Communication, University of Salamanca.

Details

Rows are the union of the predictors of all the equations, in order of first appearance; an empty cell means that the predictor was not included in that equation, which is not the same as a zero coefficient.

Because coeffs and equations keep the same order, the columns are matched to their fit statistics by position, without comparing model strings.

Because R2 and its increments are only comparable when the equations are fitted on the same cases, a warning is issued whenever the models differ in their number of observations, and the fact is recorded in the note when note=TRUE. This typically happens when a predictor added in a later step has missing values.

See Also

glmCoin, marginsTable

Examples

Run this code
data(birthwt, package="MASS")
birthwt$smoke <- factor(birthwt$smoke, labels=c("no","yes"))
birthwt$race  <- factor(birthwt$race,  labels=c("white","black","other"))

## Hierarchical regression: one response, nested sets of predictors.
## Blocks are deduced from the equation in which each predictor enters.
m1 <- glmCoin("bwt ~ age + lwt", birthwt)
m2 <- glmCoin("bwt ~ age + lwt + smoke", birthwt)
m3 <- glmCoin("bwt ~ age + lwt + smoke + race", birthwt)
coefTable(list(m1, m2, m3), note=TRUE)

## Standardized coefficients: quantitative terms only, then all of them
coefTable(m3, columns=c("coef","sta"))
coefTable(m3, columns=c("coef","sta"), stfactors="x")

## Confidence intervals instead of standard errors, with fewer decimals
coefTable(list(m1, m2, m3), columns=c("coef","sig","ci"), digits=2, digits.se=1)

## Logistic regression: odds ratios beside the coefficients
g <- glmCoin(c("bwt ~ age + lwt", "low ~ age + lwt, binomial"), birthwt)
coefTable(g, columns=c("coef","sig","exp"), footer=c("n_obs","r2"))

## Multinomial response: one block of columns per category
data(housing, package="MASS")
h <- glmCoin("Sat ~ Infl + Type + Cont, multinomial", housing, weights="Freq")
coefTable(h, blocks="variable", columns=c("coef","sig"))

Run the code above in your browser using DataLab