#Introduction The data used in the following examples comes from the heart disease dataset found at the UCI Machine Learning Repository.
#Load packages
require(tidyverse); require(cheese)
## Loading required package: tidyverse
## ── Attaching packages ────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.2.1 ✔ purrr 0.3.2
## ✔ tibble 2.1.3 ✔ dplyr 0.8.3
## ✔ tidyr 1.0.2 ✔ stringr 1.4.0
## ✔ readr 1.3.1 ✔ forcats 0.4.0
## ── Conflicts ───────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## Loading required package: cheese
#Look at the top ten rows
heart_disease
## # A tibble: 303 x 9
## Age Sex ChestPain BP Cholesterol BloodSugar MaximumHR
## <dbl> <fct> <fct> <dbl> <dbl> <lgl> <dbl>
## 1 63 Male Typical … 145 233 TRUE 150
## 2 67 Male Asymptom… 160 286 FALSE 108
## 3 67 Male Asymptom… 120 229 FALSE 129
## 4 37 Male Non-angi… 130 250 FALSE 187
## 5 41 Fema… Atypical… 130 204 FALSE 172
## 6 56 Male Atypical… 120 236 FALSE 178
## 7 62 Fema… Asymptom… 140 268 FALSE 160
## 8 57 Fema… Asymptom… 120 354 FALSE 163
## 9 63 Male Asymptom… 130 254 FALSE 147
## 10 53 Male Asymptom… 140 203 TRUE 155
## # … with 293 more rows, and 2 more variables: ExerciseInducedAngina <fct>,
## # HeartDisease <fct>
#Creating a univariate table
The function univariate_table
allows flexible summarization and presentation of variables in a dataset. Arguments are available to customize the statistics that are computed, association metrics, stratification variables, variable labels, etc. The format
argument allows the user to render any table in “html”, “latex”, “markdown”, “pandoc”, “none” (i.e. return a data.frame
). The following examples are rendered in “html” (default):
##Default By default, the median (iqr), count (%), and the number of distinct values are displayed for numeric, categorical, and 'other' data types,
#Default table
heart_disease %>%
univariate_table
Variable | Level | Summary |
---|---|---|
Age | 56 (13) | |
Sex | Female | 97 (32.01%) |
Male | 206 (67.99%) | |
ChestPain | Typical angina | 23 (7.59%) |
Atypical angina | 50 (16.5%) | |
Non-anginal pain | 86 (28.38%) | |
Asymptomatic | 144 (47.52%) | |
BP | 130 (20) | |
Cholesterol | 241 (64) | |
BloodSugar | 2 | |
MaximumHR | 153 (32.5) | |
ExerciseInducedAngina | No | 204 (67.33%) |
Yes | 99 (32.67%) | |
HeartDisease | No | 164 (54.13%) |
Yes | 139 (45.87%) |