svyCreateTableOne: Create an object summarizing both continuous and categorical...

View source: R/svyCreateTableOne.R

svyCreateTableOneR Documentation

Create an object summarizing both continuous and categorical variables for weighted data

Description

Create an object summarizing all baseline variables (both continuous and categorical) optionally stratifying by one or more startifying variables and performing statistical tests. The object gives a table that is easy to use in medical research papers.

Usage

svyCreateTableOne(
  vars,
  strata,
  data,
  factorVars,
  includeNA = FALSE,
  test = TRUE,
  testApprox = svyTestChisq,
  argsApprox = NULL,
  testNormal = svyTestNormal,
  argsNormal = list(method = "Wald"),
  testNonNormal = svyTestNonNormal,
  argsNonNormal = NULL,
  smd = TRUE,
  addOverall = FALSE
)

Arguments

vars

Variables to be summarized given as a character vector. Factors are handled as categorical variables, whereas numeric variables are handled as continuous variables. If empty, all variables in the survey design object specified in the data argument are used.

strata

Stratifying (grouping) variable name(s) given as a character vector. If omitted, the overall results are returned.

data

A survey design object in which these variables exist. All variables (both vars and strata) must be in this survey design object. It is created with the svydesign function in the survey package.

factorVars

Numerically coded variables that should be handled as categorical variables given as a character vector. Do not include factors, unless you need to relevel them by removing empty levels. If omitted, only factors are considered categorical variables. The variables specified here must also be specified in the vars argument.

includeNA

If TRUE, NA is handled as a regular factor level rather than missing. NA is shown as the last factor level in the table. Only effective for categorical variables.

test

If TRUE, as in the default and there are more than two groups, groupwise comparisons are performed.

testApprox

A function used to perform the large sample approximation based tests. The default is svychisq.

argsApprox

A named list of arguments passed to the function specified in testApprox.

testNormal

A function used to perform the normal assumption based tests. The default is multiple degrees of freedom test using svyglm and regTermTest. This is equivalent of the svyttest when there are only two groups.

argsNormal

A named list of arguments passed to the function specified in testNormal.

testNonNormal

A function used to perform the nonparametric tests. The default is svyranktest.

argsNonNormal

A named list of arguments passed to the function specified in testNonNormal.

smd

If TRUE, as in the default and there are more than two groups, standardized mean differences for all pairwise comparisons are calculated.

addOverall

(optional, only used if strata are supplied) Adds an overall column to the table. Smd and p-value calculations are performed using only the stratifed clolumns.

Details

See the details for CreateTableOne.

Value

An object of class svyTableOne, which is a list of three objects.

ContTable

an object of class svyContTable, containing continuous variables only

CatTable

an object of class svyCatTable, containing categorical variables only

MetaData

list of metadata regarding variables

Author(s)

Kazuki Yoshida

See Also

print.TableOne, summary.TableOne

Examples


## Load packages
library(tableone)
library(survey)

## Create a weighted survey design object
data(nhanes)
nhanesSvy <- svydesign(ids = ~ SDMVPSU, strata = ~ SDMVSTRA, weights = ~ WTMEC2YR,
                       nest = TRUE, data = nhanes)

## Create a table object
## factorVars are converted to factors; no need for variables already factors
## strata will stratify summaries; leave it unspecified for overall summaries
tab1 <- svyCreateTableOne(vars = c("HI_CHOL","race","agecat","RIAGENDR"),
                          strata = "RIAGENDR", data = nhanesSvy,
                          factorVars = c("race","RIAGENDR"))

## Detailed output
summary(tab1)

## Default formatted printing
tab1

## nonnormal specifies variables to be shown as median [IQR]
print(tab1, nonnormal = "HI_CHOL", contDigits = 3, catDigits = 2,
      pDigits = 4, smd = TRUE)

## minMax changes it to median [min, max]
print(tab1, nonnormal = "HI_CHOL", minMax = TRUE, contDigits = 3,
      catDigits = 2, pDigits = 4, smd = TRUE)

## showAllLevels can be used tow show levels for all categorical variables
print(tab1, showAllLevels = TRUE, smd = TRUE)

## To see all printing options
?print.TableOne

## To examine categorical variables only
tab1$CatTable

## To examine continuous variables only
tab1$ContTable

## If SMDs are needed as numericals, use ExtractSmd()
ExtractSmd(tab1)


tableone documentation built on April 15, 2022, 5:06 p.m.