Statistical analysis¶
jmetal.lab.statistical_test implements frequentist and Bayesian tests for comparing algorithms
across multiple problems and runs: the Friedman, Friedman aligned-rank, and Quade tests; post-hoc
p-value adjustment procedures (Bonferroni-Dunn, Holm, Hochberg, Holland, Finner, Li, Shaffer,
Nemenyi); Bayesian sign and signed-rank tests; and critical-distance plots. See
Experiments for how to get from a set of algorithm runs to the tidy summary these
functions expect as input.
Note
This module may be superseded by SAES, a dedicated statistical-analysis package under the same jMetal organization, once it becomes installable alongside jMetalPy -- currently blocked on a SAES release with a relaxed numpy pin.
API¶
functions
¶
bonferroni_dunn(p_values, control)
¶
Bonferroni-Dunn's procedure for the adjusted p-value computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
DataFrame | ndarray
|
2-D array or DataFrame containing the p-values obtained from a ranking test. |
required |
control
|
int | str
|
Index or name of the control algorithm. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the adjusted p-values. |
Source code in src/jmetal/lab/statistical_test/apv_procedures.py
holland(p_values, control)
¶
Holland's procedure for the adjusted p-value computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
DataFrame | ndarray
|
2-D array or DataFrame containing the p-values obtained from a ranking test. |
required |
control
|
int | str
|
Index or name of the control algorithm. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the adjusted p-values. |
Source code in src/jmetal/lab/statistical_test/apv_procedures.py
finner(p_values, control)
¶
Finner's procedure for the adjusted p-value computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
DataFrame | ndarray
|
2-D array or DataFrame containing the p-values obtained from a ranking test. |
required |
control
|
int | str
|
Index or name of the control algorithm. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the adjusted p-values. |
Source code in src/jmetal/lab/statistical_test/apv_procedures.py
hochberg(p_values, control)
¶
Hochberg's procedure for the adjusted p-value computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
DataFrame | ndarray
|
2-D array or DataFrame containing the p-values obtained from a ranking test. |
required |
control
|
int | str
|
Index or name of the control algorithm. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the adjusted p-values. |
Source code in src/jmetal/lab/statistical_test/apv_procedures.py
li(p_values, control)
¶
Li's procedure for the adjusted p-value computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
DataFrame | ndarray
|
2-D array or DataFrame containing the p-values obtained from a ranking test. |
required |
control
|
int | str
|
Index or name of the control algorithm. If provided, control vs all comparisons are considered, else all vs all. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the adjusted p-values. |
Source code in src/jmetal/lab/statistical_test/apv_procedures.py
holm(p_values, control=None)
¶
Holm's procedure for the adjusted p-value computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
DataFrame | ndarray
|
2-D array or DataFrame containing the p-values obtained from a ranking test. |
required |
control
|
int | str | None
|
Index or name of the control algorithm. If provided, control vs all comparisons are considered, else all vs all. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the adjusted p-values. |
Source code in src/jmetal/lab/statistical_test/apv_procedures.py
shaffer(p_values)
¶
Shaffer's procedure for adjusted p-value computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
DataFrame | ndarray
|
2-D array or DataFrame containing the p-values. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the adjusted p-values. |
Source code in src/jmetal/lab/statistical_test/apv_procedures.py
nemenyi(p_values)
¶
Nemenyi's procedure for adjusted p-value computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
DataFrame | ndarray
|
2-D array or DataFrame containing the p-values. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the adjusted p-values. |
Source code in src/jmetal/lab/statistical_test/apv_procedures.py
ranks(data, descending=False)
¶
Computes the rank of the elements in data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array
|
2-D matrix. |
required |
descending
|
bool
|
If true, rank is sorted in descending order. |
False
|
Returns:
| Type | Description |
|---|---|
array
|
A matrix of the same shape as |
array
|
with respect to the j-th column. |
Source code in src/jmetal/lab/statistical_test/functions.py
sign_test(data)
¶
Given the results drawn from two algorithms/methods X and Y, the sign test analyses if there is a difference between X and Y.
.. note:: Null Hypothesis: Pr(X<Y)= 0.5
:param data: An (n x 2) array or DataFrame contaning the results. In data, each column represents an algorithm and, and each row a problem. :return p_value: The associated p-value from the binomial distribution. :return bstat: Number of successes.
Source code in src/jmetal/lab/statistical_test/functions.py
friedman_test(data)
¶
Friedman ranking test.
..note:: Null Hypothesis: In a set of k (>=2) treaments (or tested algorithms), all the treatments are equivalent, so their average ranks should be equal.
:param data: An (n x 2) array or DataFrame contaning the results. In data, each column represents an algorithm and, and each row a problem. :return p_value: The associated p-value. :return friedman_stat: Friedman's chi-square.
Source code in src/jmetal/lab/statistical_test/functions.py
friedman_aligned_rank_test(data)
¶
Method of aligned ranks for the Friedman test.
..note:: Null Hypothesis: In a set of k (>=2) treaments (or tested algorithms), all the treatments are equivalent, so their average ranks should be equal.
:param data: An (n x 2) array or DataFrame contaning the results. In data, each column represents an algorithm and, and each row a problem. :return p_value: The associated p-value. :return aligned_rank_stat: Friedman's aligned rank chi-square statistic.
Source code in src/jmetal/lab/statistical_test/functions.py
quade_test(data)
¶
Quade test.
..note:: Null Hypothesis: In a set of k (>=2) treaments (or tested algorithms), all the treatments are equivalent, so their average ranks should be equal.
:param data: An (n x 2) array or DataFrame contaning the results. In data, each column represents an algorithm and, and each row a problem. :return p_value: The associated p-value from the F-distribution. :return fq: Computed F-value.
Source code in src/jmetal/lab/statistical_test/functions.py
friedman_ph_test(data, control=None, apv_procedure=None)
¶
Friedman post-hoc test.
:param data: An (n x 2) array or DataFrame contaning the results. In data, each column represents an algorithm and, and each row a problem.
:param control: optional int or string. Default None. Index or Name of the control algorithm. If control = None all FriedmanPosHocTest considers all possible comparisons among algorithms.
:param apv_procedure: optional string. Default None. Name of the procedure for computing
adjusted p-values. If apv_procedure is None, adjusted p-values are not computed;
otherwise the values are computed according to the specified procedure: for 1-vs-all
comparisons, one of 'Bonferroni', 'Holm', 'Hochberg', 'Holland',
'Finner', 'Li'; for all-vs-all comparisons, one of 'Shaffer', 'Holm',
'Nemenyi'.
:return z_values: Test statistic. :return p_values: The p-value according to the Studentized range distribution.
Source code in src/jmetal/lab/statistical_test/functions.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
friedman_aligned_ph_test(data, control=None, apv_procedure=None)
¶
Friedman Aligned Ranks post-hoc test.
:param data: An (n x 2) array or DataFrame contaning the results. In data, each column represents an algorithm and, and each row a problem.
:param control: optional int or string. Default None. Index or Name of the control algorithm. If control = None all FriedmanPosHocTest considers all possible comparisons among algorithms.
:param apv_procedure: optional string. Default None. Name of the procedure for computing
adjusted p-values. If apv_procedure is None, adjusted p-values are not computed;
otherwise the values are computed according to the specified procedure: for 1-vs-all
comparisons, one of 'Bonferroni', 'Holm', 'Hochberg', 'Holland',
'Finner', 'Li'; for all-vs-all comparisons, one of 'Shaffer', 'Holm',
'Nemenyi'.
:return z_values: Test statistic. :return p_values: The p-value according to the Studentized range distribution.
Source code in src/jmetal/lab/statistical_test/functions.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
quade_ph_test(data, control=None, apv_procedure=None)
¶
Quade post-hoc test.
:param data: An (n x 2) array or DataFrame contaning the results. In data, each column represents an algorithm and, and each row a problem.
:param control: optional int or string. Default None. Index or Name of the control algorithm. If control = None all FriedmanPosHocTest considers all possible comparisons among algorithms.
:param apv_procedure: optional string. Default None. Name of the procedure for computing
adjusted p-values. If apv_procedure is None, adjusted p-values are not computed;
otherwise the values are computed according to the specified procedure: for 1-vs-all
comparisons, one of 'Bonferroni', 'Holm', 'Hochberg', 'Holland',
'Finner', 'Li'; for all-vs-all comparisons, one of 'Shaffer', 'Holm',
'Nemenyi'.
:return z_values: Test statistic. :return p_values: The p-value according to the Studentized range distribution.
Source code in src/jmetal/lab/statistical_test/functions.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 | |
apv_procedures
¶
bonferroni_dunn(p_values, control)
¶
Bonferroni-Dunn's procedure for the adjusted p-value computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
DataFrame | ndarray
|
2-D array or DataFrame containing the p-values obtained from a ranking test. |
required |
control
|
int | str
|
Index or name of the control algorithm. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the adjusted p-values. |
Source code in src/jmetal/lab/statistical_test/apv_procedures.py
holland(p_values, control)
¶
Holland's procedure for the adjusted p-value computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
DataFrame | ndarray
|
2-D array or DataFrame containing the p-values obtained from a ranking test. |
required |
control
|
int | str
|
Index or name of the control algorithm. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the adjusted p-values. |
Source code in src/jmetal/lab/statistical_test/apv_procedures.py
finner(p_values, control)
¶
Finner's procedure for the adjusted p-value computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
DataFrame | ndarray
|
2-D array or DataFrame containing the p-values obtained from a ranking test. |
required |
control
|
int | str
|
Index or name of the control algorithm. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the adjusted p-values. |
Source code in src/jmetal/lab/statistical_test/apv_procedures.py
hochberg(p_values, control)
¶
Hochberg's procedure for the adjusted p-value computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
DataFrame | ndarray
|
2-D array or DataFrame containing the p-values obtained from a ranking test. |
required |
control
|
int | str
|
Index or name of the control algorithm. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the adjusted p-values. |
Source code in src/jmetal/lab/statistical_test/apv_procedures.py
li(p_values, control)
¶
Li's procedure for the adjusted p-value computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
DataFrame | ndarray
|
2-D array or DataFrame containing the p-values obtained from a ranking test. |
required |
control
|
int | str
|
Index or name of the control algorithm. If provided, control vs all comparisons are considered, else all vs all. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the adjusted p-values. |
Source code in src/jmetal/lab/statistical_test/apv_procedures.py
holm(p_values, control=None)
¶
Holm's procedure for the adjusted p-value computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
DataFrame | ndarray
|
2-D array or DataFrame containing the p-values obtained from a ranking test. |
required |
control
|
int | str | None
|
Index or name of the control algorithm. If provided, control vs all comparisons are considered, else all vs all. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the adjusted p-values. |
Source code in src/jmetal/lab/statistical_test/apv_procedures.py
shaffer(p_values)
¶
Shaffer's procedure for adjusted p-value computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
DataFrame | ndarray
|
2-D array or DataFrame containing the p-values. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the adjusted p-values. |
Source code in src/jmetal/lab/statistical_test/apv_procedures.py
nemenyi(p_values)
¶
Nemenyi's procedure for adjusted p-value computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p_values
|
DataFrame | ndarray
|
2-D array or DataFrame containing the p-values. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the adjusted p-values. |
Source code in src/jmetal/lab/statistical_test/apv_procedures.py
bayesian
¶
bayesian_sign_test(data, rope_limits=[-0.01, 0.01], prior_strength=0.5, prior_place='rope', sample_size=50000, return_sample=False, rng=None)
¶
Bayesian version of the sign test.
:param data: An (n x 2) array or DataFrame contaning the results. In data, each column represents an algorithm and, and each row a problem. :param rope_limits: array_like. Default [-0.01, 0.01]. Limits of the practical equivalence. :param prior_strength: positive float. Default 0.5. Value of the prior strengt :param prior_place: string {left, rope, right}. Default 'left'. Place of the pseudo-observation z_0. :param sample_size: integer. Default 10000. Total number of random_search samples generated :param return_sample: boolean. Default False. If true, also return the samples drawn from the Dirichlet process. :param rng: Optional random generator for reproducible results. When None, a fresh np.random.default_rng() is used (i.e. results vary between calls, as before this parameter existed).
:return: List of posterior probabilities: [Pr(algorith_1 < algorithm_2), Pr(algorithm_1 equiv algorithm_2), Pr(algorithm_1 > algorithm_2)]
Source code in src/jmetal/lab/statistical_test/bayesian.py
bayesian_signed_rank_test(data, rope_limits=[-0.01, 0.01], prior_strength=1.0, prior_place='rope', sample_size=10000, return_sample=False, rng=None)
¶
Bayesian version of the signed rank test.
:param data: An (n x 2) array or DataFrame contaning the results. In data, each column represents an algorithm and, and each row a problem. :param rope_limits: array_like. Default [-0.01, 0.01]. Limits of the practical equivalence. :param prior_strength: positive float. Default 0.5. Value of the prior strengt :param prior_place: string {left, rope, right}. Default 'left'. Place of the pseudo-observation z_0. :param sample_size: integer. Default 10000. Total number of random_search samples generated :param return_sample: boolean. Default False. If true, also return the samples drawn from the Dirichlet process. :param rng: Optional random generator for reproducible results. When None, a fresh np.random.default_rng() is used (i.e. results vary between calls, as before this parameter existed).
:return: List of posterior probabilities: [Pr(algorith_1 < algorithm_2), Pr(algorithm_1 equiv algorithm_2), Pr(algorithm_1 > algorithm_2)]
Source code in src/jmetal/lab/statistical_test/bayesian.py
critical_distance
¶
NemenyiCD(alpha, num_alg, num_dataset)
¶
Computes Nemenyi's critical difference: * CD = q_alpha * sqrt(num_alg(num_alg + 1)/(6num_prob)) where q_alpha is the critical value, of the Studentized range statistic divided by sqrt(2). :param alpha: {0.1, 0.999}. Significance level. :param num_alg: number of tested algorithms. :param num_dataset: Number of problems/datasets where the algorithms have been tested.
Source code in src/jmetal/lab/statistical_test/critical_distance.py
CDplot(results, alpha=0.05, higher_is_better=False, alg_names=None, output_filename='cdplot.eps')
¶
CDgraph plots the critical difference graph show in Janez Demsar's 2006 work: * Statistical Comparisons of Classifiers over Multiple Data Sets. :param results: A 2-D array containing results from each algorithm. Each row of 'results' represents an algorithm, and each column a dataset. :param alpha: {0.1, 0.999}. Significance level for the critical difference. :param alg_names: Names of the tested algorithms.
Source code in src/jmetal/lab/statistical_test/critical_distance.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |