Skip to contents

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$RevaluedData

4 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
Comparison by Diagnosis (values: mean (SD)).
Characteristic Control
N = 2421
Impaired
N = 911
p-value2 Test2
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 (%)
2 p-values use Welch t-test (two groups) or ANOVA (more than two groups) for continuous outcomes and chi-square or Fisher’s exact test, selected from expected counts for categorical outcomes.

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
Comparison by Diagnosis (values: mean (SD)).
Characteristic Control
N = 2421
Impaired
N = 911
p-value2 Test2 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.0011 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 (%)
2 p-values use Welch t-test (two groups) or ANOVA (more than two groups) for continuous outcomes and chi-square or Fisher’s exact test, selected from expected counts for categorical outcomes.

When reporting group differences, effect sizes should generally be interpreted alongside p-values.

For parametric continuous outcomes, the reported effect size depends on the number of groups:

  • Two groups use absolute Cohen’s (d). With covariates, this is the adjusted estimated marginal mean difference divided by the ANCOVA residual standard deviation.
  • More than two groups use Cohen’s (f). With covariates, partial Cohen’s (f) is calculated from the Type II ANCOVA group effect.

Cohen’s (d) and Cohen’s (f) are not numerically equivalent. In a balanced two-group design only, (d 2f). Interpret each effect-size scale in its methodological context; conventional magnitude guides are heuristics, not thresholds for clinical importance. The generated table caption and methods footnote remain focused on the summaries and hypothesis tests used.

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
Comparison by Diagnosis (values: median [IQR]).
Characteristic Control
N = 2421
Impaired
N = 911
p-value2 Test2 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 (%)
2 p-values use Wilcoxon rank-sum test (two groups) or Kruskal-Wallis test (more than two groups) for continuous outcomes and chi-square or Fisher’s exact test, selected from expected counts for categorical outcomes.

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
Comparison by Diagnosis (values: mean (SD)). p-values adjusted for Age.
Characteristic Control
N = 2421
Impaired
N = 911
p-value2 Test2 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.14 adjusted |d| (EMM / residual SD)
Calbindin 21.99 (3.90) 22.93 (4.85) 0.0722 ANCOVA (Type II) 0.22 adjusted |d| (EMM / residual SD)
Ferritin 2.70 (0.76) 2.90 (0.83) 0.0454 ANCOVA (Type II) 0.25 adjusted |d| (EMM / residual SD)
Matrix metalloproteinase 7 -4.07 (1.58) -3.21 (1.28) <0.001 ANCOVA (Type II) 0.55 adjusted |d| (EMM / residual SD)
1 n (%); Mean (SD)
2 p-values use Type II ANCOVA for continuous outcomes and logistic likelihood-ratio test for binary outcomes or multinomial likelihood-ratio test for multicategory outcomes for categorical outcomes.

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
Comparison by Genotype (values: mean (SD)). Pairwise p-values are bonferroni-adjusted within outcome.
Characteristic E2E2
N = 21
E2E3
N = 371
E2E4
N = 81
E3E3
N = 1671
E3E4
N = 1061
E4E4
N = 131
p-value2 Test2 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.14 Cohen's f 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Sex





0.475 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.09 Cohen's f 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.10 Cohen's f 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.08 Cohen's f 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.04 Cohen's f 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 n (%); Mean (SD)
2 p-values use Welch t-test (two groups) or ANOVA (more than two groups) for continuous outcomes and chi-square or Fisher’s exact test, selected from expected counts for categorical outcomes. Pairwise p-values are bonferroni-adjusted within outcome.

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
Comparison by Genotype (values: mean (SD)). Pairwise p-values are bonferroni-adjusted within outcome.
Characteristic E2E2
N = 21
E2E3
N = 371
E2E4
N = 81
E3E3
N = 1671
E3E4
N = 1061
E4E4
N = 131
p-value2 Test2 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.14 Cohen's f 1 1 1 1 1
Sex





0.475 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.09 Cohen's f 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.10 Cohen's f 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.08 Cohen's f 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.04 Cohen's f 1 1 1 1 1
1 n (%); Mean (SD)
2 p-values use Welch t-test (two groups) or ANOVA (more than two groups) for continuous outcomes and chi-square or Fisher’s exact test, selected from expected counts for categorical outcomes. Pairwise p-values are bonferroni-adjusted within outcome.

9 Summary

MakeComparisonTable() supports:

  • Descriptive statistics
  • Parametric analyses
  • Nonparametric analyses
  • Effect sizes
  • Covariate adjustment
  • Pairwise testing
  • Reference-group comparisons
  • Automatic variable labeling

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_21.0.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      labelled_2.16.0        digest_0.6.39
 [13] estimability_2.0.0     lifecycle_1.0.5        lmom_3.3
 [16] magrittr_2.0.5         compiler_4.6.1         rlang_1.3.0
 [19] sass_0.4.10            tools_4.6.1            yaml_2.3.12
 [22] gt_1.3.0               data.table_1.18.4      knitr_1.51
 [25] xml2_1.6.0             RColorBrewer_1.1-3     abind_1.4-8
 [28] expm_1.0-0             withr_3.0.3            purrr_1.2.2
 [31] nnet_7.3-20            grid_4.6.1             datawizard_1.3.1
 [34] xtable_1.8-8           e1071_1.7-17           gtsummary_2.5.1
 [37] paletteer_1.7.0        ggplot2_4.0.3          emmeans_2.0.4
 [40] scales_1.4.0           MASS_7.3-65            dichromat_2.0-1
 [43] insight_1.5.2          cli_3.6.6              mvtnorm_1.4-2
 [46] rmarkdown_2.31         generics_0.1.4         otel_0.2.0
 [49] RcppParallel_6.2.0     rstudioapi_0.19.0      httr_1.4.8
 [52] tzdb_0.5.0             parameters_0.29.2      commonmark_2.0.0
 [55] readxl_1.5.0           gld_2.6.8              proxy_0.4-29
 [58] effectsize_1.0.3       cellranger_1.1.0       base64enc_0.1-6
 [61] vctrs_0.7.3            Matrix_1.7-5           boot_1.3-32
 [64] sandwich_3.1-3         jsonlite_2.0.0         carData_3.0-6
 [67] car_3.1-5              litedown_0.10          hms_1.1.4
 [70] patchwork_1.3.2        rstatix_1.1.0          Formula_1.2-6
 [73] correlation_0.8.8      tidyr_1.3.2            glue_1.8.1
 [76] rematch2_2.1.2         gtable_0.3.6           tibble_3.3.1
 [79] pillar_1.11.1          htmltools_0.5.9        R6_2.6.1
 [82] evaluate_1.0.5         lattice_0.22-9         readr_2.2.0
 [85] markdown_2.0           haven_2.5.5            backports_1.5.1
 [88] cards_0.8.1            broom_1.0.13           snakecase_0.11.1
 [91] rstantools_2.7.0       DescTools_0.99.60      class_7.3-23
 [94] Rcpp_1.1.2             coda_0.19-4.1          xfun_0.60
 [97] fs_2.1.0               zoo_1.9-0              forcats_1.0.1
[100] pkgconfig_2.0.3