Creates an I-by-J frequency table comparing the distribution of y
across levels of x.
tabfreq(
formula = NULL,
data = NULL,
x = NULL,
y = NULL,
columns = c("xgroups", "p"),
cell = "counts",
parenth = "col.percent",
sep.char = ", ",
test = "chi.fisher",
xlevels = NULL,
yname = NULL,
ylevels = NULL,
compress.binary = FALSE,
yname.row = TRUE,
text.label = NULL,
quantiles = NULL,
quantile.vals = FALSE,
decimals = 1,
formatp.list = NULL,
n.headings = FALSE,
kable = TRUE
)Formula, e.g. Sex ~ Group.
Data frame containing variables named in formula.
Vector indicating group membership for columns of I-by-J table.
Vector indicating group membership for rows of I-by-J table.
Character vector specifying what columns to include. Choices
for each element are "n" for total sample size, "overall" for
overall distribution of y, "xgroups" for distributions of
y for each x group, "test" for test statistic, and
"p" for p-value.
Character string specifying what statistic to display in cells.
Choices are "counts", "tot.percent", "col.percent",
and "row.percent".
Character string specifying what statistic to display in
parentheses. Choices are "none", "se", "ci",
"counts", "tot.percent", "col.percent", and
"row.percent".
Character string with separator to place between lower and
upper bound of confidence intervals. Typically "-" or ", ".
Character string specifying which test for association between
x and y should be used. Choices are "chi.fisher" for
Pearson's chi-squared test if its assumptions are met, otherwise Fisher's
exact test; "chi"; "fisher"; "z" for z test without
continuity correction; and "z.continuity" for z test with continuity
correction. The last two only work if both x and y are binary.
Character vector with labels for the levels of x, used
in column headings.
Character string with a label for the y variable.
Character vector with labels for the levels of y. Note
that levels of y are listed in the order that they appear when you run
table(y, x).
Logical value for whether to compress binary y
variable to a single row, excluding the first level rather than showing both.
Logical value for whether to include a row displaying the
name of the y variable and indent the factor levels.
Character string with text to put after the y
variable name, identifying what cell values and parentheses represent.
Numeric value. If specified, table compares y across
quantiles of x created on the fly.
Logical value for whether labels for x quantiles
should show quantile number and corresponding range, e.g. Q1 [0.00, 0.25),
rather than just the quantile number.
Numeric value specifying number of decimal places for numbers other than p-values.
List of arguments to pass to formatp.
Logical value for whether to display group sample sizes in parentheses in column headings.
Logical value for whether to return a
kable.
# NOT RUN {
# Compare sex distribution by group
(freqtable1 <- tabfreq(Sex ~ Group, data = tabdata))
# Same as previous, but showing male row only and % (SE) rather than n (%)
(freqtable2 <- tabfreq(Sex ~ Group, data = tabdata,
cell = "col.percent", parenth = "se",
compress.binary = TRUE))
# }
Run the code above in your browser using DataLab