This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

load the package

Trial data

Bivariate Analysis

Cross Table Summary

library(gtsummary)
trial %>%
tbl_summary(
by = trt)
Characteristic Drug A
N = 98
1
Drug B
N = 102
1
Age 46 (37, 60) 48 (39, 56)
    Unknown 7 4
Marker Level (ng/mL) 0.84 (0.23, 1.60) 0.52 (0.18, 1.21)
    Unknown 6 4
T Stage

    T1 28 (29%) 25 (25%)
    T2 25 (26%) 29 (28%)
    T3 22 (22%) 21 (21%)
    T4 23 (23%) 27 (26%)
Grade

    I 35 (36%) 33 (32%)
    II 32 (33%) 36 (35%)
    III 31 (32%) 33 (32%)
Tumor Response 28 (29%) 33 (34%)
    Unknown 3 4
Patient Died 52 (53%) 60 (59%)
Months to Death/Censor 23.5 (17.4, 24.0) 21.2 (14.5, 24.0)
1 Median (Q1, Q3); n (%)

Common Statistics

trial %>%
tbl_summary(
by = trt,
statistic = list(
all_continuous() ~ "{mean} ({sd})",
all_categorical() ~ "{n} / {N} ({p}%)"
)
)
Characteristic Drug A
N = 98
1
Drug B
N = 102
1
Age 47 (15) 47 (14)
    Unknown 7 4
Marker Level (ng/mL) 1.02 (0.89) 0.82 (0.83)
    Unknown 6 4
T Stage

    T1 28 / 98 (29%) 25 / 102 (25%)
    T2 25 / 98 (26%) 29 / 102 (28%)
    T3 22 / 98 (22%) 21 / 102 (21%)
    T4 23 / 98 (23%) 27 / 102 (26%)
Grade

    I 35 / 98 (36%) 33 / 102 (32%)
    II 32 / 98 (33%) 36 / 102 (35%)
    III 31 / 98 (32%) 33 / 102 (32%)
Tumor Response 28 / 95 (29%) 33 / 98 (34%)
    Unknown 3 4
Patient Died 52 / 98 (53%) 60 / 102 (59%)
Months to Death/Censor 20.2 (5.0) 19.0 (5.5)
1 Mean (SD); n / N (%)

Add p, Add N-n, header

trial %>%
tbl_summary(by = trt) %>%
add_p() %>%
add_overall() %>%
add_n()
Characteristic N Overall
N = 200
1
Drug A
N = 98
1
Drug B
N = 102
1
p-value2
Age 189 47 (38, 57) 46 (37, 60) 48 (39, 56) 0.7
    Unknown
11 7 4
Marker Level (ng/mL) 190 0.64 (0.22, 1.41) 0.84 (0.23, 1.60) 0.52 (0.18, 1.21) 0.085
    Unknown
10 6 4
T Stage 200


0.9
    T1
53 (27%) 28 (29%) 25 (25%)
    T2
54 (27%) 25 (26%) 29 (28%)
    T3
43 (22%) 22 (22%) 21 (21%)
    T4
50 (25%) 23 (23%) 27 (26%)
Grade 200


0.9
    I
68 (34%) 35 (36%) 33 (32%)
    II
68 (34%) 32 (33%) 36 (35%)
    III
64 (32%) 31 (32%) 33 (32%)
Tumor Response 193 61 (32%) 28 (29%) 33 (34%) 0.5
    Unknown
7 3 4
Patient Died 200 112 (56%) 52 (53%) 60 (59%) 0.4
Months to Death/Censor 200 22.4 (15.9, 24.0) 23.5 (17.4, 24.0) 21.2 (14.5, 24.0) 0.14
1 Median (Q1, Q3); n (%)
2 Wilcoxon rank sum test; Pearson’s Chi-squared test

Add p, Add N-n, header, spanning_header, footnote, caption

trial %>%
tbl_summary(by = trt) %>%
add_p() %>%
add_overall() %>%
add_n() %>%
modify_header(label ~ "**Variable**") %>%
modify_spanning_header(c("stat_1", "stat_2") ~ "**Treatment Received**") %>%
modify_footnote(
all_stat_cols() ~ "Median (IQR) or Frequency (%)"
) %>%
modify_caption("**Table 1. Patient Characteristics**") %>%
bold_labels()
Table 1. Patient Characteristics
Variable N Overall
N = 200
1
Treatment Received
p-value2
Drug A
N = 98
1
Drug B
N = 102
1
Age 189 47 (38, 57) 46 (37, 60) 48 (39, 56) 0.7
    Unknown
11 7 4
Marker Level (ng/mL) 190 0.64 (0.22, 1.41) 0.84 (0.23, 1.60) 0.52 (0.18, 1.21) 0.085
    Unknown
10 6 4
T Stage 200


0.9
    T1
53 (27%) 28 (29%) 25 (25%)
    T2
54 (27%) 25 (26%) 29 (28%)
    T3
43 (22%) 22 (22%) 21 (21%)
    T4
50 (25%) 23 (23%) 27 (26%)
Grade 200


0.9
    I
68 (34%) 35 (36%) 33 (32%)
    II
68 (34%) 32 (33%) 36 (35%)
    III
64 (32%) 31 (32%) 33 (32%)
Tumor Response 193 61 (32%) 28 (29%) 33 (34%) 0.5
    Unknown
7 3 4
Patient Died 200 112 (56%) 52 (53%) 60 (59%) 0.4
Months to Death/Censor 200 22.4 (15.9, 24.0) 23.5 (17.4, 24.0) 21.2 (14.5, 24.0) 0.14
1 Median (IQR) or Frequency (%)
2 Wilcoxon rank sum test; Pearson’s Chi-squared test

tab_source_note

trial %>%
tbl_summary(by = trt, missing = "no") %>%
add_n() %>%
as_gt() %>%
gt::tab_source_note(gt::md("*This data is simulated*"))
Characteristic N Drug A
N = 98
1
Drug B
N = 102
1
Age 189 46 (37, 60) 48 (39, 56)
Marker Level (ng/mL) 190 0.84 (0.23, 1.60) 0.52 (0.18, 1.21)
T Stage 200

    T1
28 (29%) 25 (25%)
    T2
25 (26%) 29 (28%)
    T3
22 (22%) 21 (21%)
    T4
23 (23%) 27 (26%)
Grade 200

    I
35 (36%) 33 (32%)
    II
32 (33%) 36 (35%)
    III
31 (32%) 33 (32%)
Tumor Response 193 28 (29%) 33 (34%)
Patient Died 200 52 (53%) 60 (59%)
Months to Death/Censor 200 23.5 (17.4, 24.0) 21.2 (14.5, 24.0)
This data is simulated
1 Median (Q1, Q3); n (%)

multilayer statistics

trial %>%
select(age, trt) %>%
tbl_summary(
by = trt,
type = all_continuous() ~ "continuous2",
statistic = all_continuous() ~ c(
"{N_nonmiss}",
"{median} ({p25}, {p75})",
"{min}, {max}"
),
missing = "no"
) %>%
add_p(pvalue_fun = ~ style_pvalue(.x, digits = 2))
Characteristic Drug A
N = 98
Drug B
N = 102
p-value1
Age

0.72
    N Non-missing 91 98
    Median (Q1, Q3) 46 (37, 60) 48 (39, 56)
    Min, Max 6, 78 9, 83
1 Wilcoxon rank sum test

Univariate Analysis

Table Summary

trial %>%
tbl_summary
Characteristic N = 2001
Chemotherapy Treatment
    Drug A 98 (49%)
    Drug B 102 (51%)
Age 47 (38, 57)
    Unknown 11
Marker Level (ng/mL) 0.64 (0.22, 1.41)
    Unknown 10
T Stage
    T1 53 (27%)
    T2 54 (27%)
    T3 43 (22%)
    T4 50 (25%)
Grade
    I 68 (34%)
    II 68 (34%)
    III 64 (32%)
Tumor Response 61 (32%)
    Unknown 7
Patient Died 112 (56%)
Months to Death/Censor 22.4 (15.9, 24.0)
1 n (%); Median (Q1, Q3)
library(gtsummary)
data("swiss")

Swiss data

Univariate Analysis

Table Summary

swiss %>%
tbl_summary
Characteristic N = 471
Fertility 70 (64, 79)
Agriculture 54 (35, 68)
Examination 16 (12, 22)
Education 8 (6, 12)
Catholic 15 (5, 93)
Infant.Mortality 20.00 (18.10, 22.20)
1 Median (Q1, Q3)

Interpretation

Interpretation of Median (Q1, Q3):

Fertility: 70 (64, 79) → The typical fertility rate is 70, with 50% of values lying between 64 and 79. Fertility levels are relatively high overall.

Agriculture: 54 (35, 68) → Median agricultural workforce participation is 54%, with half of countries/units ranging between 35% and 68%. This shows moderate to high agricultural dependence.

Examination: 16 (12, 22) → Median examination score is 16, with interquartile range 12–22. This suggests relatively low but somewhat spread performance levels.

Education: 8 (6, 12) → Median years of education (or related index) is 8, with 50% of cases between 6 and 12 years. Education levels are low overall.

Catholic: 15 (5, 93) → Median Catholic population proportion is 15%, but Q1–Q3 range is 5%–93%, showing very wide variability. Some countries have very small, while others very large Catholic populations.

Infant Mortality: 20.00 (18.10, 22.20) → Median infant mortality is 20 per 1,000 live births, with 50% of countries between 18.1 and 22.2. Variation is relatively narrow compared to other variables.

Overall summary:

Fertility is high and strongly linked with high agriculture and low education/examination levels.

Catholic percentage shows extreme variation, suggesting cultural/religious diversity.

Infant mortality rates are moderate but with relatively little spread.

The median and IQR values provide a snapshot of central tendency and dispersion, highlighting contrasts between relatively stable indicators (Infant Mortality, Education) and highly variable ones (Catholic, Agriculture).

Bivariate Analysis

A. Cross Table Summary

swiss %>%
tbl_summary(
by = Fertility)
Characteristic 35
N = 1
1
42.8
N = 1
1
44.7
N = 1
1
54.3
N = 1
1
55.7
N = 1
1
56.6
N = 1
1
57.4
N = 1
1
58.3
N = 1
1
60.5
N = 1
1
61.7
N = 1
1
64.1
N = 1
1
64.4
N = 1
1
65
N = 2
1
65.1
N = 1
1
65.4
N = 1
1
65.5
N = 1
1
65.7
N = 1
1
66.9
N = 1
1
67.6
N = 1
1
68.3
N = 1
1
68.9
N = 1
1
69.3
N = 1
1
70.4
N = 1
1
70.5
N = 1
1
71.7
N = 1
1
72
N = 1
1
72.5
N = 1
1
72.7
N = 1
1
74.2
N = 1
1
75.5
N = 1
1
76.1
N = 1
1
76.9
N = 1
1
77.3
N = 1
1
77.6
N = 1
1
79.3
N = 1
1
79.4
N = 1
1
80.2
N = 1
1
82.4
N = 1
1
82.9
N = 1
1
83.1
N = 1
1
83.8
N = 1
1
85.8
N = 1
1
87.1
N = 1
1
92.2
N = 1
1
92.4
N = 1
1
92.5
N = 1
1
Agriculture 1 (1, 1) 28 (28, 28) 47 (47, 47) 15 (15, 15) 19 (19, 19) 51 (51, 51) 54 (54, 54) 27 (27, 27) 61 (61, 61) 69 (69, 69) 62 (62, 62) 18 (18, 18) 66 (55, 76) 73 (73, 73) 50 (50, 50) 60 (60, 60) 8 (8, 8) 68 (68, 68) 19 (19, 19) 73 (73, 73) 61 (61, 61) 85 (85, 85) 38 (38, 38) 78 (78, 78) 34 (34, 34) 64 (64, 64) 71 (71, 71) 17 (17, 17) 58 (58, 58) 86 (86, 86) 35 (35, 35) 44 (44, 44) 90 (90, 90) 38 (38, 38) 63 (63, 63) 65 (65, 65) 17 (17, 17) 53 (53, 53) 45 (45, 45) 45 (45, 45) 70 (70, 70) 37 (37, 37) 65 (65, 65) 85 (85, 85) 68 (68, 68) 40 (40, 40)
Examination 37 (37, 37) 22 (22, 22) 16 (16, 16) 31 (31, 31) 26 (26, 26) 22 (22, 22) 20 (20, 20) 25 (25, 25) 16 (16, 16) 22 (22, 22) 21 (21, 21) 35 (35, 35) 12 (9, 14) 19 (19, 19) 15 (15, 15) 22 (22, 22) 29 (29, 29) 14 (14, 14) 25 (25, 25) 18 (18, 18) 19 (19, 19) 7 (7, 7) 26 (26, 26) 12 (12, 12) 17 (17, 17) 6 (6, 6) 12 (12, 12) 22 (22, 22) 14 (14, 14) 3 (3, 3) 9 (9, 9) 17 (17, 17) 5 (5, 5) 15 (15, 15) 13 (13, 13) 7 (7, 7) 15 (15, 15) 12 (12, 12) 16 (16, 16) 6 (6, 6) 16 (16, 16) 12 (12, 12) 14 (14, 14) 3 (3, 3) 14 (14, 14) 5 (5, 5)
Education 53 (53, 53) 29 (29, 29) 29 (29, 29) 20 (20, 20) 28 (28, 28) 12 (12, 12) 6 (6, 6) 19 (19, 19) 10 (10, 10) 5 (5, 5) 12 (12, 12) 32 (32, 32) 6 (3, 9) 9 (9, 9) 8 (8, 8) 10 (10, 10) 11 (11, 11) 7 (7, 7) 7 (7, 7) 2 (2, 2) 12 (12, 12) 6 (6, 6) 12 (12, 12) 6 (6, 6) 8 (8, 8) 3 (3, 3) 1 (1, 1) 13 (13, 13) 8 (8, 8) 2 (2, 2) 7 (7, 7) 15 (15, 15) 2 (2, 2) 7 (7, 7) 13 (13, 13) 3 (3, 3) 12 (12, 12) 7 (7, 7) 13 (13, 13) 9 (9, 9) 7 (7, 7) 7 (7, 7) 6 (6, 6) 3 (3, 3) 8 (8, 8) 5 (5, 5)
Catholic 42 (42, 42) 58 (58, 58) 50 (50, 50) 2 (2, 2) 12 (12, 12) 15 (15, 15) 4 (4, 4) 18 (18, 18) 8 (8, 8) 3 (3, 3) 9 (9, 9) 17 (17, 17) 52 (5, 99) 3 (3, 3) 6 (6, 6) 5 (5, 5) 14 (14, 14) 2 (2, 2) 9 (9, 9) 24 (24, 24) 4 (4, 4) 100 (100, 100) 6 (6, 6) 99 (99, 99) 3 (3, 3) 3 (3, 3) 2 (2, 2) 11 (11, 11) 5 (5, 5) 100 (100, 100) 91 (91, 91) 5 (5, 5) 100 (100, 100) 5 (5, 5) 97 (97, 97) 98 (98, 98) 10 (10, 10) 98 (98, 98) 91 (91, 91) 85 (85, 85) 93 (93, 93) 34 (34, 34) 99 (99, 99) 99 (99, 99) 97 (97, 97) 93 (93, 93)
Infant.Mortality 18.00 (18.00, 18.00) 19.30 (19.30, 19.30) 18.20 (18.20, 18.20) 10.80 (10.80, 10.80) 20.20 (20.20, 20.20) 16.70 (16.70, 16.70) 15.30 (15.30, 15.30) 20.90 (20.90, 20.90) 16.30 (16.30, 16.30) 18.70 (18.70, 18.70) 16.50 (16.50, 16.50) 23.00 (23.00, 23.00) 20.10 (17.80, 22.40) 20.00 (20.00, 20.00) 22.50 (22.50, 22.50) 18.00 (18.00, 18.00) 20.50 (20.50, 20.50) 19.10 (19.10, 19.10) 19.50 (19.50, 19.50) 21.20 (21.20, 21.20) 22.70 (22.70, 22.70) 19.80 (19.80, 19.80) 20.30 (20.30, 20.30) 19.40 (19.40, 19.40) 20.00 (20.00, 20.00) 18.00 (18.00, 18.00) 21.00 (21.00, 21.00) 18.90 (18.90, 18.90) 23.80 (23.80, 23.80) 15.10 (15.10, 15.10) 26.60 (26.60, 26.60) 20.60 (20.60, 20.60) 18.30 (18.30, 18.30) 20.00 (20.00, 20.00) 18.10 (18.10, 18.10) 20.20 (20.20, 20.20) 22.20 (22.20, 22.20) 21.00 (21.00, 21.00) 24.40 (24.40, 24.40) 22.20 (22.20, 22.20) 23.60 (23.60, 23.60) 20.30 (20.30, 20.30) 24.50 (24.50, 24.50) 16.30 (16.30, 16.30) 24.90 (24.90, 24.90) 20.20 (20.20, 20.20)
1 Median (Q1, Q3)

A. Interpretation

Interpretation

Agriculture → The median agricultural workforce participation varies widely across countries (e.g., values range from very low like 1% to very high like 85–90%). This shows a large diversity in dependence on agriculture.

Examination → Median exam scores are generally low to moderate (around 12–22), with some very low outliers (3–6). This suggests variation in education system effectiveness or performance levels.

Education → Median years of education are mostly low (6–12 years), with some countries showing extremely low values (1–3 years) and a few higher (15+ years). This reflects large inequality in educational attainment.

Catholic → The Catholic population proportion is highly variable: some countries have very low (<5%), while others are almost entirely Catholic (90–100%). This indicates huge religious demographic diversity.

Infant Mortality → Median infant mortality is around 18–22 deaths per 1,000 live births. The interquartile ranges are relatively narrow, showing less variability compared to other indicators. However, a few countries still show higher rates (>25 per 1,000).

Overall Summary

Fertility-related indicators (agriculture, education, examination) show big contrasts, reflecting socioeconomic differences across countries.

Religious composition (Catholic) is extremely diverse, suggesting it could strongly influence cross-country comparisons.

Infant mortality is more stable across countries but still highlights a health burden in certain places.

B. All Statistic (including p-value)

swiss %>%
tbl_summary(by = Fertility) %>%
add_p() %>%
add_overall() %>%
add_n() %>%
modify_header(label ~ "**Variable**") %>%
modify_spanning_header(c("stat_1", "stat_2") ~ "**Treatment Received**") %>%
modify_footnote(
all_stat_cols() ~ "Median (IQR) or Frequency (%)"
) %>%
modify_caption("**Table 1. Patient Characteristics**") %>%
bold_labels()
Table 1. Patient Characteristics
Variable N Overall
N = 47
1
Treatment Received
44.7
N = 1
1
54.3
N = 1
1
55.7
N = 1
1
56.6
N = 1
1
57.4
N = 1
1
58.3
N = 1
1
60.5
N = 1
1
61.7
N = 1
1
64.1
N = 1
1
64.4
N = 1
1
65
N = 2
1
65.1
N = 1
1
65.4
N = 1
1
65.5
N = 1
1
65.7
N = 1
1
66.9
N = 1
1
67.6
N = 1
1
68.3
N = 1
1
68.9
N = 1
1
69.3
N = 1
1
70.4
N = 1
1
70.5
N = 1
1
71.7
N = 1
1
72
N = 1
1
72.5
N = 1
1
72.7
N = 1
1
74.2
N = 1
1
75.5
N = 1
1
76.1
N = 1
1
76.9
N = 1
1
77.3
N = 1
1
77.6
N = 1
1
79.3
N = 1
1
79.4
N = 1
1
80.2
N = 1
1
82.4
N = 1
1
82.9
N = 1
1
83.1
N = 1
1
83.8
N = 1
1
85.8
N = 1
1
87.1
N = 1
1
92.2
N = 1
1
92.4
N = 1
1
92.5
N = 1
1
p-value2
35
N = 1
1
42.8
N = 1
1
Agriculture 47 54 (35, 68) 1 (1, 1) 28 (28, 28) 47 (47, 47) 15 (15, 15) 19 (19, 19) 51 (51, 51) 54 (54, 54) 27 (27, 27) 61 (61, 61) 69 (69, 69) 62 (62, 62) 18 (18, 18) 66 (55, 76) 73 (73, 73) 50 (50, 50) 60 (60, 60) 8 (8, 8) 68 (68, 68) 19 (19, 19) 73 (73, 73) 61 (61, 61) 85 (85, 85) 38 (38, 38) 78 (78, 78) 34 (34, 34) 64 (64, 64) 71 (71, 71) 17 (17, 17) 58 (58, 58) 86 (86, 86) 35 (35, 35) 44 (44, 44) 90 (90, 90) 38 (38, 38) 63 (63, 63) 65 (65, 65) 17 (17, 17) 53 (53, 53) 45 (45, 45) 45 (45, 45) 70 (70, 70) 37 (37, 37) 65 (65, 65) 85 (85, 85) 68 (68, 68) 40 (40, 40) 0.5
Examination 47 16 (12, 22) 37 (37, 37) 22 (22, 22) 16 (16, 16) 31 (31, 31) 26 (26, 26) 22 (22, 22) 20 (20, 20) 25 (25, 25) 16 (16, 16) 22 (22, 22) 21 (21, 21) 35 (35, 35) 12 (9, 14) 19 (19, 19) 15 (15, 15) 22 (22, 22) 29 (29, 29) 14 (14, 14) 25 (25, 25) 18 (18, 18) 19 (19, 19) 7 (7, 7) 26 (26, 26) 12 (12, 12) 17 (17, 17) 6 (6, 6) 12 (12, 12) 22 (22, 22) 14 (14, 14) 3 (3, 3) 9 (9, 9) 17 (17, 17) 5 (5, 5) 15 (15, 15) 13 (13, 13) 7 (7, 7) 15 (15, 15) 12 (12, 12) 16 (16, 16) 6 (6, 6) 16 (16, 16) 12 (12, 12) 14 (14, 14) 3 (3, 3) 14 (14, 14) 5 (5, 5) 0.4
Education 47 8 (6, 12) 53 (53, 53) 29 (29, 29) 29 (29, 29) 20 (20, 20) 28 (28, 28) 12 (12, 12) 6 (6, 6) 19 (19, 19) 10 (10, 10) 5 (5, 5) 12 (12, 12) 32 (32, 32) 6 (3, 9) 9 (9, 9) 8 (8, 8) 10 (10, 10) 11 (11, 11) 7 (7, 7) 7 (7, 7) 2 (2, 2) 12 (12, 12) 6 (6, 6) 12 (12, 12) 6 (6, 6) 8 (8, 8) 3 (3, 3) 1 (1, 1) 13 (13, 13) 8 (8, 8) 2 (2, 2) 7 (7, 7) 15 (15, 15) 2 (2, 2) 7 (7, 7) 13 (13, 13) 3 (3, 3) 12 (12, 12) 7 (7, 7) 13 (13, 13) 9 (9, 9) 7 (7, 7) 7 (7, 7) 6 (6, 6) 3 (3, 3) 8 (8, 8) 5 (5, 5) 0.5
Catholic 47 15 (5, 93) 42 (42, 42) 58 (58, 58) 50 (50, 50) 2 (2, 2) 12 (12, 12) 15 (15, 15) 4 (4, 4) 18 (18, 18) 8 (8, 8) 3 (3, 3) 9 (9, 9) 17 (17, 17) 52 (5, 99) 3 (3, 3) 6 (6, 6) 5 (5, 5) 14 (14, 14) 2 (2, 2) 9 (9, 9) 24 (24, 24) 4 (4, 4) 100 (100, 100) 6 (6, 6) 99 (99, 99) 3 (3, 3) 3 (3, 3) 2 (2, 2) 11 (11, 11) 5 (5, 5) 100 (100, 100) 91 (91, 91) 5 (5, 5) 100 (100, 100) 5 (5, 5) 97 (97, 97) 98 (98, 98) 10 (10, 10) 98 (98, 98) 91 (91, 91) 85 (85, 85) 93 (93, 93) 34 (34, 34) 99 (99, 99) 99 (99, 99) 97 (97, 97) 93 (93, 93) 0.6
Infant.Mortality 47 20.00 (18.10, 22.20) 18.00 (18.00, 18.00) 19.30 (19.30, 19.30) 18.20 (18.20, 18.20) 10.80 (10.80, 10.80) 20.20 (20.20, 20.20) 16.70 (16.70, 16.70) 15.30 (15.30, 15.30) 20.90 (20.90, 20.90) 16.30 (16.30, 16.30) 18.70 (18.70, 18.70) 16.50 (16.50, 16.50) 23.00 (23.00, 23.00) 20.10 (17.80, 22.40) 20.00 (20.00, 20.00) 22.50 (22.50, 22.50) 18.00 (18.00, 18.00) 20.50 (20.50, 20.50) 19.10 (19.10, 19.10) 19.50 (19.50, 19.50) 21.20 (21.20, 21.20) 22.70 (22.70, 22.70) 19.80 (19.80, 19.80) 20.30 (20.30, 20.30) 19.40 (19.40, 19.40) 20.00 (20.00, 20.00) 18.00 (18.00, 18.00) 21.00 (21.00, 21.00) 18.90 (18.90, 18.90) 23.80 (23.80, 23.80) 15.10 (15.10, 15.10) 26.60 (26.60, 26.60) 20.60 (20.60, 20.60) 18.30 (18.30, 18.30) 20.00 (20.00, 20.00) 18.10 (18.10, 18.10) 20.20 (20.20, 20.20) 22.20 (22.20, 22.20) 21.00 (21.00, 21.00) 24.40 (24.40, 24.40) 22.20 (22.20, 22.20) 23.60 (23.60, 23.60) 20.30 (20.30, 20.30) 24.50 (24.50, 24.50) 16.30 (16.30, 16.30) 24.90 (24.90, 24.90) 20.20 (20.20, 20.20) 0.5
1 Median (IQR) or Frequency (%)
2 Kruskal-Wallis rank sum test

B. Interpretation

Interpretation:

Agriculture: Median = 54% (IQR 35–68). Variation exists across countries, but the p = 0.5 means no significant difference between groups.

Examination: Median = 16 (IQR 12–22). Some variation, but p = 0.4 indicates no group differences.

Education: Median = 8 years (IQR 6–12). Overall low education levels; p = 0.5 suggests no significant variation across groups.

Catholic: Median = 15% (IQR 5–93). Very wide spread, but p = 0.6 means differences are not statistically significant.

Infant Mortality: Median = 20 (IQR 18.1–22.2). Relatively narrow variation; p = 0.5 confirms no group differences.

Overall conclusion

Across all five characteristics, the Kruskal–Wallis tests found no statistically significant differences (all p > 0.05). This means the distributions of Agriculture, Examination, Education, Catholic, and Infant Mortality are similar across the compared groups, and observed differences are likely due to chance rather than real group effects.

Add Common Statistics

swiss %>%
tbl_summary(
by = Fertility,
statistic = list(
all_continuous() ~ "{mean} ({sd})",
all_categorical() ~ "{n} / {N} ({p}%)"
)
)
Characteristic 35
N = 1
1
42.8
N = 1
1
44.7
N = 1
1
54.3
N = 1
1
55.7
N = 1
1
56.6
N = 1
1
57.4
N = 1
1
58.3
N = 1
1
60.5
N = 1
1
61.7
N = 1
1
64.1
N = 1
1
64.4
N = 1
1
65
N = 2
1
65.1
N = 1
1
65.4
N = 1
1
65.5
N = 1
1
65.7
N = 1
1
66.9
N = 1
1
67.6
N = 1
1
68.3
N = 1
1
68.9
N = 1
1
69.3
N = 1
1
70.4
N = 1
1
70.5
N = 1
1
71.7
N = 1
1
72
N = 1
1
72.5
N = 1
1
72.7
N = 1
1
74.2
N = 1
1
75.5
N = 1
1
76.1
N = 1
1
76.9
N = 1
1
77.3
N = 1
1
77.6
N = 1
1
79.3
N = 1
1
79.4
N = 1
1
80.2
N = 1
1
82.4
N = 1
1
82.9
N = 1
1
83.1
N = 1
1
83.8
N = 1
1
85.8
N = 1
1
87.1
N = 1
1
92.2
N = 1
1
92.4
N = 1
1
92.5
N = 1
1
Agriculture 1 (NA) 28 (NA) 47 (NA) 15 (NA) 19 (NA) 51 (NA) 54 (NA) 27 (NA) 61 (NA) 69 (NA) 62 (NA) 18 (NA) 66 (15) 73 (NA) 50 (NA) 60 (NA) 8 (NA) 68 (NA) 19 (NA) 73 (NA) 61 (NA) 85 (NA) 38 (NA) 78 (NA) 34 (NA) 64 (NA) 71 (NA) 17 (NA) 58 (NA) 86 (NA) 35 (NA) 44 (NA) 90 (NA) 38 (NA) 63 (NA) 65 (NA) 17 (NA) 53 (NA) 45 (NA) 45 (NA) 70 (NA) 37 (NA) 65 (NA) 85 (NA) 68 (NA) 40 (NA)
Examination 37 (NA) 22 (NA) 16 (NA) 31 (NA) 26 (NA) 22 (NA) 20 (NA) 25 (NA) 16 (NA) 22 (NA) 21 (NA) 35 (NA) 12 (4) 19 (NA) 15 (NA) 22 (NA) 29 (NA) 14 (NA) 25 (NA) 18 (NA) 19 (NA) 7 (NA) 26 (NA) 12 (NA) 17 (NA) 6 (NA) 12 (NA) 22 (NA) 14 (NA) 3 (NA) 9 (NA) 17 (NA) 5 (NA) 15 (NA) 13 (NA) 7 (NA) 15 (NA) 12 (NA) 16 (NA) 6 (NA) 16 (NA) 12 (NA) 14 (NA) 3 (NA) 14 (NA) 5 (NA)
Education 53 (NA) 29 (NA) 29 (NA) 20 (NA) 28 (NA) 12 (NA) 6 (NA) 19 (NA) 10 (NA) 5 (NA) 12 (NA) 32 (NA) 6 (4) 9 (NA) 8 (NA) 10 (NA) 11 (NA) 7 (NA) 7 (NA) 2 (NA) 12 (NA) 6 (NA) 12 (NA) 6 (NA) 8 (NA) 3 (NA) 1 (NA) 13 (NA) 8 (NA) 2 (NA) 7 (NA) 15 (NA) 2 (NA) 7 (NA) 13 (NA) 3 (NA) 12 (NA) 7 (NA) 13 (NA) 9 (NA) 7 (NA) 7 (NA) 6 (NA) 3 (NA) 8 (NA) 5 (NA)
Catholic 42 (NA) 58 (NA) 50 (NA) 2 (NA) 12 (NA) 15 (NA) 4 (NA) 18 (NA) 8 (NA) 3 (NA) 9 (NA) 17 (NA) 52 (67) 3 (NA) 6 (NA) 5 (NA) 14 (NA) 2 (NA) 9 (NA) 24 (NA) 4 (NA) 100 (NA) 6 (NA) 99 (NA) 3 (NA) 3 (NA) 2 (NA) 11 (NA) 5 (NA) 100 (NA) 91 (NA) 5 (NA) 100 (NA) 5 (NA) 97 (NA) 98 (NA) 10 (NA) 98 (NA) 91 (NA) 85 (NA) 93 (NA) 34 (NA) 99 (NA) 99 (NA) 97 (NA) 93 (NA)
Infant.Mortality 18.00 (NA) 19.30 (NA) 18.20 (NA) 10.80 (NA) 20.20 (NA) 16.70 (NA) 15.30 (NA) 20.90 (NA) 16.30 (NA) 18.70 (NA) 16.50 (NA) 23.00 (NA) 20.10 (3.25) 20.00 (NA) 22.50 (NA) 18.00 (NA) 20.50 (NA) 19.10 (NA) 19.50 (NA) 21.20 (NA) 22.70 (NA) 19.80 (NA) 20.30 (NA) 19.40 (NA) 20.00 (NA) 18.00 (NA) 21.00 (NA) 18.90 (NA) 23.80 (NA) 15.10 (NA) 26.60 (NA) 20.60 (NA) 18.30 (NA) 20.00 (NA) 18.10 (NA) 20.20 (NA) 22.20 (NA) 21.00 (NA) 24.40 (NA) 22.20 (NA) 23.60 (NA) 20.30 (NA) 24.50 (NA) 16.30 (NA) 24.90 (NA) 20.20 (NA)
1 Mean (SD)

Interpretation

Interpretation

Agriculture: Mean values range from very low (≈1%) to very high (≈90%). This indicates large variation in agricultural dependence among groups.

Examination: Scores range from very low (≈3–7) to relatively higher (≈30+). This shows considerable differences in educational performance across groups.

Education: Mean years of education range from as low as 1–3 years to 15+ years, reflecting strong inequality in educational attainment between groups.

Catholic: The proportion of Catholic population varies from almost none (≈2–5%) to almost entire (≈90–100%). This confirms extreme diversity in religious composition among countries/regions.

Infant Mortality: Mean values cluster around 18–22 deaths per 1,000 live births, with some groups lower (≈10–15) and some higher (≈25+). This shows moderate variation in child health outcomes.

Overall conclusion

The results show substantial variation in agriculture, education, examination scores, and Catholic population across groups.

Infant mortality is relatively consistent but still highlights health inequalities.

The wide spread of means across groups suggests socioeconomic and demographic diversity rather than uniform trends.

👉 Would you like me to also connect this back to the statistical test results (p-values) from the earlier Kruskal–Wallis analysis, so it reads like a proper “Results” section in a thesis or article?

C. multilayer statisticS

swiss %>%
tbl_summary(
by = Fertility,
type = all_continuous() ~ "continuous2",
statistic = all_continuous() ~ c(
"{N_nonmiss}",
"{median} ({p25}, {p75})",
"{min}, {max}"
),
missing = "no"
) %>%
add_p(pvalue_fun = ~ style_pvalue(.x, digits = 2))
Characteristic 35
N = 1
42.8
N = 1
44.7
N = 1
54.3
N = 1
55.7
N = 1
56.6
N = 1
57.4
N = 1
58.3
N = 1
60.5
N = 1
61.7
N = 1
64.1
N = 1
64.4
N = 1
65
N = 2
65.1
N = 1
65.4
N = 1
65.5
N = 1
65.7
N = 1
66.9
N = 1
67.6
N = 1
68.3
N = 1
68.9
N = 1
69.3
N = 1
70.4
N = 1
70.5
N = 1
71.7
N = 1
72
N = 1
72.5
N = 1
72.7
N = 1
74.2
N = 1
75.5
N = 1
76.1
N = 1
76.9
N = 1
77.3
N = 1
77.6
N = 1
79.3
N = 1
79.4
N = 1
80.2
N = 1
82.4
N = 1
82.9
N = 1
83.1
N = 1
83.8
N = 1
85.8
N = 1
87.1
N = 1
92.2
N = 1
92.4
N = 1
92.5
N = 1
p-value1
Agriculture













































0.46
    N Non-missing 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    Median (Q1, Q3) 1 (1, 1) 28 (28, 28) 47 (47, 47) 15 (15, 15) 19 (19, 19) 51 (51, 51) 54 (54, 54) 27 (27, 27) 61 (61, 61) 69 (69, 69) 62 (62, 62) 18 (18, 18) 66 (55, 76) 73 (73, 73) 50 (50, 50) 60 (60, 60) 8 (8, 8) 68 (68, 68) 19 (19, 19) 73 (73, 73) 61 (61, 61) 85 (85, 85) 38 (38, 38) 78 (78, 78) 34 (34, 34) 64 (64, 64) 71 (71, 71) 17 (17, 17) 58 (58, 58) 86 (86, 86) 35 (35, 35) 44 (44, 44) 90 (90, 90) 38 (38, 38) 63 (63, 63) 65 (65, 65) 17 (17, 17) 53 (53, 53) 45 (45, 45) 45 (45, 45) 70 (70, 70) 37 (37, 37) 65 (65, 65) 85 (85, 85) 68 (68, 68) 40 (40, 40)
    Min, Max 1, 1 28, 28 47, 47 15, 15 19, 19 51, 51 54, 54 27, 27 61, 61 69, 69 62, 62 18, 18 55, 76 73, 73 50, 50 60, 60 8, 8 68, 68 19, 19 73, 73 61, 61 85, 85 38, 38 78, 78 34, 34 64, 64 71, 71 17, 17 58, 58 86, 86 35, 35 44, 44 90, 90 38, 38 63, 63 65, 65 17, 17 53, 53 45, 45 45, 45 70, 70 37, 37 65, 65 85, 85 68, 68 40, 40
Examination













































0.44
    N Non-missing 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    Median (Q1, Q3) 37 (37, 37) 22 (22, 22) 16 (16, 16) 31 (31, 31) 26 (26, 26) 22 (22, 22) 20 (20, 20) 25 (25, 25) 16 (16, 16) 22 (22, 22) 21 (21, 21) 35 (35, 35) 12 (9, 14) 19 (19, 19) 15 (15, 15) 22 (22, 22) 29 (29, 29) 14 (14, 14) 25 (25, 25) 18 (18, 18) 19 (19, 19) 7 (7, 7) 26 (26, 26) 12 (12, 12) 17 (17, 17) 6 (6, 6) 12 (12, 12) 22 (22, 22) 14 (14, 14) 3 (3, 3) 9 (9, 9) 17 (17, 17) 5 (5, 5) 15 (15, 15) 13 (13, 13) 7 (7, 7) 15 (15, 15) 12 (12, 12) 16 (16, 16) 6 (6, 6) 16 (16, 16) 12 (12, 12) 14 (14, 14) 3 (3, 3) 14 (14, 14) 5 (5, 5)
    Min, Max 37, 37 22, 22 16, 16 31, 31 26, 26 22, 22 20, 20 25, 25 16, 16 22, 22 21, 21 35, 35 9, 14 19, 19 15, 15 22, 22 29, 29 14, 14 25, 25 18, 18 19, 19 7, 7 26, 26 12, 12 17, 17 6, 6 12, 12 22, 22 14, 14 3, 3 9, 9 17, 17 5, 5 15, 15 13, 13 7, 7 15, 15 12, 12 16, 16 6, 6 16, 16 12, 12 14, 14 3, 3 14, 14 5, 5
Education













































0.48
    N Non-missing 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    Median (Q1, Q3) 53 (53, 53) 29 (29, 29) 29 (29, 29) 20 (20, 20) 28 (28, 28) 12 (12, 12) 6 (6, 6) 19 (19, 19) 10 (10, 10) 5 (5, 5) 12 (12, 12) 32 (32, 32) 6 (3, 9) 9 (9, 9) 8 (8, 8) 10 (10, 10) 11 (11, 11) 7 (7, 7) 7 (7, 7) 2 (2, 2) 12 (12, 12) 6 (6, 6) 12 (12, 12) 6 (6, 6) 8 (8, 8) 3 (3, 3) 1 (1, 1) 13 (13, 13) 8 (8, 8) 2 (2, 2) 7 (7, 7) 15 (15, 15) 2 (2, 2) 7 (7, 7) 13 (13, 13) 3 (3, 3) 12 (12, 12) 7 (7, 7) 13 (13, 13) 9 (9, 9) 7 (7, 7) 7 (7, 7) 6 (6, 6) 3 (3, 3) 8 (8, 8) 5 (5, 5)
    Min, Max 53, 53 29, 29 29, 29 20, 20 28, 28 12, 12 6, 6 19, 19 10, 10 5, 5 12, 12 32, 32 3, 9 9, 9 8, 8 10, 10 11, 11 7, 7 7, 7 2, 2 12, 12 6, 6 12, 12 6, 6 8, 8 3, 3 1, 1 13, 13 8, 8 2, 2 7, 7 15, 15 2, 2 7, 7 13, 13 3, 3 12, 12 7, 7 13, 13 9, 9 7, 7 7, 7 6, 6 3, 3 8, 8 5, 5
Catholic













































0.55
    N Non-missing 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    Median (Q1, Q3) 42 (42, 42) 58 (58, 58) 50 (50, 50) 2 (2, 2) 12 (12, 12) 15 (15, 15) 4 (4, 4) 18 (18, 18) 8 (8, 8) 3 (3, 3) 9 (9, 9) 17 (17, 17) 52 (5, 99) 3 (3, 3) 6 (6, 6) 5 (5, 5) 14 (14, 14) 2 (2, 2) 9 (9, 9) 24 (24, 24) 4 (4, 4) 100 (100, 100) 6 (6, 6) 99 (99, 99) 3 (3, 3) 3 (3, 3) 2 (2, 2) 11 (11, 11) 5 (5, 5) 100 (100, 100) 91 (91, 91) 5 (5, 5) 100 (100, 100) 5 (5, 5) 97 (97, 97) 98 (98, 98) 10 (10, 10) 98 (98, 98) 91 (91, 91) 85 (85, 85) 93 (93, 93) 34 (34, 34) 99 (99, 99) 99 (99, 99) 97 (97, 97) 93 (93, 93)
    Min, Max 42, 42 58, 58 50, 50 2, 2 12, 12 15, 15 4, 4 18, 18 8, 8 3, 3 9, 9 17, 17 5, 99 3, 3 6, 6 5, 5 14, 14 2, 2 9, 9 24, 24 4, 4 100, 100 6, 6 99, 99 3, 3 3, 3 2, 2 11, 11 5, 5 100, 100 91, 91 5, 5 100, 100 5, 5 97, 97 98, 98 10, 10 98, 98 91, 91 85, 85 93, 93 34, 34 99, 99 99, 99 97, 97 93, 93
Infant.Mortality













































0.53
    N Non-missing 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
    Median (Q1, Q3) 18.00 (18.00, 18.00) 19.30 (19.30, 19.30) 18.20 (18.20, 18.20) 10.80 (10.80, 10.80) 20.20 (20.20, 20.20) 16.70 (16.70, 16.70) 15.30 (15.30, 15.30) 20.90 (20.90, 20.90) 16.30 (16.30, 16.30) 18.70 (18.70, 18.70) 16.50 (16.50, 16.50) 23.00 (23.00, 23.00) 20.10 (17.80, 22.40) 20.00 (20.00, 20.00) 22.50 (22.50, 22.50) 18.00 (18.00, 18.00) 20.50 (20.50, 20.50) 19.10 (19.10, 19.10) 19.50 (19.50, 19.50) 21.20 (21.20, 21.20) 22.70 (22.70, 22.70) 19.80 (19.80, 19.80) 20.30 (20.30, 20.30) 19.40 (19.40, 19.40) 20.00 (20.00, 20.00) 18.00 (18.00, 18.00) 21.00 (21.00, 21.00) 18.90 (18.90, 18.90) 23.80 (23.80, 23.80) 15.10 (15.10, 15.10) 26.60 (26.60, 26.60) 20.60 (20.60, 20.60) 18.30 (18.30, 18.30) 20.00 (20.00, 20.00) 18.10 (18.10, 18.10) 20.20 (20.20, 20.20) 22.20 (22.20, 22.20) 21.00 (21.00, 21.00) 24.40 (24.40, 24.40) 22.20 (22.20, 22.20) 23.60 (23.60, 23.60) 20.30 (20.30, 20.30) 24.50 (24.50, 24.50) 16.30 (16.30, 16.30) 24.90 (24.90, 24.90) 20.20 (20.20, 20.20)
    Min, Max 18.00, 18.00 19.30, 19.30 18.20, 18.20 10.80, 10.80 20.20, 20.20 16.70, 16.70 15.30, 15.30 20.90, 20.90 16.30, 16.30 18.70, 18.70 16.50, 16.50 23.00, 23.00 17.80, 22.40 20.00, 20.00 22.50, 22.50 18.00, 18.00 20.50, 20.50 19.10, 19.10 19.50, 19.50 21.20, 21.20 22.70, 22.70 19.80, 19.80 20.30, 20.30 19.40, 19.40 20.00, 20.00 18.00, 18.00 21.00, 21.00 18.90, 18.90 23.80, 23.80 15.10, 15.10 26.60, 26.60 20.60, 20.60 18.30, 18.30 20.00, 20.00 18.10, 18.10 20.20, 20.20 22.20, 22.20 21.00, 21.00 24.40, 24.40 22.20, 22.20 23.60, 23.60 20.30, 20.30 24.50, 24.50 16.30, 16.30 24.90, 24.90 20.20, 20.20
1 Kruskal-Wallis rank sum test

C.Interpretation

Reported p-values:

Agriculture → 0.46

Examination → 0.44

Education → 0.48

Catholic → 0.55

Infant Mortality → 0.53

Interpretation:

The null hypothesis (H₀) of the Kruskal–Wallis test: all groups have the same distribution (median ranks are equal).

The alternative hypothesis (H₁): at least one group differs.

Decision rule: If p < 0.05, reject H₀ (there’s a statistically significant difference).

Since all the p-values are greater than 0.05, we fail to reject the null hypothesis.

Conclusion: There is no statistically significant difference among the groups for Agriculture, Examination, Education, Catholic, and Infant Mortality. In other words, the medians across groups are similar, and the observed variations are likely due to chance rather than real differences.