Fitting and Roadmap¶
roadmap
¶
Development roadmap and future features for HeavyTails library.
This module contains placeholder functions and TODO items that will be automatically converted to GitHub Issues by the TODO workflow.
bootstrap_confidence_intervals
¶
bootstrap_confidence_intervals(
data,
distribution,
n_bootstrap=1000,
confidence_level=0.95,
seed=None,
)
Calculate bootstrap confidence intervals for distribution parameters.
Uses percentile bootstrap method to quantify uncertainty in MLE estimates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
list[float]
|
Sample data |
required |
distribution
|
str
|
Name of distribution to fit |
required |
n_bootstrap
|
int
|
Number of bootstrap samples (default: 1000) |
1000
|
confidence_level
|
float
|
Confidence level, e.g., 0.95 for 95% CI (default: 0.95) |
0.95
|
seed
|
int | None
|
Random seed for reproducibility (default: None) |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, tuple[float, float]]
|
Dictionary with parameter names as keys and (lower, upper) CI tuples as values |
Examples:
>>> from heavytails import Pareto
>>> dist = Pareto(alpha=2.5, xm=1.0)
>>> data = dist.rvs(500, seed=42)
>>> ci = bootstrap_confidence_intervals(data, 'pareto', n_bootstrap=100, seed=42)
>>> 'alpha' in ci
True
>>> ci['alpha'][0] < 2.5 < ci['alpha'][1] # Should contain true value
True
Source code in heavytails/roadmap.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 | |
fit_mle
¶
Fit distribution parameters using Maximum Likelihood Estimation.
Supports analytical and numerical MLE for all distributions in the library. For distributions without closed-form MLEs, uses scipy.optimize if available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
list[float]
|
Sample data to fit |
required |
distribution
|
str
|
Name of distribution (case-insensitive) Supported: 'pareto', 'lognormal', 'weibull', 'cauchy', 'studentt', 'exponential', 'frechet', 'generalizedpareto', 'burrxii', 'loglogistic', 'inversegamma', 'betaprime' |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary of fitted parameter names and values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If distribution is unknown or data is invalid |
ImportError
|
If scipy is required but not available |
Examples:
>>> import random
>>> from heavytails import Pareto
>>> dist = Pareto(alpha=2.5, xm=1.0)
>>> data = dist.rvs(1000, seed=42)
>>> params = fit_mle(data, 'pareto')
>>> abs(params['alpha'] - 2.5) < 0.2 # Should be close
True
Source code in heavytails/roadmap.py
model_comparison
¶
Compare distribution fits using information criteria.
Computes AIC and BIC for each distribution and ranks them. Lower values indicate better fit (penalized by model complexity).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
list[float]
|
Sample data |
required |
distributions
|
list[str]
|
List of distribution names to compare |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
Dictionary with results for each distribution containing: - params: Fitted parameters - log_likelihood: Log-likelihood value - AIC: Akaike Information Criterion - BIC: Bayesian Information Criterion - rank_AIC: Rank by AIC (1 = best) - rank_BIC: Rank by BIC (1 = best) |
Examples:
>>> from heavytails import Pareto
>>> dist = Pareto(alpha=2.5, xm=1.0)
>>> data = dist.rvs(1000, seed=42)
>>> results = model_comparison(data, ['pareto', 'lognormal', 'weibull'])
>>> results['pareto']['rank_AIC'] # Pareto should rank best
1
Source code in heavytails/roadmap.py
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 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 | |
robust_hill_estimator
¶
Improved Hill estimator with bias correction and stability checks.
Implements bias-corrected Hill estimator with automatic k selection and diagnostic information for assessing estimate reliability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
list[float]
|
Sample data (should be heavy-tailed) |
required |
k
|
int | None
|
Number of top order statistics to use. If None, automatically selected. |
None
|
bias_correction
|
bool
|
Apply second-order bias correction (default: True) |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, float | int | bool | str]
|
Dictionary containing: - gamma: Tail index estimate (gamma = 1/alpha for Pareto) - alpha: Shape parameter estimate (alpha = 1/gamma) - k_used: Number of order statistics used - bias_corrected: Whether bias correction was applied - n: Sample size - reliability: Quality indicator ('good', 'fair', 'poor') |
Examples:
>>> from heavytails import Pareto
>>> dist = Pareto(alpha=2.5, xm=1.0)
>>> data = dist.rvs(1000, seed=42)
>>> result = robust_hill_estimator(data)
>>> abs(result['alpha'] - 2.5) < 0.5 # Should be close
True
>>> result['reliability'] in ['good', 'fair', 'poor']
True
References
Dekkers, A. L., Einmahl, J. H., & De Haan, L. (1989). A moment estimator for the index of an extreme-value distribution. Annals of Statistics, 17(4), 1833-1855.
Source code in heavytails/roadmap.py
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 | |