tabmedians: Create Table Comparing Group Medians

Description Usage Arguments Details Value Examples

View source: R/archived/tabmedians-2020-03-28.R View source: R/tabmedians.R

Description

Creates a table comparing the median of y across levels of x.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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. BMI ~ Group.

data

Data frame containing variables named in formula.

x

Vector of values for the categorical x variable.

y

Vector of values for the continuous y variable.

columns

Character vector specifying what columns to include. Choices for each element are "n" for total sample size, "overall" for overall median, "xgroups" for x group medians, "diff" for difference in x group medians (only available for binary x), "test" for test statistic, and "p" for p-value.

parenth

Character string specifying what values are shown in parentheses after the medians in each cell. Choices are "none", "iqr", "q1q3" for first and third quartiles, "range", "minmax", and "ci" for 95% confidence interval for the medians based on normal approximation to binomial.

sep.char

Character string with separator to place between lower and upper bound of confidence intervals. Typically "-" or ", ".

xlevels

Character vector with labels for the levels of x, used in column headings.

yname

Character string with a label for the y variable.

text.label

Character string with text to put after the y variable name, identifying what cell values and parentheses represent.

quantiles

Numeric value. If specified, table compares y across quantiles of x created on the fly.

quantile.vals

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.

decimals

Numeric value specifying number of decimal places for numbers other than p-values.

formatp.list

List of arguments to pass to formatp.

n.headings

Logical value for whether to display group sample sizes in parentheses in column headings.

kable

Logical value for whether to return a kable.

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

kable.

Examples

1
2
3
4
5
6
# 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"))

tab documentation built on Aug. 2, 2021, 9:06 a.m.