create_tidy_table_one_no_strata: Tidy table one with no strata

View source: R/create-tidy-table-one_no-strata.R

create_tidy_table_one_no_strataR Documentation

Tidy table one with no strata

Description

Creates a tidy data frame of the results that can go into a "Table 1" of summary descriptive statistics of a study sample. Inspiration for this is owed to the tableone package by Kazuki Yoshida.

Usage

create_tidy_table_one_no_strata(
  data,
  strata = NULL,
  vars,
  na_level = "(Missing)",
  b_replicates = 2000,
  ...
)

Arguments

data

A data frame or tibble containing the variables to be summarized.

strata

NULL

vars

Character vector of the variable names to be summarized. If empty, then all variables in the given data frame are used.

na_level

Character string of the text to replace NA in the strata variable, if any exist.

b_replicates

an integer specifying the number of replicates used in the Monte Carlo test for Fisher's Exact test and Chi-square test.

...

Additional arguments. Not used.

Value

A tibble with the following results

strata

Level of the stratifying variable

var

Variable/column name

n

Number of records

n_distinct

Numer of distinct values

complete

Number of non-missing observations

missing

Number of missing observations

mean

Mean

sd

Standard deviation

p0

Minimum

p25

25th percentile

p50

Median

p75

75th percentile

p100

Maximum

cv

Coefficient of variation

shapiro_test

Shapiro-Wilkes test: p-value

ks_test

Kolmogorov-Smirnov test: p-value

ad_test

Anderson-Darling test for normality: p-value

level

Level of the variable

n_level

Total number in the variable's group

n_strata

Total number in the variable group and strata

Examples

library(dplyr)

tab1 <- create_tidy_table_one_no_strata(data = pbc_mayo,
                                        strata = NULL,
                                        vars = c("time",
                                                 "status",
                                                 "trt",
                                                 "age",
                                                 "sex",
                                                 "ascites",
                                                 "hepato",
                                                 "spiders",
                                                 "edema",
                                                 "bili",
                                                 "chol",
                                                 "albumin",
                                                 "copper",
                                                 "alk_phos",
                                                 "ast",
                                                 "trig",
                                                 "platelet",
                                                 "protime",
                                                 "stage"))

dplyr::glimpse(tab1)


library(ggplot2)  # diamonds data set

tab2 <- create_tidy_table_one_no_strata(data = diamonds,
                                        vars = c("carat",
                                                 "cut",
                                                 "color",
                                                 "clarity",
                                                 "depth",
                                                 "table",
                                                 "price"))

dplyr::glimpse(tab2)

emilelatour/tidytableone documentation built on Jan. 6, 2025, 9:20 a.m.