tabmeans: Create Table Comparing Group Means

Description Usage Arguments Details Value Examples

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

Description

Creates a table comparing the mean 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
19
tabmeans(
  formula = NULL,
  data = NULL,
  x = NULL,
  y = NULL,
  columns = c("xgroups", "p"),
  parenth = "sd",
  sep.char = ", ",
  variance = "unequal",
  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 mean, "xgroups" for x group means, "diff" for difference in x group means (this one and the next two are only available for binary x), "diffci" for 95 x group means, "diff.ci" for difference in group means and 95 confidence interval, "test" for test statistic, and "p" for p-value.

parenth

Character string specifying what statistic to display in parentheses after the means. Choices are "none", "sd", "se", "t.ci", "z.ci", "range", and "minmax".

sep.char

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

variance

Character string specifying which version of the two-sample t-test to use if x has 2 levels. Choices are "equal" for equal variance t-test, "unequal" for unequal variance t-test, and "f" for F test to determine which to use.

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

A t-test is used to compare means if x has two levels, and a one-way analysis of variance is used if x has more than two levels. Observations with missing values for x and/or y are dropped.

Value

kable or character matrix.

Examples

1
2
3
4
5
6
# Compare mean BMI in control vs. treatment group in sample dataset
(meanstable1 <- tabmeans(BMI ~ Group, data = tabdata))

# Compare mean baseline systolic BP across tertiles of BMI
(meanstable2 <- tabmeans(bp.1 ~ BMI, data = tabdata,
                         quantiles = 3, yname = "Systolic BP"))

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