tabfreq: Create Frequency Table

Description Usage Arguments Value Examples

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

Description

Creates an I-by-J frequency table comparing the distribution 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
20
21
22
23
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
)

Arguments

formula

Formula, e.g. Sex ~ Group.

data

Data frame containing variables named in formula.

x

Vector indicating group membership for columns of I-by-J table.

y

Vector indicating group membership for rows of I-by-J table.

columns

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.

cell

Character string specifying what statistic to display in cells. Choices are "counts", "tot.percent", "col.percent", and "row.percent".

parenth

Character string specifying what statistic to display in parentheses. Choices are "none", "se", "ci", "counts", "tot.percent", "col.percent", and "row.percent".

sep.char

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

test

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.

xlevels

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

yname

Character string with a label for the y variable.

ylevels

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).

compress.binary

Logical value for whether to compress binary y variable to a single row, excluding the first level rather than showing both.

yname.row

Logical value for whether to include a row displaying the name of the y variable and indent the factor levels.

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.

Value

kable.

Examples

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

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