tableRegression: Format Coefficient Tables of Regression Models

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Shows regression output in a desired way.

Usage

1
2
3
4
5
tableRegression(model,
    stats = NULL, col.nam = NULL, row.nam = NULL, intercept = NULL,
    text = "english", text.ci = text, 
    eps.pvalue = 0.0001, digits = NULL, big.mark = "'",
    xtable = TRUE, align = NULL, caption = NULL, label = NULL, ...)

Arguments

model

an object of class "lm", "glm", "negbin" (fitted by glm.nb in package MASS), "coxph", or "list" (for Weibull models).

stats

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

col.nam

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

row.nam

Names of rows, character vector

intercept

logical, should intercept be provided or not. If model is a binomial regression, intercept is set FALSE. If intercept is set TRUE, the first line of the summary output is removed (intercepts are not available for weibull or cox models, because they do not provide any intercept value).

text

Character, german or english, used e.g. for naming the intercept.

text.ci

Character, german or english or none, referring to the language used for the confidence interval, see displayCI.

eps.pvalue

p-values smaller than eps.pvalue will be formatted as '< eps.pvalue'.

digits

Vector of length stats, digits used for each column.

big.mark

Character vector, see format.

xtable

Logical indicating if a LaTeX table should be produced (default) or just a data frame be returned.

align,caption,label

see xtable.

...

Arguments passed to print.xtable.

Details

In stats:

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

xtable

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
## Linear model
## ---------------
mod.lm <- lm(Sepal.Length ~ Sepal.Width, data = iris)
mod.lm1 <- lm(Sepal.Length ~ .^2, data = iris) 

## using default style
tableRegression(mod.lm)

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

## adapt row names, plus special format for ci
tableRegression(mod.lm, row.nam = 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(mod.glm.pois)


## Negative binomial model
## --------------
if (require("MASS")) {
    mod.glm.nb <- glm.nb(Days ~ Sex + Age, data = quine)
    tableRegression(
        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(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(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)) 

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

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


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

biostatUZH documentation built on May 2, 2019, 6:06 p.m.