PDF and ECDF¶
Manual and statsmodels empirical CDFs, PDF/ECDF overlay plots and combined goodness-of-fit reports.
get_pdf(data, dist, params=None, num_points=100)
¶
Compute PDF values for a distribution over the data range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like
|
Observed data (used to determine x-axis range). |
required |
dist
|
scipy.stats continuous_rv_generic
|
Distribution object. |
required |
params
|
tuple
|
Pre-fitted parameters. If None, the distribution is fitted to data. |
None
|
num_points
|
int
|
Number of evenly spaced x points for the PDF curve. |
100
|
Returns:
| Type | Description |
|---|---|
tuple of (np.ndarray, np.ndarray)
|
(x, pdf_values) over [min(data), max(data)]. |
Source code in utils/pdf_ecdf_utils.py
compute_manual_ecdf(data)
¶
Compute the empirical CDF from data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like
|
Observed data. |
required |
Returns:
| Type | Description |
|---|---|
tuple of (np.ndarray, np.ndarray)
|
(x, y) where x is sorted data and y is cumulative probability in [0, 1]. |
Source code in utils/pdf_ecdf_utils.py
compute_statsmodels_ecdf(data)
¶
Compute the empirical CDF using the statsmodels ECDF implementation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like
|
Observed data. |
required |
Returns:
| Type | Description |
|---|---|
tuple of (np.ndarray, np.ndarray)
|
(x, y) where x is sorted data and y is the ECDF evaluated at each point. |
Notes
This uses statsmodels.distributions.ECDF which handles ties consistently. For most use cases, compute_manual_ecdf gives identical results.
Source code in utils/pdf_ecdf_utils.py
plot_pdf_ecdf_overlay(data, dist, params=None, title='', annotate_ks=True, save_path=None)
¶
Plot ECDF with theoretical CDF overlay and optional KS test annotation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like
|
Observed data. |
required |
dist
|
scipy.stats continuous_rv_generic
|
Distribution object. |
required |
params
|
tuple
|
Pre-fitted parameters. If None, the distribution is fitted to data. |
None
|
title
|
str
|
Plot title. |
''
|
annotate_ks
|
bool
|
If True, annotates the plot with the KS test p-value. |
True
|
save_path
|
str
|
File path to save the figure. If None, the figure is not saved. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Source code in utils/pdf_ecdf_utils.py
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 | |
plot_enhanced_ecdf_comparison(data, dist_list, dist_labels=None, annotate_tests=True, title='ECDF vs Multiple Distributions', save_path=None)
¶
Plot ECDF alongside theoretical CDFs for multiple distributions with goodness-of-fit annotations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like
|
Observed data. |
required |
dist_list
|
list of scipy.stats continuous_rv_generic
|
List of distribution objects to compare against. |
required |
dist_labels
|
list of str
|
Custom labels for each distribution. Defaults to dist.name. |
None
|
annotate_tests
|
bool
|
If True, adds KS, Anderson-Darling, and Shapiro-Wilk test results as text annotation. |
True
|
title
|
str
|
Plot title. |
'ECDF vs Multiple Distributions'
|
save_path
|
str
|
File path to save the figure. |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
|
Source code in utils/pdf_ecdf_utils.py
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 | |
run_goodness_of_fit_tests(data, dist)
¶
Run a battery of goodness-of-fit tests against a specified distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array - like
|
Observed data. |
required |
dist
|
scipy.stats continuous_rv_generic
|
Distribution object to test against (must have .fit and .cdf methods). |
required |
Returns:
| Type | Description |
|---|---|
dict of str -> float
|
{'KS_stat': float, 'KS_p': float, 'AD_stat': float, 'Shapiro_p': float} |
Notes
- KS (Kolmogorov-Smirnov): tests max deviation between ECDF and fitted CDF.
- Anderson-Darling: weights differences more heavily in the tails.
- Shapiro-Wilk: specifically tests for normality (not the fitted dist).