srdkit 1.0__tar.gz → 1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. {srdkit-1.0 → srdkit-1.1}/.gitignore +4 -0
  2. srdkit-1.1/CHANGELOG.md +95 -0
  3. {srdkit-1.0 → srdkit-1.1}/CITATION.cff +9 -1
  4. {srdkit-1.0 → srdkit-1.1}/PKG-INFO +11 -4
  5. {srdkit-1.0 → srdkit-1.1}/README.md +10 -3
  6. {srdkit-1.0 → srdkit-1.1}/examples/01_basics/plot_01_first_srd.py +17 -8
  7. {srdkit-1.0 → srdkit-1.1}/examples/01_basics/plot_03_ties_and_ranks.py +2 -2
  8. srdkit-1.1/examples/02_validation/plot_01_exact_distribution.py +91 -0
  9. {srdkit-1.0 → srdkit-1.1}/examples/02_validation/plot_02_crrn_and_cv.py +1 -1
  10. srdkit-1.1/examples/02_validation/plot_05_bundesliga.py +59 -0
  11. {srdkit-1.0 → srdkit-1.1}/examples/03_family/plot_01_rank_distances.py +21 -0
  12. {srdkit-1.0 → srdkit-1.1}/examples/03_family/plot_02_weighted_and_topk.py +2 -2
  13. {srdkit-1.0 → srdkit-1.1}/examples/03_family/plot_03_dne_dnm.py +2 -2
  14. {srdkit-1.0 → srdkit-1.1}/examples/03_family/plot_04_beyond_ranks.py +2 -2
  15. {srdkit-1.0 → srdkit-1.1}/examples/04_decision/plot_01_usrd_emissions.py +3 -3
  16. {srdkit-1.0 → srdkit-1.1}/examples/04_decision/plot_03_mcda_consensus.py +1 -1
  17. {srdkit-1.0 → srdkit-1.1}/examples/04_decision/plot_04_nmf_srd.py +3 -3
  18. {srdkit-1.0 → srdkit-1.1}/examples/04_decision/plot_07_data_driven_weights.py +1 -1
  19. srdkit-1.1/examples/04_decision/plot_08_leiden_ranking.py +88 -0
  20. {srdkit-1.0 → srdkit-1.1}/examples/05_visualization/plot_01_parallel_coordinates.py +1 -1
  21. {srdkit-1.0 → srdkit-1.1}/examples/06_segmentation/plot_01_ranking_regimes.py +4 -4
  22. {srdkit-1.0 → srdkit-1.1}/examples/07_fusion/plot_01_merit_fusion.py +1 -1
  23. {srdkit-1.0 → srdkit-1.1}/examples/07_fusion/plot_02_outliers_and_roc.py +1 -1
  24. {srdkit-1.0 → srdkit-1.1}/examples/07_fusion/plot_03_gpcm.py +1 -1
  25. {srdkit-1.0 → srdkit-1.1}/pyproject.toml +1 -1
  26. srdkit-1.1/src/srdkit/_version.py +1 -0
  27. {srdkit-1.0 → srdkit-1.1}/src/srdkit/anova.py +1 -1
  28. {srdkit-1.0 → srdkit-1.1}/src/srdkit/core.py +15 -6
  29. {srdkit-1.0 → srdkit-1.1}/src/srdkit/datasets/__init__.py +70 -2
  30. srdkit-1.1/src/srdkit/datasets/data/bundesliga_2020_21.csv +19 -0
  31. srdkit-1.1/src/srdkit/datasets/data/leiden_ranking_2020.csv.gz +0 -0
  32. {srdkit-1.0 → srdkit-1.1}/src/srdkit/diagnostics.py +5 -5
  33. {srdkit-1.0 → srdkit-1.1}/src/srdkit/distances.py +116 -1
  34. {srdkit-1.0 → srdkit-1.1}/src/srdkit/distribution.py +86 -3
  35. {srdkit-1.0 → srdkit-1.1}/src/srdkit/framework.py +1 -1
  36. {srdkit-1.0 → srdkit-1.1}/src/srdkit/representation.py +2 -2
  37. {srdkit-1.0 → srdkit-1.1}/src/srdkit/segmentation.py +2 -2
  38. {srdkit-1.0 → srdkit-1.1}/src/srdkit/validation.py +17 -7
  39. srdkit-1.1/src/srdkit/viz/_style.py +198 -0
  40. {srdkit-1.0 → srdkit-1.1}/src/srdkit/viz/applications.py +10 -2
  41. {srdkit-1.0 → srdkit-1.1}/src/srdkit/viz/basic.py +132 -37
  42. {srdkit-1.0 → srdkit-1.1}/src/srdkit/viz/maps.py +55 -6
  43. {srdkit-1.0 → srdkit-1.1}/src/srdkit/viz/validation.py +7 -5
  44. {srdkit-1.0 → srdkit-1.1}/src/srdkit/weights.py +1 -1
  45. srdkit-1.1/tests/test_v11.py +77 -0
  46. srdkit-1.0/CHANGELOG.md +0 -42
  47. srdkit-1.0/examples/02_validation/plot_01_exact_distribution.py +0 -73
  48. srdkit-1.0/src/srdkit/_version.py +0 -1
  49. srdkit-1.0/src/srdkit/viz/_style.py +0 -87
  50. {srdkit-1.0 → srdkit-1.1}/LICENSE +0 -0
  51. {srdkit-1.0 → srdkit-1.1}/examples/01_basics/README.rst +0 -0
  52. {srdkit-1.0 → srdkit-1.1}/examples/01_basics/plot_02_references.py +0 -0
  53. {srdkit-1.0 → srdkit-1.1}/examples/02_validation/README.rst +0 -0
  54. {srdkit-1.0 → srdkit-1.1}/examples/02_validation/plot_03_anova.py +0 -0
  55. {srdkit-1.0 → srdkit-1.1}/examples/02_validation/plot_04_power.py +0 -0
  56. {srdkit-1.0 → srdkit-1.1}/examples/03_family/README.rst +0 -0
  57. {srdkit-1.0 → srdkit-1.1}/examples/04_decision/README.rst +0 -0
  58. {srdkit-1.0 → srdkit-1.1}/examples/04_decision/plot_02_promethee_psrd.py +0 -0
  59. {srdkit-1.0 → srdkit-1.1}/examples/04_decision/plot_05_post_pareto.py +0 -0
  60. {srdkit-1.0 → srdkit-1.1}/examples/04_decision/plot_06_fair_comparison.py +0 -0
  61. {srdkit-1.0 → srdkit-1.1}/examples/05_visualization/README.rst +0 -0
  62. {srdkit-1.0 → srdkit-1.1}/examples/05_visualization/plot_02_maps_constellations.py +0 -0
  63. {srdkit-1.0 → srdkit-1.1}/examples/05_visualization/plot_03_heatmaps_dendrograms.py +0 -0
  64. {srdkit-1.0 → srdkit-1.1}/examples/06_segmentation/README.rst +0 -0
  65. {srdkit-1.0 → srdkit-1.1}/examples/06_segmentation/plot_02_local_agreement.py +0 -0
  66. {srdkit-1.0 → srdkit-1.1}/examples/07_fusion/README.rst +0 -0
  67. {srdkit-1.0 → srdkit-1.1}/examples/08_diagnostics/README.rst +0 -0
  68. {srdkit-1.0 → srdkit-1.1}/examples/08_diagnostics/plot_01_influence_sensitivity.py +0 -0
  69. {srdkit-1.0 → srdkit-1.1}/examples/08_diagnostics/plot_02_reduction_and_report.py +0 -0
  70. {srdkit-1.0 → srdkit-1.1}/examples/README.rst +0 -0
  71. {srdkit-1.0 → srdkit-1.1}/src/srdkit/__init__.py +0 -0
  72. {srdkit-1.0 → srdkit-1.1}/src/srdkit/_utils.py +0 -0
  73. {srdkit-1.0 → srdkit-1.1}/src/srdkit/clustering.py +0 -0
  74. {srdkit-1.0 → srdkit-1.1}/src/srdkit/datasets/data/co2_2018.csv +0 -0
  75. {srdkit-1.0 → srdkit-1.1}/src/srdkit/fusion.py +0 -0
  76. {srdkit-1.0 → srdkit-1.1}/src/srdkit/gpcm.py +0 -0
  77. {srdkit-1.0 → srdkit-1.1}/src/srdkit/mcda.py +0 -0
  78. {srdkit-1.0 → srdkit-1.1}/src/srdkit/nmf.py +0 -0
  79. {srdkit-1.0 → srdkit-1.1}/src/srdkit/parcoord.py +0 -0
  80. {srdkit-1.0 → srdkit-1.1}/src/srdkit/pareto.py +0 -0
  81. {srdkit-1.0 → srdkit-1.1}/src/srdkit/promethee.py +0 -0
  82. {srdkit-1.0 → srdkit-1.1}/src/srdkit/ranking.py +0 -0
  83. {srdkit-1.0 → srdkit-1.1}/src/srdkit/reference.py +0 -0
  84. {srdkit-1.0 → srdkit-1.1}/src/srdkit/report.py +0 -0
  85. {srdkit-1.0 → srdkit-1.1}/src/srdkit/simulate.py +0 -0
  86. {srdkit-1.0 → srdkit-1.1}/src/srdkit/tournament.py +0 -0
  87. {srdkit-1.0 → srdkit-1.1}/src/srdkit/utility.py +0 -0
  88. {srdkit-1.0 → srdkit-1.1}/src/srdkit/value.py +0 -0
  89. {srdkit-1.0 → srdkit-1.1}/src/srdkit/viz/__init__.py +0 -0
  90. {srdkit-1.0 → srdkit-1.1}/src/srdkit/viz/framework.py +0 -0
  91. {srdkit-1.0 → srdkit-1.1}/src/srdkit/weighted.py +0 -0
  92. {srdkit-1.0 → srdkit-1.1}/tests/test_applications.py +0 -0
  93. {srdkit-1.0 → srdkit-1.1}/tests/test_core.py +0 -0
  94. {srdkit-1.0 → srdkit-1.1}/tests/test_distribution.py +0 -0
  95. {srdkit-1.0 → srdkit-1.1}/tests/test_framework.py +0 -0
  96. {srdkit-1.0 → srdkit-1.1}/tests/test_validation.py +0 -0
  97. {srdkit-1.0 → srdkit-1.1}/tests/test_variants.py +0 -0
  98. {srdkit-1.0 → srdkit-1.1}/tests/test_viz.py +0 -0
@@ -51,3 +51,7 @@ docs/api/generated/
51
51
  # LaTeX intermediates of the cover
52
52
  book/cover/*.aux
53
53
  book/cover/*.log
54
+ book/*.lof
55
+ book/*.run.xml
56
+ book/*.blg
57
+ __pycache__/
@@ -0,0 +1,95 @@
1
+ # Changelog
2
+
3
+ ## 1.1 (2026-11-29)
4
+
5
+ Revisions after the review of Károly Héberger.
6
+
7
+ **Discreteness and notation**
8
+
9
+ - `SRDDistribution.brackets()` returns the two attainable values on both sides
10
+ of the 5% and 95% points (outer: still significant, inner: no longer);
11
+ `percentiles()` reports their midpoint by default (`method="mid"`; the 1.0
12
+ convention is `method="ppf"`). `percentile_table()` adds the brackets and the
13
+ lattice step `2/floor(n^2/2)`.
14
+ - SRD plots draw the 5% and 95% points as pairs of dashed lines at the
15
+ bracketing values, labelled "5%" and "95%" (XX1 and XX19 in the SRD
16
+ literature).
17
+ - "Scaled SRD" instead of "normalized SRD" in the texts; `SRDResult.scaled` and
18
+ `SRDDistribution.scaled_values` are aliases of the old attribute names.
19
+
20
+ **Rank distances**
21
+
22
+ - `distances.euclidean` (square root of the Spearman distance, a metric),
23
+ `distances.correlation_distance` (1-c, (1-c)/2, sqrt((1-c)/2), 1-|c|, 1-c^2
24
+ for Spearman's rho and Kendall's tau) and `distances.check_metric`, a
25
+ brute-force check of the metric axioms over all permutations or weak orders.
26
+
27
+ **Data and examples**
28
+
29
+ - `datasets.load_bundesliga`: the football example of the rSRD package
30
+ (reproduced exactly); `datasets.load_leiden_ranking`: 1176 universities of
31
+ the CWTS Leiden Ranking 2020 under full and fractional counting.
32
+ - New gallery examples: the Bundesliga worked example and the indicators of
33
+ the Leiden Ranking with an SRD-ANOVA of full against fractional counting.
34
+
35
+ **Figures**
36
+
37
+ - Labels no longer overlap: SRD plots move names to a row with leaders when
38
+ they would collide (also with the percentile labels) and recompute the
39
+ layout when fonts are enlarged; GAIA biplots merge coinciding criteria and
40
+ place the other labels apart; parallel-coordinate axis names, constellation
41
+ labels and cross-validation marks are spread apart.
42
+
43
+ **Book**
44
+
45
+ - Discreteness of SRD (even values, lattice step for odd and even n, exact
46
+ mean 2/3 for odd n), the normal curve as an approximation only, the
47
+ footrule coincides with SRD only without ties, the kernel of the soft ranks,
48
+ distances from correlation coefficients and their metric properties,
49
+ multicriteria and multiobjective problems treated together, an outlook on
50
+ multi-way data, and new references (Koziol 2013, Berry and Mielke 1997,
51
+ Costa and Lourenço 2026, Zafari, Ekin and Ruggeri 2026, PARAFAC and Tucker3).
52
+
53
+ ## 1.0 (2026-11-29)
54
+
55
+ First public release, together with the documentation and the book
56
+ *Sum of Ranking Differences in Python: The srdkit toolbox*.
57
+ The book is available in three editions built from the same LaTeX source:
58
+ PDF, EPUB and a web edition (https://complexsystemsintelligence.github.io/srdkit/book/)
59
+ whose figures link to the example scripts and open them in Google Colab.
60
+
61
+ **The published SRD methods**
62
+
63
+ - SRD with mid-ranks for ties, every data-fusion reference (mean, median,
64
+ minimum, maximum, mixed row rules, trimmed, weighted, geometric, mean rank),
65
+ normalization by the theoretical or attainable maximum, pairwise SRD.
66
+ - CRRN randomization test, cross-validation (random, k-fold, contiguous,
67
+ leave-one-out, bootstrap, 5x2) with Wilcoxon, Dietterich and Alpaydin tests,
68
+ SRD-ANOVA with post hoc tests.
69
+ - Weighted and top-k SRD, rank distances (Kendall, Cayley, Ulam, Hamming,
70
+ Spearman, Chebyshev, Cayley-footrule), the value-based DnE and DnM with their
71
+ randomization test and cross-validation, utility-based SRD (uSRD).
72
+ - Promethee II, P-SRD, GAIA, sparse GAIA and P-PFA; NMF-SRD many-objective
73
+ ranking; post-Pareto analysis; MCDM methods and their SRD consensus.
74
+ - SRD-ordered parallel coordinates with the deviation angle; model-merit
75
+ fusion; consensus outliers; SRD-ROC; PCM and GPCM with the conditional exact
76
+ and Williams' tests.
77
+ - SRD-derived weights and weighted references; the COVAT heatmap; the
78
+ seven-method consensus framework for fair comparison (SRD, DnE, DnM, HM,
79
+ CEpW, WtpW, power-weakness ratio).
80
+
81
+ **New in srdkit**
82
+
83
+ - Exact null distribution of SRD for any number of objects and any tie
84
+ pattern (dynamic programme over a sweep), exact moments with ties.
85
+ - Footrule-optimal (assignment) and Kemeny consensus references,
86
+ leave-one-out references.
87
+ - Corrected resampled t-test, Friedman test with critical differences,
88
+ compact letter display, power analysis.
89
+ - Soft ranks, exact normalization of weighted SRD, permutation null of DnE
90
+ and DnM, row scaling for value-based SRD.
91
+ - Self-consistent data-driven weights, SRD-based criterion weights,
92
+ proficiency-test z-scores and leave-one-method-out diagnostics.
93
+ - SRD maps and constellations, travelling-salesman orderings of parallel
94
+ coordinates, segmentation of ranking sequences and range-dependent agreement,
95
+ diagnostics, criteria reduction and one-call reports.
@@ -2,8 +2,16 @@ cff-version: 1.2.0
2
2
  message: "If you use srdkit, please cite it as below, together with the original publications of the methods you use."
3
3
  type: software
4
4
  title: "srdkit: sum of ranking differences in Python"
5
- version: "1.0"
5
+ version: "1.1"
6
6
  date-released: 2026-11-29
7
+ doi: 10.5281/zenodo.24650550
8
+ identifiers:
9
+ - type: doi
10
+ value: 10.5281/zenodo.24650551
11
+ description: "Version 1.0 (Zenodo)"
12
+ - type: doi
13
+ value: 10.5281/zenodo.24650550
14
+ description: "All versions (Zenodo concept DOI)"
7
15
  license: MIT
8
16
  repository-code: "https://github.com/ComplexSystemsIntelligence/srdkit"
9
17
  url: "https://complexsystemsintelligence.github.io/srdkit"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: srdkit
3
- Version: 1.0
3
+ Version: 1.1
4
4
  Summary: Sum of Ranking Differences (SRD) in Python: the complete SRD family (classic, tied, weighted, value-based DnE/DnM, utility-based uSRD, Promethee P-SRD, NMF-SRD), exact null distributions for any tie pattern, cross-validation tests, SRD-ANOVA, data-driven weights, a tested consensus of complementary MCDM methods, GPCM, fusion, segmentation, representation and visualization.
5
5
  Project-URL: Homepage, https://github.com/ComplexSystemsIntelligence/srdkit
6
6
  Project-URL: Documentation, https://complexsystemsintelligence.github.io/srdkit
@@ -75,7 +75,8 @@ Description-Content-Type: text/markdown
75
75
 
76
76
  [![tests](https://github.com/ComplexSystemsIntelligence/srdkit/actions/workflows/ci.yml/badge.svg)](https://github.com/ComplexSystemsIntelligence/srdkit/actions/workflows/ci.yml)
77
77
  [![docs](https://img.shields.io/badge/docs-gallery%20%2B%20API-285780)](https://complexsystemsintelligence.github.io/srdkit)
78
- [![book](https://img.shields.io/badge/book-PDF-D55E00)](https://complexsystemsintelligence.github.io/srdkit/book.html)
78
+ [![book](https://img.shields.io/badge/book-PDF%20%C2%B7%20EPUB%20%C2%B7%20web-D55E00)](https://complexsystemsintelligence.github.io/srdkit/book.html)
79
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.24650550.svg)](https://doi.org/10.5281/zenodo.24650550)
79
80
  [![PyPI](https://img.shields.io/pypi/v/srdkit.svg)](https://pypi.org/project/srdkit/)
80
81
  [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/ComplexSystemsIntelligence/srdkit/blob/main/LICENSE)
81
82
 
@@ -132,12 +133,18 @@ print(sk.analyze(X, reference=y).to_markdown()) # the whole analysis as a repo
132
133
  ## Documentation and book
133
134
 
134
135
  * Documentation with the example gallery and the API: https://complexsystemsintelligence.github.io/srdkit
135
- * The book *Sum of Ranking Differences in Python: The srdkit toolbox* (CC BY 4.0) is built from `book/`;
136
+ * The book *Sum of Ranking Differences in Python: The srdkit toolbox* (CC BY 4.0):
137
+ [read online](https://complexsystemsintelligence.github.io/srdkit/book/) ·
138
+ [PDF](https://complexsystemsintelligence.github.io/srdkit/srdkit-book.pdf) ·
139
+ [EPUB](https://complexsystemsintelligence.github.io/srdkit/srdkit-book.epub).
140
+ It is built from `book/` (PDF with XeLaTeX, web and EPUB editions with tex4ht:
141
+ `python book/web/make_web.py`, `python book/epub/make_epub.py`);
136
142
  every computed figure comes from a script of the gallery.
137
143
 
138
144
  ## Citing
139
145
 
140
- K. Héberger, Á. Ipkovich, J. Abonyi, *srdkit: sum of ranking differences in Python*, version 1.0, 2026.
146
+ K. Héberger, Á. Ipkovich, J. Abonyi, *srdkit: sum of ranking differences in Python*, 2026,
147
+ [doi:10.5281/zenodo.24650550](https://doi.org/10.5281/zenodo.24650550) (all versions; version 1.0: [doi:10.5281/zenodo.24650551](https://doi.org/10.5281/zenodo.24650551)).
141
148
  Please cite also the original publications of the methods you use; see `CITATION.cff` and the
142
149
  [citing page](https://complexsystemsintelligence.github.io/srdkit/citing.html).
143
150
 
@@ -4,7 +4,8 @@
4
4
 
5
5
  [![tests](https://github.com/ComplexSystemsIntelligence/srdkit/actions/workflows/ci.yml/badge.svg)](https://github.com/ComplexSystemsIntelligence/srdkit/actions/workflows/ci.yml)
6
6
  [![docs](https://img.shields.io/badge/docs-gallery%20%2B%20API-285780)](https://complexsystemsintelligence.github.io/srdkit)
7
- [![book](https://img.shields.io/badge/book-PDF-D55E00)](https://complexsystemsintelligence.github.io/srdkit/book.html)
7
+ [![book](https://img.shields.io/badge/book-PDF%20%C2%B7%20EPUB%20%C2%B7%20web-D55E00)](https://complexsystemsintelligence.github.io/srdkit/book.html)
8
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.24650550.svg)](https://doi.org/10.5281/zenodo.24650550)
8
9
  [![PyPI](https://img.shields.io/pypi/v/srdkit.svg)](https://pypi.org/project/srdkit/)
9
10
  [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/ComplexSystemsIntelligence/srdkit/blob/main/LICENSE)
10
11
 
@@ -61,12 +62,18 @@ print(sk.analyze(X, reference=y).to_markdown()) # the whole analysis as a repo
61
62
  ## Documentation and book
62
63
 
63
64
  * Documentation with the example gallery and the API: https://complexsystemsintelligence.github.io/srdkit
64
- * The book *Sum of Ranking Differences in Python: The srdkit toolbox* (CC BY 4.0) is built from `book/`;
65
+ * The book *Sum of Ranking Differences in Python: The srdkit toolbox* (CC BY 4.0):
66
+ [read online](https://complexsystemsintelligence.github.io/srdkit/book/) ·
67
+ [PDF](https://complexsystemsintelligence.github.io/srdkit/srdkit-book.pdf) ·
68
+ [EPUB](https://complexsystemsintelligence.github.io/srdkit/srdkit-book.epub).
69
+ It is built from `book/` (PDF with XeLaTeX, web and EPUB editions with tex4ht:
70
+ `python book/web/make_web.py`, `python book/epub/make_epub.py`);
65
71
  every computed figure comes from a script of the gallery.
66
72
 
67
73
  ## Citing
68
74
 
69
- K. Héberger, Á. Ipkovich, J. Abonyi, *srdkit: sum of ranking differences in Python*, version 1.0, 2026.
75
+ K. Héberger, Á. Ipkovich, J. Abonyi, *srdkit: sum of ranking differences in Python*, 2026,
76
+ [doi:10.5281/zenodo.24650550](https://doi.org/10.5281/zenodo.24650550) (all versions; version 1.0: [doi:10.5281/zenodo.24650551](https://doi.org/10.5281/zenodo.24650551)).
70
77
  Please cite also the original publications of the methods you use; see `CITATION.cff` and the
71
78
  [citing page](https://complexsystemsintelligence.github.io/srdkit/citing.html).
72
79
 
@@ -5,8 +5,10 @@ First steps: the sum of ranking differences
5
5
  Five methods estimate a property of eight samples, and a reference value is
6
6
  known for every sample. SRD ranks every column, compares the ranks with the
7
7
  ranks of the reference and sums the absolute differences. The smaller the sum,
8
- the closer the method to the reference. The values are normalized by the largest
9
- possible SRD, :math:`\\lfloor n^2/2\\rfloor`, the SRD of the reversed ranking.
8
+ the closer the method to the reference. The values are scaled by the largest
9
+ possible SRD, :math:`\\lfloor n^2/2\\rfloor`, the SRD of the reversed ranking
10
+ (:math:`n^2/2` for even and :math:`(n^2-1)/2` for odd :math:`n`), and reported in
11
+ percent.
10
12
 
11
13
  The table is invented for teaching: M1 follows the reference, M2 swaps two
12
14
  pairs, M3 is noisy, M4 is almost random and M5 reverses the order.
@@ -32,10 +34,13 @@ print("|differences| of M2:", res.contributions["M2"].tolist())
32
34
  # %%
33
35
  # The classical SRD plot
34
36
  # ----------------------
35
- # Every method is a line at its normalized SRD. The black curve is the
37
+ # Every method is a line at its scaled SRD. The black curve is the
36
38
  # cumulative distribution of SRD values of random rankings of eight objects
37
- # (computed exactly); the dotted lines mark its 5% (XX1), 50% (Med) and 95%
38
- # (XX19) points. Lines left of XX1 are better than random, lines right of XX19
39
+ # (computed exactly). The distribution is discrete, so its 5% and 95% points
40
+ # (called XX1 and XX19 in the SRD literature) fall between two attainable values:
41
+ # each is drawn as a pair of dashed lines, the outer one still significant, the
42
+ # inner one no longer; the dotted line is the median. Lines at or left of the
43
+ # outer 5% line are better than random, lines at or right of the outer 95% line
39
44
  # are reversed.
40
45
  # [snippet:plot]
41
46
  val = res.validate() # comparison of ranks with random numbers
@@ -56,7 +61,11 @@ fig.tight_layout()
56
61
  # Parameter study: the number of objects
57
62
  # --------------------------------------
58
63
  # The same relative agreement is more convincing with more objects: the band
59
- # between XX1 and XX19 narrows around the expected value 2/3 of random rankings.
64
+ # between the 5% and 95% points narrows around the expected value 2/3 of random
65
+ # rankings. The brackets are the attainable values on both sides of each point.
60
66
  for n in (5, 8, 13, 20, 50, 100):
61
- p = sk.null_distribution(n=n).percentiles()
62
- print(f"n={n:3d} XX1={p['XX1']:.3f} Med={p['Med']:.3f} XX19={p['XX19']:.3f}")
67
+ d = sk.null_distribution(n=n)
68
+ p, br = d.percentiles(), d.brackets()
69
+ lo, hi = br["lower"], br["upper"]
70
+ print(f"n={n:3d} 5%={p['XX1']:.3f} [{lo[0]:.3f}, {lo[1]:.3f}] Med={p['Med']:.3f} "
71
+ f"95%={p['XX19']:.3f} [{hi[0]:.3f}, {hi[1]:.3f}]")
@@ -5,8 +5,8 @@ Ties, rank conventions and soft ranks
5
5
  Rounded measurements produce ties. SRD gives tied values the mean of the
6
6
  positions they occupy (mid-ranks; Kollár-Hunek and Héberger, 2013). Other
7
7
  conventions change SRD slightly; the exact null distribution of srdkit takes the
8
- tie pattern of every column into account. Soft ranks — the expected ranks under a
9
- small Gaussian measurement error — make SRD a continuous function of the data:
8
+ tie pattern of every column into account. Soft ranks --- the expected ranks under a
9
+ small Gaussian measurement error --- make SRD a continuous function of the data:
10
10
  equal values get half a rank each from the other, exactly the mid-rank.
11
11
  """
12
12
 
@@ -0,0 +1,91 @@
1
+ """
2
+ The exact null distribution of SRD
3
+ ==================================
4
+
5
+ The comparison of ranks with random numbers needs the distribution of SRD for
6
+ random rankings. Héberger and Kollár-Hunek (2011) enumerated all permutations up
7
+ to n = 13 and used a normal approximation above; the distribution is discrete,
8
+ and the normal curve is only an approximation of it. srdkit computes the distribution
9
+ exactly for any n and any tie pattern by a dynamic programme that sweeps a cut
10
+ point along the rank axis and tracks the number of pairs crossing it. Without
11
+ ties the integer counts reproduce Spearman's footrule numbers (OEIS A062869).
12
+ """
13
+
14
+ import math
15
+ import time
16
+
17
+ import matplotlib.pyplot as plt
18
+ import numpy as np
19
+
20
+ import srdkit as sk
21
+ from srdkit import viz
22
+
23
+ # %%
24
+ # Exact counts and the enumeration they replace
25
+ # ---------------------------------------------
26
+ # [snippet:exact]
27
+ d = sk.footrule_null_exact(n=6, exact=True)
28
+ print("values:", d.values.tolist())
29
+ print("counts:", d.counts, " sum =", sum(d.counts), "= 6! =", math.factorial(6))
30
+ e = sk.distribution.footrule_null_enumerate(n=6)
31
+ print("enumeration agrees:", d.counts == e.counts)
32
+ # [/snippet:exact]
33
+
34
+ # %%
35
+ # A discrete distribution: odd and even n
36
+ # ---------------------------------------
37
+ # Without ties SRD is always even (the rank differences sum to zero), so the
38
+ # attainable values are 0, 2, 4, ..., floor(n^2/2): the scaled values form a
39
+ # lattice whose step 2/floor(n^2/2) differs for odd n (floor(n^2/2) = (n^2-1)/2)
40
+ # and even n (n^2/2). For odd n the expected scaled value is exactly 2/3, for
41
+ # even n it is 2/3 (1 - 1/n^2). The exact moments (Diaconis and Graham, 1977)
42
+ # are E = (n^2-1)/3 and Var = (n+1)(2n^2+7)/45; a normal curve with these
43
+ # moments describes the centre for moderate n but misses the discreteness and
44
+ # the skewness, and it cannot say which attainable value is the 5% limit.
45
+ # [snippet:compare]
46
+ for n in (9, 10):
47
+ ex = sk.null_distribution(n=n, method="exact")
48
+ nm = sk.null_distribution(n=n, method="normal")
49
+ lo = ex.brackets()["lower"]
50
+ print(f"n={n}: max={sk.srd_max(n)}, step={200 / sk.srd_max(n):.1f}%, mean={ex.mean / ex.scale:.4f}, "
51
+ f"5% between {100 * lo[0]:.1f}% and {100 * lo[1]:.1f}% (normal: {100 * nm.ppf(0.05, True):.1f}%)")
52
+ mc = sk.null_distribution(n=9, method="monte-carlo", n_sim=50_000, random_state=0)
53
+ print("Monte Carlo, n=9: 5% point", round(mc.percentiles()["XX1"], 4))
54
+ # [/snippet:compare]
55
+ from scipy import stats # noqa: E402
56
+
57
+ fig, axs = plt.subplots(1, 2, figsize=(10.0, 3.3), sharey=True)
58
+ for ax, n in zip(axs, (9, 10)):
59
+ ex = sk.null_distribution(n=n, method="exact")
60
+ nm = sk.null_distribution(n=n, method="normal")
61
+ viz.plot_distribution(ex, ax=ax, percent=True, label="exact")
62
+ xs = np.linspace(0, 100, 400)
63
+ ax.plot(xs, stats.norm.pdf(xs / 100 * nm.scale, nm.mu, nm.sigma) * 2, color="#D55E00", lw=1.2,
64
+ label="normal\n(same moments)")
65
+ for v in ex.brackets()["lower"]:
66
+ ax.axvline(100 * v, color="#5b6876", ls=(0, (3, 2)), lw=0.9)
67
+ ax.set_title(f"n = {n}: max SRD = {sk.srd_max(n)}, step {200 / sk.srd_max(n):.1f}%", fontsize=9, loc="left")
68
+ axs[1].set_ylabel("")
69
+ axs[0].legend(frameon=False, fontsize=7.5, loc="upper left", borderaxespad=0.2)
70
+ fig.tight_layout()
71
+
72
+ # %%
73
+ # Scaling of the dynamic programme
74
+ # --------------------------------
75
+ for n in (20, 50, 100, 150):
76
+ t0 = time.perf_counter()
77
+ dd = sk.footrule_null_exact(n=n)
78
+ p = dd.percentiles()
79
+ print(f"n={n:4d}: {time.perf_counter() - t0:6.3f} s 5%={p['XX1']:.4f} 95%={p['XX19']:.4f}")
80
+
81
+ # %%
82
+ # Parameter study: ties of the reference
83
+ # --------------------------------------
84
+ # A reference with many ties narrows the distribution (fewer distinct rank
85
+ # positions), so the 5% limit moves.
86
+ fig, ax = plt.subplots(figsize=(6.5, 3.2))
87
+ for k, blocks in enumerate(([1] * 12, [2] * 6, [3] * 4, [4] * 3)):
88
+ yref = sk.ranking.midranks_from_blocks(blocks)
89
+ dd = sk.footrule_null_exact(None, yref, n=12)
90
+ viz.plot_distribution(dd, ax=ax, cumulative=True, color=viz._style.CATEGORICAL[k], label=f"tie blocks of {blocks[0]}")
91
+ ax.legend(frameon=False, fontsize=8)
@@ -43,7 +43,7 @@ cv52 = sk.cross_validate(X, reference=truth, scheme="5x2", n_folds=5, random_sta
43
43
  print(cv52.test(test="alpaydin")[["A", "B", "p", "mark"]])
44
44
  # [/snippet:cv]
45
45
 
46
- fig, axs = plt.subplots(1, 2, figsize=(11, 3.8))
46
+ fig, axs = plt.subplots(1, 2, figsize=(11, 4.4))
47
47
  viz.plot_srd(res, val, ax=axs[0])
48
48
  viz.plot_cv(cv, ax=axs[1])
49
49
  fig.tight_layout()
@@ -0,0 +1,59 @@
1
+ """
2
+ A worked example: which game statistics predict the league table?
3
+ =================================================================
4
+
5
+ The example of the rSRD package (Sziklai, Gere, Héberger and Staudacher, 2026):
6
+ seven game statistics of the 18 Bundesliga teams in the 2020/21 season, compiled
7
+ from whoscored.com, are compared with the final number of points. The points
8
+ are the natural gold standard, so SRD tells which statistic orders the teams
9
+ most like the league table, CRRN tells which statistics are better than random
10
+ and which are reversed, and cross-validation tells which statistics differ
11
+ significantly. srdkit reproduces the published SRD values exactly.
12
+ """
13
+
14
+ import matplotlib.pyplot as plt
15
+
16
+ import srdkit as sk
17
+ from srdkit import viz
18
+
19
+ # %%
20
+ # SRD against the points
21
+ # ----------------------
22
+ # Larger values are not "better" for every statistic (more fouls is not a
23
+ # virtue), but SRD needs no direction: a statistic that orders the teams in the
24
+ # reverse order of the points is recognized as reversed.
25
+ # [snippet:srd]
26
+ X, pts = sk.datasets.load_bundesliga()
27
+ res = sk.srd(X, reference=pts)
28
+ val = res.validate() # exact null distribution for the tie pattern of the points
29
+ print(val.table.round(3))
30
+ lo, hi = val.distribution.brackets()["lower"], val.distribution.brackets()["upper"]
31
+ print(f"5% point between {lo[0]:.3f} and {lo[1]:.3f}, 95% point between {hi[0]:.3f} and {hi[1]:.3f}")
32
+ # [/snippet:srd]
33
+
34
+ # %%
35
+ # Cross-validation
36
+ # ----------------
37
+ # Eight random folds with Wilcoxon's test (the overall best choice of Sziklai,
38
+ # Baranyi and Héberger, 2025) and the stricter 5x2 test of Alpaydin.
39
+ # [snippet:cv]
40
+ cv = sk.cross_validate(X, reference=pts, scheme="random", n_folds=8, random_state=0)
41
+ print(cv.test(test="wilcoxon")[["A", "B", "p", "mark"]])
42
+ cv52 = sk.cross_validate(X, reference=pts, scheme="5x2", n_folds=5, random_state=0)
43
+ print(cv52.test(test="alpaydin")[["A", "B", "p", "mark"]])
44
+ # [/snippet:cv]
45
+
46
+ fig, axs = plt.subplots(1, 2, figsize=(11.5, 5.0), gridspec_kw={"width_ratios": [1.15, 1]})
47
+ viz.plot_srd(res, val, ax=axs[0])
48
+ viz.plot_cv(cv, ax=axs[1])
49
+ fig.tight_layout(w_pad=3.0)
50
+
51
+ # %%
52
+ # Reading the result
53
+ # ------------------
54
+ # Possession, shots and passing accuracy rank the teams like the league table
55
+ # (left of the 5% point); dribbles, offsides and cards cannot be told from
56
+ # random rankings; fouls are reversed: the weaker teams commit more fouls. The
57
+ # three similar statistics are close to each other, and cross-validation shows
58
+ # which of their differences are real.
59
+ print(res.to_frame().round(3))
@@ -45,6 +45,27 @@ for name in ("footrule", "kendall", "spearman", "cayley", "ulam", "hamming"):
45
45
  rows[name] = [f"{p:.2f} ({vd[0]})" for p, vd in zip(r.normalized, v.table.loc[r.columns, "verdict"])]
46
46
  print(pd.DataFrame(rows, index=X.columns).T)
47
47
 
48
+ # %%
49
+ # Which distances are metrics?
50
+ # ----------------------------
51
+ # Distances derived from correlation coefficients are not interchangeable.
52
+ # ``check_metric`` compares all permutations of five objects and all weak orders
53
+ # (rankings with ties, as mid-ranks) of four objects and counts the violated
54
+ # triangle inequalities and the pairs of different rankings at distance zero.
55
+ # [snippet:metric]
56
+ cd = sk.distances.correlation_distance
57
+ candidates = {"SRD (footrule)": "footrule", "sum d^2 (Spearman)": "spearman", "(1-rho)/2": cd("spearman", "half"),
58
+ "sqrt((1-rho)/2)": cd("spearman", "sqrt"), "1-|rho|": cd("spearman", "abs"),
59
+ "(1-tau)/2": cd("kendall", "half"), "Kemeny (Kendall)": "kendall", "1-tau^2": cd("kendall", "square")}
60
+ rows = []
61
+ for label, dist in candidates.items():
62
+ a = sk.distances.check_metric(dist, n=5)
63
+ b = sk.distances.check_metric(dist, n=4, ties=True)
64
+ rows.append({"distance": label, "metric (no ties)": a["metric"], "triangle viol.": a["triangle_violations"],
65
+ "zero pairs": a["zero_pairs"], "metric (ties)": b["metric"]})
66
+ print(pd.DataFrame(rows).set_index("distance"))
67
+ # [/snippet:metric]
68
+
48
69
  # %%
49
70
  # Agreement of the family members
50
71
  # -------------------------------
@@ -2,8 +2,8 @@
2
2
  Weighted and top-k SRD
3
3
  ======================
4
4
 
5
- When the top of a ranking matters most — the best alternatives, the first
6
- draft picks, the most active compounds — displacements near the top should cost
5
+ When the top of a ranking matters most --- the best alternatives, the first
6
+ draft picks, the most active compounds --- displacements near the top should cost
7
7
  more. The weighted footrule of Kumar and Vassilvitskii (2010) uses position
8
8
  weights (here the DCG discount) and object weights; the top-k footrule of Fagin
9
9
  et al. (2003) ignores everything below position k. The normalization is the
@@ -4,7 +4,7 @@ Leaving the ranks: DnE and DnM
4
4
 
5
5
  Ranking discards the size of the differences. Héberger (2026) defined two
6
6
  value-based relatives of SRD: the sum of Euclidean distance differences (DnE)
7
- and the sum of absolute Manhattan distance differences (DnM), normalized by the
7
+ and the sum of absolute Manhattan distance differences (DnM), scaled by the
8
8
  largest possible deviation of every row within the range of the extended matrix.
9
9
  Their randomization test fills that range with uniform random numbers. They
10
10
  discriminate more finely than SRD but need the columns on a common scale. Here
@@ -46,7 +46,7 @@ ve = sk.value_crrn(e, n_sim=100_000, random_state=0)
46
46
  print(ve.table.round(4))
47
47
  # [/snippet:dne]
48
48
 
49
- fig, axs = plt.subplots(1, 2, figsize=(11, 3.8))
49
+ fig, axs = plt.subplots(1, 2, figsize=(11, 4.6))
50
50
  viz.plot_srd(s, s.validate(), ax=axs[0], title="SRD")
51
51
  viz.plot_srd(e, ve, ax=axs[1], title="DnE")
52
52
  fig.tight_layout()
@@ -46,7 +46,7 @@ print(table.sort_values("SRD%"))
46
46
  print("distinct values:", {k: table[k].nunique() for k in table})
47
47
  # [/snippet:degenerate]
48
48
 
49
- fig, axs = plt.subplots(1, 3, figsize=(13, 3.8))
49
+ fig, axs = plt.subplots(1, 3, figsize=(13, 4.8))
50
50
  viz.plot_srd(s, s.validate(), ax=axs[0], title="SRD (row maximum)")
51
51
  viz.plot_srd(e, e.validate(n_sim=200_000, random_state=1), ax=axs[1], title="DnE")
52
52
  viz.plot_srd(m, m.validate(n_sim=200_000, random_state=1), ax=axs[2], title="DnM")
@@ -77,7 +77,7 @@ robust = pd.DataFrame(robust).T
77
77
  print(robust.round(3))
78
78
  # [/snippet:constant]
79
79
 
80
- fig, axs = plt.subplots(1, 3, figsize=(13, 3.6))
80
+ fig, axs = plt.subplots(1, 3, figsize=(13, 4.6))
81
81
  viz.plot_srd(s_c, ax=axs[0], title="SRD, constant benchmark")
82
82
  viz.plot_srd(e_c, e_c.validate(n_sim=100_000, random_state=2), ax=axs[1], title="DnE, constant benchmark")
83
83
  xx = np.arange(len(robust))
@@ -8,7 +8,7 @@ multi-attribute utility. We use the 2018 emission indicators of 146 countries:
8
8
  first, total emissions per capita are the reference and SRD reveals which
9
9
  sectors drive the total; then emissions get Derringer desirabilities (low
10
10
  emission = desirable) and GDP per capita a utility (high = desirable), and the
11
- "clean development utility" — the additive aggregate — ranks the countries.
11
+ "clean development utility" --- the additive aggregate --- ranks the countries.
12
12
  """
13
13
 
14
14
  import matplotlib.pyplot as plt
@@ -26,7 +26,7 @@ val = res.validate()
26
26
  print(val.table.round(3).head(8))
27
27
  print(val.table["verdict"].value_counts())
28
28
  # [/snippet:sectors]
29
- fig, ax = plt.subplots(figsize=(10, 4.2))
29
+ fig, ax = plt.subplots(figsize=(10, 5.0))
30
30
  viz.plot_srd(res, val, ax=ax, label_rotation=90)
31
31
 
32
32
  # %%
@@ -44,7 +44,7 @@ best = D.index[cdu.argsort()[::-1][:8]].tolist()
44
44
  print("highest clean development utility:", best)
45
45
  # [/snippet:usrd]
46
46
 
47
- fig, axs = plt.subplots(1, 2, figsize=(11, 3.6))
47
+ fig, axs = plt.subplots(1, 2, figsize=(11, 4.6))
48
48
  viz.plot_utilities(X["ENGeAllGHG"], {"Derringer (10-90 pct), reversed": lambda v: 1 - sk.utility.derringer_percentile(v, 10, 90),
49
49
  "ECDF, reversed": lambda v: 1 - sk.utility.ecdf(v),
50
50
  "min-max, reversed": lambda v: 1 - sk.utility.minmax(v)}, ax=axs[0],
@@ -27,7 +27,7 @@ val = res.validate()
27
27
  print(val.table.round(3))
28
28
  # [/snippet:mcda]
29
29
 
30
- fig, axs = plt.subplots(1, 2, figsize=(11, 4.0))
30
+ fig, axs = plt.subplots(1, 2, figsize=(11, 5.0))
31
31
  viz.plot_srd(res, val, ax=axs[0], title="MCDM methods vs consensus")
32
32
  viz.plot_heatmap(sk.pairwise_srd(S), ax=axs[1], cluster=True, annotate=False)
33
33
  fig.tight_layout()
@@ -3,9 +3,9 @@ Many-objective ranking with NMF and SRD
3
3
  =======================================
4
4
 
5
5
  With many objectives almost every alternative is Pareto optimal. Abonyi,
6
- Ipkovich, Dörgő and Héberger (2023) aggregate the objectives by non-negative
7
- matrix factorization — whose non-negative loadings never mix conflicting
8
- objectives — and rank the alternatives by the layers of non-dominated sorting of
6
+ Ipkovich, Dörg\u0151 and Héberger (2023) aggregate the objectives by non-negative
7
+ matrix factorization --- whose non-negative loadings never mix conflicting
8
+ objectives --- and rank the alternatives by the layers of non-dominated sorting of
9
9
  the NMF scores. SRD with the row-maximum reference removes the objectives that
10
10
  rank the alternatives randomly or reversely. PCA, by contrast, mixes negatively
11
11
  correlated objectives into the same component.
@@ -56,7 +56,7 @@ print(sw)
56
56
  print(sw.history.round(3))
57
57
  # [/snippet:selfweight]
58
58
 
59
- fig, axs = plt.subplots(1, 3, figsize=(13, 3.6), gridspec_kw={"width_ratios": [1.1, 1.1, 1]})
59
+ fig, axs = plt.subplots(1, 3, figsize=(13, 4.6), gridspec_kw={"width_ratios": [1.1, 1.1, 1]})
60
60
  viz.plot_srd(res, res.validate(), ax=axs[0], title="row maximum")
61
61
  viz.plot_srd(sw.result, sw.result.validate(), ax=axs[1], title="self-weighted reference")
62
62
  viz.plot_weights(sw.weights, ax=axs[2], groups=sk.weights.group_srd_values(sw.result.percent, k=3))
@@ -0,0 +1,88 @@
1
+ """
2
+ A worked example: the indicators of the CWTS Leiden Ranking
3
+ ===========================================================
4
+
5
+ The CWTS Leiden Ranking 2020 describes 1176 universities with bibliometric
6
+ indicators of scientific impact, collaboration, open access publishing and
7
+ gender diversity (period 2015-2018). Abonyi, Ipkovich, Dörg\u0151 and Héberger
8
+ (2023) used it to show how SRD and non-negative matrix factorization select and
9
+ validate the objectives of a many-objective ranking. Here SRD answers two
10
+ questions: which size-independent indicators order the universities like the
11
+ consensus of all indicators, and does fractional counting of co-authored
12
+ publications make the impact indicators agree better?
13
+ """
14
+
15
+ import matplotlib.pyplot as plt
16
+ import numpy as np
17
+ import pandas as pd
18
+
19
+ import srdkit as sk
20
+ from srdkit import viz
21
+
22
+ # %%
23
+ # Which indicators follow the consensus?
24
+ # --------------------------------------
25
+ # The reference is the mean rank (Borda) of the 18 size-independent indicators
26
+ # under fractional counting.
27
+ # [snippet:indicators]
28
+ groups = sk.datasets.LEIDEN_GROUPS
29
+ indicators = sum(groups.values(), [])
30
+ U = sk.datasets.load_leiden_ranking("fractional")
31
+ res = sk.srd(U[indicators], reference="borda")
32
+ val = res.validate() # n = 1176: normal approximation with exact moments
33
+ print(val.table[["SRD%", "verdict"]].round(1))
34
+ print("5% and 95% points:", {k: round(100 * v, 2) for k, v in val.percentiles.items() if k in ("XX1", "XX19")})
35
+ # [/snippet:indicators]
36
+
37
+ fig, ax = plt.subplots(figsize=(10.5, 5.4))
38
+ colors = {c: viz._style.CATEGORICAL[k] for k, (g, cols) in enumerate(groups.items()) for c in cols}
39
+ viz.plot_srd(res, val, ax=ax, colors=colors)
40
+ handles = [plt.Line2D([], [], color=viz._style.CATEGORICAL[k], lw=2) for k in range(len(groups))]
41
+ ax.legend(handles, list(groups), frameon=False, fontsize=8, loc="lower left", bbox_to_anchor=(0.0, 0.03))
42
+ fig.tight_layout()
43
+
44
+ # %%
45
+ # With 1176 objects the band of random rankings is narrow (the 5% and 95% points
46
+ # are within a few percent of 2/3), so almost every indicator differs from random;
47
+ # what matters is how far it is from the consensus. Cross-validation gives the
48
+ # uncertainty of every SRD value.
49
+ # [snippet:cv]
50
+ cv = sk.cross_validate(U[indicators], reference="borda", scheme="random", n_folds=8, random_state=0)
51
+ print((100 * cv.summary()[["mean", "std"]]).round(2).head(8))
52
+ print(cv.test(test="wilcoxon")[["A", "B", "p", "mark"]].head(8))
53
+ # [/snippet:cv]
54
+
55
+ # %%
56
+ # Full or fractional counting?
57
+ # ----------------------------
58
+ # Under full counting a co-authored publication counts fully for every
59
+ # university involved, under fractional counting it is divided among them; only
60
+ # the impact indicators depend on the choice. The six impact indicators under
61
+ # both counting methods are compared with their common consensus, and SRD-ANOVA
62
+ # on eight cross-validation folds separates the effect of the indicator, of the
63
+ # counting method and of their interaction.
64
+ # [snippet:counting]
65
+ B = sk.datasets.load_leiden_ranking("both")
66
+ imp = groups["impact"]
67
+ wide = {c: B[B.counting == c].set_index("university")[imp].add_suffix(f"|{c}") for c in ("full", "fractional")}
68
+ XI = pd.concat([wide["full"], wide["fractional"].loc[wide["full"].index]], axis=1)
69
+ cvc = sk.cross_validate(XI, reference="borda", scheme="random", n_folds=8, random_state=0)
70
+ long = sk.anova.split_factors(cvc.folds.melt(var_name="solution", value_name="srd"), names=["indicator", "counting"])
71
+ print(sk.anova.anova(long, response="srd", factors=["indicator", "counting"]).round(4))
72
+ means = long.assign(srd=100 * long.srd).pivot_table(index="indicator", columns="counting", values="srd")
73
+ print(means.loc[imp].round(2))
74
+ print("mean over the indicators:", means.mean().round(2).to_dict())
75
+ # [/snippet:counting]
76
+
77
+ fig, ax = plt.subplots(figsize=(7.2, 3.4))
78
+ sd = long.assign(srd=100 * long.srd).pivot_table(index="indicator", columns="counting", values="srd", aggfunc="std")
79
+ x = np.arange(len(imp))
80
+ for k, (c, off) in enumerate((("full", -0.17), ("fractional", 0.17))):
81
+ ax.errorbar(x + off, means.loc[imp, c], yerr=sd.loc[imp, c], fmt="o", ms=5, capsize=3,
82
+ color=viz._style.CATEGORICAL[k], label=f"{c} counting")
83
+ ax.set_xticks(x)
84
+ ax.set_xticklabels(imp)
85
+ ax.set_ylabel("SRD (%) to the consensus")
86
+ ax.legend(frameon=False, fontsize=8)
87
+ viz._style.despine(ax)
88
+ fig.tight_layout()