Learn R Programming

tab (version 2.1.3)

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

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.

Arguments

Details

ll{ Package: tab Type: Package Version: 2.1.3 Date: 2014-09-16 License: GPL-2 } The following functions are included in the package: tabfreq, tabmeans, tabmedians, tabmulti, tabglm, tabcox, tabgee, tabfreq.svy, tabmeans.svy, tabglm.svy, formatp

References

1. Therneau T (2013). A Package for Survival Analysis in S. R package version 2.37-4, http://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, http://CRAN.R-project.org/package=xtable. 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

Run this code
# Load in sample dataset d and drop rows with missing values
data(d)
d <- d[complete.cases(d), ]

# Create labels for treatment group, sex, and race
groups <- c("Control", "Treatment")
sexes <- c("Female", "Male")
races <- c("White", "Black", "Mexican American", "Other")

# Compare race distribution by group, with group as column variable
freqtable <- tabfreq(x = d$group, y = d$race, xlevels = groups, 
                     ylevels = races, yname = "Race")

# Compare mean BMI in control group vs. treatment group
meanstable <- tabmeans(x = d$group, y = d$bmi, xlevels = groups, yname = "BMI")

# Compare median BMI in control group vs. treatment group
medianstable <- tabmedians(x = d$group, y = d$bmi, xlevels = groups, yname = "BMI")

# Create a typical Table 1 for statistical report or manuscript
table1 <- tabmulti(dataset = d, xvarname = "group",
                   yvarnames = c("age", "sex", "race", "bmi"), xlevels = groups,
                   ynames = c("Age", "Sex", "Race", "BMI"), ylevels = list(sexes, races))

# 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"))

# Click on freqtable, meanstable, table1, lintable, logtable, and coxtable in 
# the Workspace tab of RStudio to see the tables that could be copied and pasted 
# into a Word document. Alternatively, setting the latex input to TRUE produces
# tables that can be inserted into LaTeX using the xtable package.

Run the code above in your browser using DataLab