cds2.stats
Statistical tests, summaries and effect sizes on scipy.stats.
Statistical tests and summaries built on scipy.stats.
TestResult
dataclass
Outcome of a statistical hypothesis test.
Source code in src/cds2/stats.py
51 52 53 54 55 56 | |
CorrelationResult
dataclass
Correlation coefficient with its significance test.
Source code in src/cds2/stats.py
59 60 61 62 63 64 | |
DescribeResult
dataclass
Descriptive summary of a numeric sample.
Source code in src/cds2/stats.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
BootstrapResult
dataclass
Bootstrap estimate with standard error and percentile interval.
Source code in src/cds2/stats.py
345 346 347 348 349 350 351 352 | |
StreamingStats
Welford incremental mean/variance for datasets larger than memory.
Source code in src/cds2/stats.py
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 | |
describe(data)
Full descriptive summary (moments + quantiles) of a sample.
Source code in src/cds2/stats.py
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 | |
t_test(sample, popmean=0.0)
One-sample t-test of the sample mean against popmean.
Source code in src/cds2/stats.py
162 163 164 165 166 167 168 169 170 | |
independent_t_test(a, b, equal_var=True)
Two-sample t-test; equal_var=False runs Welch's variant.
Source code in src/cds2/stats.py
173 174 175 176 177 178 179 180 | |
paired_t_test(a, b)
Paired-samples t-test on two related samples.
Source code in src/cds2/stats.py
183 184 185 186 187 | |
anova(*groups)
One-way analysis of variance F-test across two or more groups.
Source code in src/cds2/stats.py
190 191 192 193 194 195 196 197 198 199 | |
kruskal_wallis(*groups)
Non-parametric Kruskal-Wallis H-test across groups.
Source code in src/cds2/stats.py
202 203 204 205 206 207 208 | |
mann_whitney_u(a, b)
Mann-Whitney U rank test comparing two independent samples.
Source code in src/cds2/stats.py
211 212 213 214 | |
wilcoxon_signed_rank(a, b)
Wilcoxon signed-rank test for paired samples.
Source code in src/cds2/stats.py
217 218 219 220 221 | |
normality_test(data)
Shapiro-Wilk test of normality; requires at least three observations.
Source code in src/cds2/stats.py
224 225 226 227 | |
levene_test(*groups)
Levene test for equality of variances across groups.
Source code in src/cds2/stats.py
230 231 232 233 234 235 236 | |
pearson_correlation(x, y)
Correlation between equal-length finite, non-constant samples.
Source code in src/cds2/stats.py
239 240 241 242 243 244 245 | |
spearman_correlation(x, y)
Correlation between equal-length finite, non-constant samples.
Source code in src/cds2/stats.py
248 249 250 251 252 253 254 | |
kendall_tau(x, y)
Correlation between equal-length finite, non-constant samples.
Source code in src/cds2/stats.py
257 258 259 260 261 262 263 | |
chi_square_independence(table)
Chi-square test of independence on a valid contingency table.
Source code in src/cds2/stats.py
266 267 268 269 270 | |
cohens_d(a, b)
Cohen's d standardized mean difference with pooled sample SD.
Source code in src/cds2/stats.py
273 274 275 276 277 278 279 280 | |
eta_squared_from_f(f_statistic, df1, df2)
Eta-squared effect size derived from a non-negative ANOVA F statistic.
Source code in src/cds2/stats.py
283 284 285 286 287 288 289 | |
cramers_v(table)
Cramer's V association strength from a contingency table in [0, 1].
Source code in src/cds2/stats.py
292 293 294 295 296 297 298 | |
percentile(data, q)
Percentile(s) of a sample for q in [0, 100].
Source code in src/cds2/stats.py
301 302 303 304 305 306 307 308 309 | |
z_scores(data)
Standardize a sample to zero mean and unit sample standard deviation.
Source code in src/cds2/stats.py
312 313 314 315 316 317 318 | |
norm_pdf(x, mu=0.0, sigma=1.0)
Normal distribution helper with validated location and scale.
Source code in src/cds2/stats.py
321 322 323 324 325 326 | |
norm_cdf(x, mu=0.0, sigma=1.0)
Normal distribution helper with validated location and scale.
Source code in src/cds2/stats.py
329 330 331 332 333 334 | |
norm_ppf(q, mu=0.0, sigma=1.0)
Inverse normal CDF for a probability in [0, 1].
Source code in src/cds2/stats.py
337 338 339 340 341 342 | |
bootstrap_ci(data, statistic=None, n_resamples=10000, confidence=0.95, seed=None)
Percentile bootstrap confidence interval for an arbitrary scalar statistic.
Source code in src/cds2/stats.py
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 | |
permutation_test(a, b, n_permutations=10000, seed=None)
Two-sided permutation test on the difference of means.
Source code in src/cds2/stats.py
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 | |
covariance_matrix(data)
Sample covariance matrix of column-variables (rows = observations).
Source code in src/cds2/stats.py
423 424 425 426 | |
correlation_matrix(data)
Pearson correlation matrix of non-constant column-variables.
Source code in src/cds2/stats.py
429 430 431 432 433 434 | |
multivariate_normal_logpdf(x, mean, cov)
Log-density of a multivariate normal at a single point.
Source code in src/cds2/stats.py
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 | |
bonferroni_correction(p_values)
Bonferroni family-wise error rate correction.
Each p-value is multiplied by the number of tests and capped at 1:
min(1, m * p). Controls the probability of any false positive at
alpha when every adjusted p-value is compared against alpha.
The simplest and most conservative of the three corrections offered
here; prefer :func:holm_correction (uniformly more powerful, same
guarantee) or :func:benjamini_hochberg_correction (FDR control).
Source code in src/cds2/stats.py
474 475 476 477 478 479 480 481 482 483 484 485 | |
holm_correction(p_values)
Holm-Bonferroni step-down family-wise error rate correction.
Sorted p-values are scaled by m, m-1, ..., 1, made non-decreasing
with a running maximum and capped at 1, then returned in the original
order. Controls the family-wise error rate like Bonferroni but is
uniformly at least as powerful (adjusted values never exceed
Bonferroni's).
Source code in src/cds2/stats.py
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | |
benjamini_hochberg_correction(p_values)
Benjamini-Hochberg step-up false discovery rate (FDR) correction.
Sorted p-values are scaled by m / rank, made non-decreasing from
the largest downwards with a running minimum and capped at 1, then
returned in the original order. Comparing adjusted values against
alpha controls the expected proportion of false discoveries among
the rejected hypotheses at alpha (under independence or positive
dependence). Less conservative than family-wise corrections: the right
default when scanning many candidate effects, e.g. hypothesis mining.
Source code in src/cds2/stats.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | |