Learn R Programming

tab (version 4.1.1)

tabmedians.svy: Create Table Comparing Group Medians (for Complex Survey Data)

Description

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

Usage

tabmedians.svy(formula, design, columns = c("xgroups", "p"),
  parenth = "iqr", sep.char = ", ", xlevels = NULL, yname = NULL,
  text.label = NULL, decimals = NULL, svyranktest.list = NULL,
  formatp.list = NULL, n.headings = FALSE, N.headings = FALSE,
  print.html = FALSE, html.filename = "table1.html")

Arguments

formula

Formula, e.g. BMI ~ Sex.

design

Survey design object from svydesign.

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

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.

decimals

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

svyranktest.list

List of arguments to pass to svyranktest.

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.

N.headings

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

print.html

Logical value for whether to write a .html file with the table to the current working directory.

html.filename

Character string specifying the name of the .html file that gets written if print.html = TRUE.

Value

Data frame which you can print in R (e.g. with xtable's xtable or knitr's kable) or export to Word, Excel, or some other program. To export the table, set print.html = TRUE. This will result in a .html file being written to your current working directory, which you can open and copy/paste into your document.

Details

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

Examples

Run this code
# NOT RUN {
# Create survey design object
library("survey")
design <- svydesign(
  data = tabsvydata,
  ids = ~sdmvpsu,
  strata = ~sdmvstra,
  weights = ~wtmec2yr,
  nest = TRUE
)

# Compare median BMI by sex
(medtable1 <- tabmedians.svy(BMI ~ Sex, design = design))


# }

Run the code above in your browser using DataLab