# Load in sample dataset d
data(d)
# Create labels for group and race
groups <- c("Control", "Treatment")
sexes <- c("Female", "Male")
races <- c("White", "Black", "Mexican American", "Other")
# Compare age, sex, race, and BMI in control vs. treatment group, using all available
# data for each comparison
table1 <- tabmulti(dataset = d, xvarname = "group",
yvarnames = c("age", "sex", "race", "bmi"), xlevels = groups,
ynames = c("Age", "Sex", "Race", "BMI"), ylevels = list(sexes, races),
n = TRUE)
# Repeat, but use listwise deletion, i.e. drop observations that do not have complete
# data for all variables of interest, and suppress sample size column
table2 <- tabmulti(dataset = d, xvarname = "group",
yvarnames = c("age", "sex", "race", "bmi"), listwise.deletion = TRUE,
xlevels = groups, ynames = c("Age", "Sex", "Race", "BMI"),
ylevels = list(sexes, races))
# Repeat, but compare medians rather than means for BMI
table3 <- tabmulti(dataset = d, xvarname = "group",
yvarnames = c("age", "sex", "race", "bmi"),
ymeasures = c("mean", "freq", "freq", "median"),
listwise.deletion = TRUE, xlevels = groups,
ynames = c("Age", "Sex", "Race", "BMI"), ylevels = list(sexes, races))
# Click on table1, table2, or table3 in the Workspace tab of RStudio to see the tables
# that could be copied and pasted into a report or manuscript. 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