tabmedians {tab} | R Documentation |
Create Table Comparing Group Medians
Description
Creates a table comparing the median of y
across levels of x
.
Usage
tabmedians(
formula = NULL,
data = NULL,
x = NULL,
y = NULL,
columns = c("xgroups", "p"),
parenth = "iqr",
sep.char = ", ",
xlevels = NULL,
yname = NULL,
text.label = NULL,
quantiles = NULL,
quantile.vals = FALSE,
decimals = NULL,
formatp.list = NULL,
n.headings = TRUE,
kable = TRUE
)
Arguments
formula |
Formula, e.g. |
data |
Data frame containing variables named in |
x |
Vector of values for the categorical |
y |
Vector of values for the continuous |
columns |
Character vector specifying what columns to include. Choices
for each element are |
parenth |
Character string specifying what values are shown in
parentheses after the medians in each cell. Choices are |
sep.char |
Character string with separator to place between lower and
upper bound of confidence intervals. Typically |
xlevels |
Character vector with labels for the levels of |
yname |
Character string with a label for the |
text.label |
Character string with text to put after the |
quantiles |
Numeric value. If specified, table compares |
quantile.vals |
Logical value for whether labels for |
decimals |
Numeric value specifying number of decimal places for numbers other than p-values. |
formatp.list |
List of arguments to pass to |
n.headings |
Logical value for whether to display group sample sizes in parentheses in column headings. |
kable |
Logical value for whether to return a
|
Details
If x
has 2 levels, a Mann-Whitney U (also known as Wilcoxon
rank-sum) test is used to test whether the distribution of y
differs
in the two groups; if x
has more than 2 levels, a Kruskal-Wallis test
is used to test whether the distribution of y
differs across at
least two of the groups. Observations with missing values for x
and/or
y
are dropped.
Value
Examples
# Compare median BMI in control group vs. treatment group in sample dataset
(medtable1 <- tabmedians(BMI ~ Group, data = tabdata))
# Compare median baseline systolic BP across tertiles of BMI
(medtable2 <- tabmedians(bp.1 ~ BMI, data = tabdata,
quantiles = 3, yname = "Systolic BP"))