Learn R Programming

visR (version 0.4.1)

get_tableone: Calculate summary statistics

Description

[Questioning] S3 method for creating a table of summary statistics. The summary statistics can be used for presentation in tables such as table one or baseline and demography tables.

The summary statistics estimated are conditional on the variable type: continuous, binary, categorical, etc.

By default the following summary stats are calculated:

  • Numeric variables: mean, min, 25th-percentile, median, 75th-percentile, maximum, standard deviation

  • Factor variables: proportion of each factor level in the overall dataset

  • Default: number of unique values and number of missing values

Usage

get_tableone(
  data,
  strata = NULL,
  overall = TRUE,
  summary_function = summarize_short
)

# S3 method for default get_tableone( data, strata = NULL, overall = TRUE, summary_function = summarize_short )

Value

object of class tableone. That is a list of data specified summaries for all input variables.

Arguments

data

The dataset to summarize as dataframe or tibble

strata

Stratifying/Grouping variable name(s) as character vector. If NULL, only overall results are returned

overall

If TRUE, the summary statistics for the overall dataset are also calculated

summary_function

A function defining summary statistics for numeric and categorical values

Details

It is possible to provide your own summary function. Please have a loot at summary for inspiration.

Examples

Run this code

# Example using the ovarian data set

survival::ovarian %>%
  dplyr::select(-fustat) %>%
  dplyr::mutate(
    age_group = factor(
      dplyr::case_when(
        age <= 50 ~ "<= 50 years",
        age <= 60 ~ "<= 60 years",
        age <= 70 ~ "<= 70 years",
        TRUE ~ "> 70 years"
      )
    ),
    rx = factor(rx),
    ecog.ps = factor(ecog.ps)
  ) %>%
  dplyr::select(age, age_group, everything()) %>%
  visR::get_tableone()

# Examples using ADaM data

# display patients in an analysis set
adtte %>%
  dplyr::filter(SAFFL == "Y") %>%
  dplyr::select(TRTA) %>%
  visR::get_tableone()

## display overall summaries for demog
adtte %>%
  dplyr::filter(SAFFL == "Y") %>%
  dplyr::select(AGE, AGEGR1, SEX, RACE) %>%
  visR::get_tableone()

## By actual treatment
adtte %>%
  dplyr::filter(SAFFL == "Y") %>%
  dplyr::select(AGE, AGEGR1, SEX, RACE, TRTA) %>%
  visR::get_tableone(strata = "TRTA")

## By actual treatment, without overall
adtte %>%
  dplyr::filter(SAFFL == "Y") %>%
  dplyr::select(AGE, AGEGR1, SEX, EVNTDESC, TRTA) %>%
  visR::get_tableone(strata = "TRTA", overall = FALSE)

Run the code above in your browser using DataLab