1 Overview
MakeComparisonTable() creates publication-ready summary tables for comparing groups across continuous and categorical variables.
This vignette demonstrates:
- Basic group comparisons
- Adding effect sizes
- Parametric versus nonparametric testing
- Covariate adjustment
- Pairwise comparisons
- Reference-group comparisons
- Automatic use of variable labels
2 Load packages
3 Load example data
SciDataReportR includes an example dataset and codebook.
data("SampleData")
data("SampleVariableTypes")
RevaluedObj <- RevalueData(
SampleData,
SampleVariableTypes
)
df_Revalued <- RevaluedObj$RevaluedData4 Basic comparison table
The most common use case is comparing groups across a set of variables.
Here we compare diagnostic groups.
tbl_basic <- MakeComparisonTable(
df_Revalued,
CompVariable = "Diagnosis",
Variables = c(
"age",
"sex",
"Genotype",
"AXL",
"Calbindin",
"Ferritin",
"MMP7"
)
)
tbl_basic| Characteristic |
Control N = 2421 |
Impaired N = 911 |
p-value | Test |
|---|---|---|---|---|
| Age | 72.75 (13.26) | 71.78 (13.12) | 0.553 | Welch t-test |
| Sex | 0.0272 | Pearson chi-squared | ||
| Female | 157 (65%) | 47 (52%) | ||
| Male | 85 (35%) | 44 (48%) | ||
| Genotype | <0.001 | Fisher (sim.) | ||
| E2E2 | 2 (0.8%) | 0 (0%) | ||
| E2E3 | 30 (12%) | 7 (7.7%) | ||
| E2E4 | 7 (2.9%) | 1 (1.1%) | ||
| E3E3 | 133 (55%) | 34 (37%) | ||
| E3E4 | 65 (27%) | 41 (45%) | ||
| E4E4 | 5 (2.1%) | 8 (8.8%) | ||
| AXL receptor tyrosine kinase | 0.28 (0.46) | 0.34 (0.41) | 0.238 | Welch t-test |
| Calbindin | 21.99 (3.90) | 22.93 (4.85) | 0.101 | Welch t-test |
| Ferritin | 2.70 (0.76) | 2.90 (0.83) | 0.0426 | Welch t-test |
| Matrix metalloproteinase 7 | -4.07 (1.58) | -3.21 (1.28) | <0.001 | Welch t-test |
| 1 Mean (SD); n (%) | ||||
The resulting table contains:
- Descriptive statistics
- Group comparison tests
- P-values
- Automatically applied variable labels
5 Adding effect sizes
Effect sizes provide information about the magnitude of group differences.
tbl_effectsize <- MakeComparisonTable(
df_Revalued,
CompVariable = "Diagnosis",
Variables = c(
"age",
"sex",
"Genotype",
"AXL",
"Calbindin",
"Ferritin",
"MMP7"
),
AddEffectSize = TRUE
)
tbl_effectsize| Characteristic |
Control N = 2421 |
Impaired N = 911 |
p-value | Test | Effect size | ES method |
|---|---|---|---|---|---|---|
| Age | 72.75 (13.26) | 71.78 (13.12) | 0.553 | Welch t-test | 0.07 | |d| |
| Sex | 0.0272 | Pearson chi-squared | 0.12 | Cramer's V | ||
| Female | 157 (65%) | 47 (52%) | ||||
| Male | 85 (35%) | 44 (48%) | ||||
| Genotype | <0.001 | Fisher (sim.) | 0.25 | Cramer's V | ||
| E2E2 | 2 (0.8%) | 0 (0%) | ||||
| E2E3 | 30 (12%) | 7 (7.7%) | ||||
| E2E4 | 7 (2.9%) | 1 (1.1%) | ||||
| E3E3 | 133 (55%) | 34 (37%) | ||||
| E3E4 | 65 (27%) | 41 (45%) | ||||
| E4E4 | 5 (2.1%) | 8 (8.8%) | ||||
| AXL receptor tyrosine kinase | 0.28 (0.46) | 0.34 (0.41) | 0.238 | Welch t-test | 0.14 | |d| |
| Calbindin | 21.99 (3.90) | 22.93 (4.85) | 0.101 | Welch t-test | 0.22 | |d| |
| Ferritin | 2.70 (0.76) | 2.90 (0.83) | 0.0426 | Welch t-test | 0.26 | |d| |
| Matrix metalloproteinase 7 | -4.07 (1.58) | -3.21 (1.28) | <0.001 | Welch t-test | 0.57 | |d| |
| 1 Mean (SD); n (%) | ||||||
When reporting group differences, effect sizes should generally be interpreted alongside p-values.
6 Nonparametric analyses
Nonparametric testing uses rank-based methods that are more robust to non-normal distributions.
tbl_nonparametric <- MakeComparisonTable(
df_Revalued,
CompVariable = "Diagnosis",
Variables = c(
"age",
"sex",
"Genotype",
"AXL",
"Calbindin",
"Ferritin",
"MMP7"
),
Parametric = FALSE,
AddEffectSize = TRUE
)
tbl_nonparametric| Characteristic |
Control N = 2421 |
Impaired N = 911 |
p-value | Test | Effect size | ES method |
|---|---|---|---|---|---|---|
| Age | 74.00 [64.00, 83.00] | 73.00 [63.00, 82.00] | 0.707 | Wilcoxon rank-sum | -0.00 | epsilon-squared |
| Sex | 0.0272 | Pearson chi-squared | 0.12 | Cramer's V | ||
| Female | 157 (65%) | 47 (52%) | ||||
| Male | 85 (35%) | 44 (48%) | ||||
| Genotype | <0.001 | Fisher (sim.) | 0.25 | Cramer's V | ||
| E2E2 | 2 (0.8%) | 0 (0%) | ||||
| E2E3 | 30 (12%) | 7 (7.7%) | ||||
| E2E4 | 7 (2.9%) | 1 (1.1%) | ||||
| E3E3 | 133 (55%) | 34 (37%) | ||||
| E3E4 | 65 (27%) | 41 (45%) | ||||
| E4E4 | 5 (2.1%) | 8 (8.8%) | ||||
| AXL receptor tyrosine kinase | 0.28 [-0.04, 0.61] | 0.28 [0.10, 0.61] | 0.481 | Wilcoxon rank-sum | -0.00 | epsilon-squared |
| Calbindin | 21.92 [19.63, 24.46] | 22.66 [20.00, 26.91] | 0.119 | Wilcoxon rank-sum | 0.00 | epsilon-squared |
| Ferritin | 2.71 [2.20, 3.22] | 2.90 [2.29, 3.33] | 0.127 | Wilcoxon rank-sum | 0.00 | epsilon-squared |
| Matrix metalloproteinase 7 | -4.03 [-5.12, -3.16] | -3.35 [-4.03, -2.26] | <0.001 | Wilcoxon rank-sum | 0.07 | epsilon-squared |
| 1 Median [Q1, Q3]; n (%) | ||||||
7 Including Covariates
Age is frequently included as a covariate in biomedical analyses.
The example below evaluates group differences after accounting for age.
tbl_covariate <- MakeComparisonTable(
df_Revalued,
CompVariable = "Diagnosis",
Variables = c(
"sex",
"Genotype",
"AXL",
"Calbindin",
"Ferritin",
"MMP7"
),
Covariates = "age",
AddEffectSize = TRUE
)
tbl_covariate| Characteristic |
Control N = 2421 |
Impaired N = 911 |
p-value | Test | Effect size | ES method |
|---|---|---|---|---|---|---|
| Sex | 0.0323 | Logistic regression (LR) | 0.12 | Cramer's V | ||
| Female | 157 (65%) | 47 (52%) | ||||
| Male | 85 (35%) | 44 (48%) | ||||
| Genotype | <0.001 | Multinomial LR | 0.25 | Cramer's V | ||
| E2E2 | 2 (0.8%) | 0 (0%) | ||||
| E2E3 | 30 (12%) | 7 (7.7%) | ||||
| E2E4 | 7 (2.9%) | 1 (1.1%) | ||||
| E3E3 | 133 (55%) | 34 (37%) | ||||
| E3E4 | 65 (27%) | 41 (45%) | ||||
| E4E4 | 5 (2.1%) | 8 (8.8%) | ||||
| AXL receptor tyrosine kinase | 0.28 (0.46) | 0.34 (0.41) | 0.257 | ANCOVA (Type II) | 0.00 | partial eta-squared |
| Calbindin | 21.99 (3.90) | 22.93 (4.85) | 0.0722 | ANCOVA (Type II) | 0.01 | partial eta-squared |
| Ferritin | 2.70 (0.76) | 2.90 (0.83) | 0.0454 | ANCOVA (Type II) | 0.01 | partial eta-squared |
| Matrix metalloproteinase 7 | -4.07 (1.58) | -3.21 (1.28) | <0.001 | ANCOVA (Type II) | 0.06 | partial eta-squared |
| 1 n (%); Mean (SD) | ||||||
Covariate adjustment can help determine whether observed group differences persist after controlling for potential confounding factors.
8 Pairwise comparisons
When comparing more than two groups, pairwise comparisons can identify which groups differ from one another.
tbl_pairwise <- MakeComparisonTable(
df_Revalued,
CompVariable = "Genotype",
Variables = c(
"Diagnosis",
"age",
"sex",
"AXL",
"Calbindin",
"Ferritin",
"MMP7"
),
AddPairwise = TRUE,
AddEffectSize = TRUE
)
tbl_pairwise| Characteristic |
E2E2 N = 21 |
E2E3 N = 371 |
E2E4 N = 81 |
E3E3 N = 1671 |
E3E4 N = 1061 |
E4E4 N = 131 |
p-value | Test | Effect size | ES method | E2E2 - E2E3 | E2E2 - E2E4 | E2E2 - E3E3 | E2E2 - E3E4 | E2E2 - E4E4 | E2E3 - E2E4 | E2E3 - E3E3 | E2E3 - E3E4 | E2E3 - E4E4 | E2E4 - E3E3 | E2E4 - E3E4 | E2E4 - E4E4 | E3E3 - E3E4 | E3E3 - E4E4 | E3E4 - E4E4 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Diagnosis | <0.001 | Fisher (sim.) | 0.25 | Cramer's V | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0.426 | 0.163 | 1 | 1 | 1 | 0.0143 | 0.037 | 1 | ||||||
| Control | 2 (100%) | 30 (81%) | 7 (88%) | 133 (80%) | 65 (61%) | 5 (38%) | |||||||||||||||||||
| Impaired | 0 (0%) | 7 (19%) | 1 (13%) | 34 (20%) | 41 (39%) | 8 (62%) | |||||||||||||||||||
| Age | 54.00 (15.56) | 72.30 (12.78) | 78.13 (19.47) | 72.04 (13.87) | 72.85 (11.37) | 74.83 (15.19) | 0.305 | ANOVA | 0.02 | eta-squared | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| Sex | 0.473 | Fisher (sim.) | 0.12 | Cramer's V | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | ||||||
| Female | 0 (0%) | 22 (59%) | 4 (50%) | 100 (60%) | 70 (66%) | 8 (62%) | |||||||||||||||||||
| Male | 2 (100%) | 15 (41%) | 4 (50%) | 67 (40%) | 36 (34%) | 5 (38%) | |||||||||||||||||||
| AXL receptor tyrosine kinase | 0.08 (0.64) | 0.32 (0.42) | 0.38 (0.66) | 0.31 (0.47) | 0.29 (0.41) | 0.13 (0.33) | 0.727 | ANOVA | 0.01 | eta-squared | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| Calbindin | 20.24 (5.22) | 21.98 (4.04) | 23.36 (3.89) | 22.04 (4.31) | 22.70 (3.88) | 21.55 (5.81) | 0.676 | ANOVA | 0.01 | eta-squared | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| Ferritin | 2.54 (1.06) | 2.76 (0.80) | 2.77 (0.91) | 2.74 (0.81) | 2.81 (0.75) | 2.48 (0.62) | 0.807 | ANOVA | 0.01 | eta-squared | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| Matrix metalloproteinase 7 | -3.49 (3.68) | -3.80 (1.46) | -4.10 (1.54) | -3.82 (1.53) | -3.83 (1.59) | -3.98 (1.83) | 0.993 | ANOVA | 0.00 | eta-squared | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 1 n (%); Mean (SD) | |||||||||||||||||||||||||
You can also choose a referent and compare only to that
tbl_pairwise_referent <- MakeComparisonTable(
df_Revalued,
CompVariable = "Genotype",
Variables = c(
"Diagnosis",
"age",
"sex",
"AXL",
"Calbindin",
"Ferritin",
"MMP7"
),
AddPairwise = TRUE,
AddEffectSize = TRUE,
Referent = "E3E3"
)
tbl_pairwise_referent| Characteristic |
E2E2 N = 21 |
E2E3 N = 371 |
E2E4 N = 81 |
E3E3 N = 1671 |
E3E4 N = 1061 |
E4E4 N = 131 |
p-value | Test | Effect size | ES method | E3E3 - E2E2 | E3E3 - E2E3 | E3E3 - E2E4 | E3E3 - E3E4 | E3E3 - E4E4 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Diagnosis | <0.001 | Fisher (sim.) | 0.25 | Cramer's V | 1 | 1 | 1 | 0.00475 | 0.0123 | ||||||
| Control | 2 (100%) | 30 (81%) | 7 (88%) | 133 (80%) | 65 (61%) | 5 (38%) | |||||||||
| Impaired | 0 (0%) | 7 (19%) | 1 (13%) | 34 (20%) | 41 (39%) | 8 (62%) | |||||||||
| Age | 54.00 (15.56) | 72.30 (12.78) | 78.13 (19.47) | 72.04 (13.87) | 72.85 (11.37) | 74.83 (15.19) | 0.305 | ANOVA | 0.02 | eta-squared | 1 | 1 | 1 | 1 | 1 |
| Sex | 0.481 | Fisher (sim.) | 0.12 | Cramer's V | 0.826 | 1 | 1 | 1 | 1 | ||||||
| Female | 0 (0%) | 22 (59%) | 4 (50%) | 100 (60%) | 70 (66%) | 8 (62%) | |||||||||
| Male | 2 (100%) | 15 (41%) | 4 (50%) | 67 (40%) | 36 (34%) | 5 (38%) | |||||||||
| AXL receptor tyrosine kinase | 0.08 (0.64) | 0.32 (0.42) | 0.38 (0.66) | 0.31 (0.47) | 0.29 (0.41) | 0.13 (0.33) | 0.727 | ANOVA | 0.01 | eta-squared | 1 | 1 | 1 | 1 | 0.404 |
| Calbindin | 20.24 (5.22) | 21.98 (4.04) | 23.36 (3.89) | 22.04 (4.31) | 22.70 (3.88) | 21.55 (5.81) | 0.676 | ANOVA | 0.01 | eta-squared | 1 | 1 | 1 | 0.963 | 1 |
| Ferritin | 2.54 (1.06) | 2.76 (0.80) | 2.77 (0.91) | 2.74 (0.81) | 2.81 (0.75) | 2.48 (0.62) | 0.807 | ANOVA | 0.01 | eta-squared | 1 | 1 | 1 | 1 | 0.926 |
| Matrix metalloproteinase 7 | -3.49 (3.68) | -3.80 (1.46) | -4.10 (1.54) | -3.82 (1.53) | -3.83 (1.59) | -3.98 (1.83) | 0.993 | ANOVA | 0.00 | eta-squared | 1 | 1 | 1 | 1 | 1 |
| 1 n (%); Mean (SD) | |||||||||||||||
9 Summary
MakeComparisonTable() supports:
- Descriptive statistics
- Parametric analyses
- Nonparametric analyses
- Effect sizes
- Covariate adjustment
- Pairwise testing
- Reference-group comparisons
- Automatic variable labeling
10 Related functions
RevalueData()CreateCodebook()PlotBoxPlot()PlotVolcanoEffects()CompareDatasets()
11 Session information
R version 4.6.1 (2026-06-24)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.4 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
locale:
[1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
[4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
[7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
time zone: UTC
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] dplyr_1.2.1 SciDataReportR_20.9.0
loaded via a namespace (and not attached):
[1] Exact_3.3 ggstatsplot_1.0.0 sjlabelled_1.2.0
[4] tidyselect_1.2.1 rootSolve_1.8.2.4 farver_2.1.2
[7] statsExpressions_2.0.0 S7_0.2.2 fastmap_1.2.0
[10] bayestestR_0.18.1 broom.helpers_1.22.0 labelled_2.16.0
[13] digest_0.6.39 estimability_2.0.0 lifecycle_1.0.5
[16] lmom_3.3 magrittr_2.0.5 compiler_4.6.1
[19] rlang_1.2.0 sass_0.4.10 tools_4.6.1
[22] yaml_2.3.12 gt_1.3.0 data.table_1.18.4
[25] knitr_1.51 xml2_1.6.0 RColorBrewer_1.1-3
[28] abind_1.4-8 expm_1.0-0 withr_3.0.3
[31] purrr_1.2.2 nnet_7.3-20 grid_4.6.1
[34] datawizard_1.3.1 xtable_1.8-8 e1071_1.7-17
[37] gtsummary_2.5.1 paletteer_1.7.0 ggplot2_4.0.3
[40] MASS_7.3-65 emmeans_2.0.3 scales_1.4.0
[43] dichromat_2.0-0.1 insight_1.5.2 cli_3.6.6
[46] mvtnorm_1.4-1 rmarkdown_2.31 generics_0.1.4
[49] otel_0.2.0 RcppParallel_5.1.11-2 rstudioapi_0.19.0
[52] httr_1.4.8 tzdb_0.5.0 parameters_0.29.2
[55] commonmark_2.0.0 readxl_1.5.0 gld_2.6.8
[58] proxy_0.4-29 effectsize_1.0.2 cellranger_1.1.0
[61] base64enc_0.1-6 vctrs_0.7.3 Matrix_1.7-5
[64] boot_1.3-32 sandwich_3.1-1 jsonlite_2.0.0
[67] carData_3.0-6 car_3.1-5 litedown_0.9
[70] hms_1.1.4 patchwork_1.3.2 rstatix_1.0.0
[73] Formula_1.2-5 correlation_0.8.8 tidyr_1.3.2
[76] glue_1.8.1 rematch2_2.1.2 gtable_0.3.6
[79] tibble_3.3.1 pillar_1.11.1 htmltools_0.5.9
[82] R6_2.6.1 evaluate_1.0.5 lattice_0.22-9
[85] readr_2.2.0 markdown_2.0 haven_2.5.5
[88] backports_1.5.1 cards_0.8.0 broom_1.0.13
[91] snakecase_0.11.1 rstantools_2.6.0 DescTools_0.99.60
[94] class_7.3-23 Rcpp_1.1.1-1.1 coda_0.19-4.1
[97] xfun_0.59 fs_2.1.0 zoo_1.8-15
[100] forcats_1.0.1 pkgconfig_2.0.3
