get_tableone: Calculate summary statistics

View source: R/get_tableone.R

get_tableoneR Documentation

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
)

## Default S3 method:
get_tableone(
  data,
  strata = NULL,
  overall = TRUE,
  summary_function = summarize_short
)

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.

Value

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

Note

All columns in the table will be summarized. If only some columns shall be used, please select only those variables prior to creating the summary table by using dplyr::select()

Examples


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


visR documentation built on May 29, 2024, 11:50 a.m.