tableRegression: Format coefficient tables of regression models

View source: R/tableRegression.R

tableRegressionR Documentation

Format coefficient tables of regression models

Description

Formats output from the regression model functions: lm, glm, glm.nb, coxph, and Weibull.

Usage

tableRegression(
  model,
  stats = NULL,
  col.names = NULL,
  row.names = NULL,
  intercept = NULL,
  text = c("english", "german"),
  text.ci = text,
  eps.pvalue = 1e-04,
  digits = NULL,
  strict = FALSE,
  big.mark = "'",
  xtable = TRUE,
  align = NULL,
  caption = NULL,
  label = NULL,
  vars = NULL,
  ...
)

Arguments

model

Object of class lm, glm, negbin (obtained by glm.nb), coxph (obtained by coxph), and list obtained by Weibull.

stats

character vector with stats chosen from "estimate", "exp.estimate", "standarderror", "t.value", "ci.95", and "p.value".

col.names

Character vector of same length and order as in stats. A percentage sign must be escaped by two backslashes.

row.names

Character vector of row names.

intercept

Logical vector of length one indicating whether to provide an intercept or not. If intercept is set TRUE, the first line of the summary output is removed. If the model is a binomial regression, intercept is set FALSE. Intercepts are not available for Weibull or Cox models, because they do not provide any intercept value.

text

Either "english" (default) or "german" indicating the used language names.

text.ci

Either "english", "german" or "none". The language used to denote confidence interval, see formatCI.

eps.pvalue

If strict = FALSE, p-values smaller than eps.pvalue will be formatted as "< eps.pvalue". Otherwise this argument is ignored.

digits

Vector of length stats, digits used for each column.

strict

Either TRUE or FALSE (default). If FALSE, p-values are formatted with formatPval. Otherwise formatPvalStrict is used to format p-values. This argument is thus only relevant when the argument stats is either NULL or contains "p.value".

big.mark

Character vector as in format.

xtable

If TRUE, a Latex table is returned, otherwise a data.frame is returned.

align

See xtable.

caption

See xtable.

label

See xtable.

vars

Specify the variables for which regression summaries should be printed. The argument vars takes a string vector with the names of the coefficients in the model.

...

Arguments passed to print.xtable.

Details

In stats:

  • If t.value is chosen, the z.value might be taken, depending on the model.

  • For lm-models: ci.95 calculates a confidence interval for the estimate.

  • For glm- and coxph-models: ci.95 calculates a confidence interval for the exp(estimate).

Value

Depending on the value of the xtable argument, the function either prints and returns LaTeX code representing the produced table of coefficients, or it returns the corresponding data frame.

Author(s)

Sina Rueeger with contributions by Sebastian Meyer.

See Also

tableOR, xtable, lm, glm, glm.nb coxph, Weibull.

Examples


## Linear model
## ---------------
mod.lm <- lm(Sepal.Length ~ Sepal.Width, data = iris)
mod.lm1 <- lm(Sepal.Length ~ .^2, data = iris) 

tableRegression(model = mod.lm)

## strict argument is used to force p-values to have a certain number
## of digits (here 4).
tableRegression(model = mod.lm, digits = c(2, 2, 4), strict = TRUE)
tableRegression(model = mod.lm, digits = c(2, 2, 4), strict = FALSE)

## choosing columns, columns and row naming in german
tableRegression(model = mod.lm1, stats = c("estimate", "t.value", "p.value"),
                text = "german")

## adapt row names, plus special format for ci
tableRegression(model = mod.lm, row.names = c("Intercept", "Width Sepal"),
                text.ci = "none")

## Poisson model
## (example from ?glm)
## --------------
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
d.AD <- data.frame(treatment, outcome, counts)
mod.glm.pois <- glm(counts ~ outcome + treatment, family=poisson())
tableRegression(model = mod.glm.pois)


## Negative binomial model
## --------------
mod.glm.nb <- glm.nb(Days ~ Sex + Age, data = quine)
tableRegression(model = mod.glm.nb,
    caption = paste("NegBin model. Estimated dispersion:",
        sprintf("%4.2f ($se=%4.2f$).", mod.glm.nb$theta, mod.glm.nb$SE.theta)),
    label = "tab:glm.nb")



## Logistic model
## -------------
dat <- survival::rats
dat$rx <- factor(dat$rx, labels = c(" (A)", " (B)"))
mod.glm.bin <- glm(status ~ litter + rx, family = binomial, data = dat)

tableRegression(model = mod.glm.bin,
                stats = c("estimate", "exp.estimate", "ci.95", "t.value", "p.value"),
                text = "english", digits = rep(3, 5),
                caption = "Here goes the caption.", label = "mod:logit")

## including intercept
tableRegression(model = mod.glm.bin,
                stats = c("estimate", "exp.estimate", "ci.95", "t.value", "p.value"),
                text = "english", digits = rep(3, 5),
                caption = "Here goes the caption.", label = "mod:logit",
                intercept = TRUE)


## Cox model
## (example from ?survival::coxph)
## -------------
dat <- list(time = c(4, 3, 1, 1, 2, 2, 3), 
            status = c(1, 1, 1, 0, 1, 1, 0), 
            x = c(0, 2, 1, 1, 1, 0, 0), 
            sex = c(0, 0, 0, 0, 1, 1, 1)) 

mod.cox <- coxph(Surv(time, status) ~ x, data = dat)
mod.cox1 <- coxph(Surv(time, status) ~ x + factor(sex), data = dat)
mod.cox2 <- coxph(Surv(time, status) ~ x + strata(sex), data = dat)

tableRegression(model = mod.cox)
tableRegression(model = mod.cox1)
tableRegression(model = mod.cox2)


## Weibull
## (example from WeibullReg)
## -------------
data("larynx")
mod.wb <- weibullReg(Surv(time, death) ~ factor(stage) + age,
                     data = larynx)
tableRegression(model = mod.wb)


felix-hof/biostatUZH documentation built on Sept. 27, 2024, 1:48 p.m.