View source: R/create-tidy-table-one.R
create_tidy_table_one | R Documentation |
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.
create_tidy_table_one(
data,
strata = NULL,
vars,
na_level = "(Missing)",
b_replicates = 2000,
...
)
data |
A data frame or tibble containing the variables to be summarized. |
strata |
Character vector of the stratifying (grouping) variable. |
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 |
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. |
A tibble with the following results
Level of the stratifying variable
Variable/column name
Number of records
Numer of distinct values
Number of non-missing observations
Number of missing observations
Mean
Standard deviation
Minimum
25th percentile
Median
75th percentile
Maximum
Coefficient of variation
Shapiro-Wilkes test: p-value
Kolmogorov-Smirnov test: p-value
Anderson-Darling test for normality: p-value
Level of the variable
Total number in the variable's group
Total number in the variable group and strata
Chi square test: p-value, with continuity correction
Chi square test: p-value, without continuity correction
Chi square test: p-value: simulated p-value
Fisher's exact test: p-value
Fisher's exact test: simulated p-value
Is Chi square OK? Consider Fisher
Oneway anova test: p-value, equivalent to t-test when only 2 groups, unequal variances
Oneway anova test: p-value, equivalent to t-test when only 2 groups, equal variances
Kruskal-Wallis Rank Sum Test: p-value, equivalent to Mann-Whitney U test when only 2 groups
Bartlett's test for homogeneity of variances: p-value
Levene's test for homogeneity of variances: p-value
Standarized mean difference for all pairwise comparisons
library(dplyr)
tab1 <- create_tidy_table_one(data = pbc_mayo,
strata = "trt",
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
#### With strata --------------------------------
# Continuous and categoical
(t1 <- create_tidy_table_one(data = diamonds,
strata = "cut",
vars = c("carat",
# Don't have to include the strata variable
# "cut",
"color",
"clarity",
"depth",
"table",
"price"))
)
dplyr::glimpse(t1)
t1 |>
adorn_tidytableone()
# Continuous only
(t2 <- create_tidy_table_one(data = diamonds,
strata = "cut",
vars = c("carat"))
)
t2 |>
adorn_tidytableone()
# Categorical only
(t3 <- create_tidy_table_one(data = diamonds,
strata = "cut",
vars = c("color")))
t3 |>
adorn_tidytableone()
#### Withou strata --------------------------------
# Continuous and categoical
(t1 <- create_tidy_table_one(data = diamonds,
strata = NULL,
vars = c("carat",
# Don't have to include the strata variable
# "cut",
"color",
"clarity",
"depth",
"table",
"price"))
)
t1 |>
adorn_tidytableone()
# Continuous only
(t2 <- create_tidy_table_one(data = diamonds,
strata = NULL,
vars = c("carat"))
)
t2 |>
adorn_tidytableone()
# Categorical only
(t3 <- create_tidy_table_one(data = diamonds,
strata = NULL,
vars = c("color")))
t3 |>
adorn_tidytableone()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.