tabfreq.svy: Create Frequency Table (for Complex Survey Data)

Description Usage Arguments Details Value Examples

View source: R/archived/tabfreq_svy-2020-03-28.R View source: R/tabfreq_svy.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
tabfreq.svy(
  formula,
  design,
  columns = c("xgroups", "p"),
  cell = "col.percent",
  parenth = "se",
  sep.char = ", ",
  xlevels = NULL,
  yname = NULL,
  ylevels = NULL,
  compress.binary = FALSE,
  yname.row = TRUE,
  text.label = NULL,
  decimals = 1,
  svychisq.list = NULL,
  formatp.list = NULL,
  n.headings = FALSE,
  N.headings = FALSE,
  kable = TRUE
)

Arguments

formula

Formula, e.g. Race ~ Sex.

design

Survey design object from svydesign.

columns

Character vector specifying what columns to include. Choices for each element are "n" for total unweighted sample size, "N" for total weighted sample size, "overall" for overall distribution of y, "xgroups" for distributions of y for each x group, and "p" for Chi-square p-value.

cell

Character string specifying what statistic to display in cells. Choices are "n", "N", and "col.percent".

parenth

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

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.

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.

text.label

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

decimals

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

svychisq.list

List of arguments to pass to svychisq.

formatp.list

List of arguments to pass to formatp.

n.headings

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

N.headings

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

kable

Logical value for whether to return a kable.

Details

Basically tabmedians for complex survey data. Relies heavily on the survey package.

Value

kable or character matrix.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Create survey design object
library("survey")
design <- svydesign(
  data = tabsvydata,
  ids = ~sdmvpsu,
  strata = ~sdmvstra,
  weights = ~wtmec2yr,
  nest = TRUE
)

# Compare race distribution by sex
tabfreq.svy(Race ~ Sex, design)

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