tab-package: Functions for Creating Summary Tables for Statistical Reports

Description Details Author(s) References See Also Examples

Description

Contains functions for generating tables for statistical reports written in Microsoft Word or LaTeX. There are functions for I-by-J frequency tables, comparison of means or medians across levels of a categorical variable, and summarizing fitted generalized linear models, generalized estimating equations, and Cox proportional hazards regression. Functions are available to handle data simple random samples or survey data. The package is intended to make it easier for researchers to translate results from statistical analyses in R to their reports or manuscripts.

Details

Package: tab
Type: Package
Version: 3.1.3
Date: 2017-09-14
License: GPL-2

The following functions are included:

tabfreq
tabmeans
tabmedians
tabmulti
tabglm
tabcox
tabgee
tabfreq.svy
tabmeans.svy
tabmedians.svy
tabmulti.svy
tabglm.svy
formatp

Author(s)

Dane R. Van Domelen

Maintainer: Dane R. Van Domelen <vandomed@gmail.com>

References

1. Therneau T (2013). A Package for Survival Analysis in S. R package version 2.37-4, https://cran.r-project.org/package=survival.

2. Terry M. Therneau and Patricia M. Grambsch (2000). Modeling Survival Data: Extending the Cox Model. Springer, New York. ISBN 0-387-98784-3.

3. Dahl DB (2013). xtable: Export tables to LaTeX or HTML. R package version 1.7-1, https://cran.r-project.org/package=xtable.

4. Kevin Ushey (2013). Kmisc: Kevin Miscellaneous. R package version 0.5.0. https://CRAN.R-project.org/package=Kmisc.

Acknowledgment: This material is based upon work supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE-0940903.

See Also

NA

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
# Load in sample dataset d and drop rows with missing values
data(d)
d <- d[complete.cases(d), ]

# Compare race distribution by group, with group as column variable
freqtable <- tabfreq(x = d$Group, y = d$Race)

# Compare mean BMI in control group vs. treatment group
meanstable <- tabmeans(x = d$Group, y = d$BMI)

# Generate plot comparing mean BMI in control group vs. treatment group
meansfig <- tabmeans(x = d$Group, y = d$BMI, fig = TRUE)

# Compare median BMI in control group vs. treatment group
medianstable <- tabmedians(x = d$Group, y = d$BMI)

# Create a typical Table 1 for statistical report or manuscript
table1 <- tabmulti(dataset = d, xvarname = "Group",
                   yvarnames = c("Age", "Sex", "Race", "BMI"))

# Create vector of race labels for use in regression tables
races <- c("White", "Black", "Mexican American", "other")

# Test whether age, sex, race, and treatment group are associated with BMI
glmfit1 <- glm(BMI ~ Age + Sex + Race + Group, data = d)
lintable <- tabglm(glmfit = glmfit1,
                   xlabels = c("Intercept", "Age", "Male", "Race", races,
                               "Treatment"))

# Test whether age, sex, race, and treatment group are associated with 1-year
# mortality
glmfit2 <- glm(death_1yr ~ Age + Sex + Race + Group, data = d,
               family = binomial)
logtable <- tabglm(glmfit = glmfit2, ci.beta = FALSE,
                   xlabels = c("Intercept", "Age", "Male", "Race", races,
                               "Treatment"))

# Test whether age, sex, race, and treatment group are associated with survival
coxtable <- tabcox(x = d[,c("Age", "Sex", "Race", "Group")], time = d$time,
                   delta = d$delta,
                   xlabels = c("Age", "Male", "Race", races, "Treatment"))

# To move freqtable into Word, run write.cb(freqtable) to copy the table onto
# your clipboard. Paste into Word, highlight the table and go to Insert - Table
# - Convert Text to Table... OK. Alternatively, if you set print.html to TRUE,
# the function will write a html file named html.filename to your current
# working directory. You can open this file, copy the table, and paste it into
# Word.

# If you wish to use LaTeX, R Markdown, knitr, Sweave, etc., set the latex input
# to TRUE and then use the xtable package [3]. You may have to set
# sanitize.text.function = identity when calling print.xtable.

Example output

Pearson's chi-square test was used to test whether the distribution of Race differed across groups.
Unequal variance t-test was used to compare mean BMI in the two groups.
Unequal variance t-test was used to compare mean BMI in the two groups.
Unequal variance t-test was used to compare mean Age in the two groups.
Pearson's chi-square test was used to test whether the distribution of Sex differed across groups.
Pearson's chi-square test was used to test whether the distribution of Race differed across groups.
Unequal variance t-test was used to compare mean BMI in the two groups.

tab documentation built on May 2, 2019, 6:50 p.m.