spei.dist module

class spei.dist.Dist(data: pandas.core.series.Series, dist: Any | scipy.stats._distn_infrastructure.rv_continuous, prob_zero: bool = False, data_window: pandas.core.series.Series | None = None)

Bases: object

cdf() Series

Compute cumulative density function of a Scipy Continuous Distribution

data: Series
data_window: Series | None = None

Represents a distribution associated with data.

Parameters:
  • data (Series) – The input data for fitting the distribution.

  • dist (ContinuousDist) – The SciPy continuous distribution associated to be fitted.

  • prob_zero (bool, default=False) – Flag indicating whether the probability of zero values in the series is calculated by the occurence.

  • data_window (Optional[Series], default=None) – Subset of data for fitting more data (if provided).

  • loc (float) – Location of the distribution

  • scale (float) – Scale of the distribution

  • pars (Optional[List[float]]) – Attribute storing additional distribution parameters (if applicable).

  • p0 (float) – The probability of zero values in the data. Only calculated if prob_zero=True.

Notes

The fit_dist method uses the dist.fit function from Scipy to estimate distribution parameters. If the fitted distribution requires additional parameters beyond loc and scale, they are stored in the pars attribute.

dist: Any | rv_continuous
static fit_dist(data: Series, dist: Any | rv_continuous) tuple[list[float] | None, float, float]

Fits a Scipy continuous distribution to the data.

Parameters:
  • data (Series) – The input data for fitting.

  • dist (ContinuousDist) – The continuous distribution to be fitted.

Returns:

Tuple containing distribution parameters (pars, loc, scale).

Return type:

Tuple

ks_test(method: Literal['auto', 'exact', 'approx', 'asymp'] = 'auto') float

Fit a distribution and perform the two-sided Kolmogorov-Smirnov test for goodness of fit. The null hypothesis is that the data and distributions are identical, the alternative is that they are not identical.

Parameters:

method (Literal['auto', 'exact', 'approx', 'asymp'], optional) – Defines the distribution used for calculating the p-value. The following options are available (default is ‘auto’): ‘auto’ selects one of the other options, ‘exact’ uses the exact distribution of test statistic, ‘approx’ approximates the two-sided probability with twice the one-sided probability, ‘asymp’ uses asymptotic distribution of test statistic

Returns:

p-value

Return type:

float

References

Onnen, H.: Intro to Probability Distributions and Distribution Fitting with Pythons SciPy, 2021.

loc: float
p0: float = 0.0
pars: list[float] | None
pdf() Series
ppf(q: float) Series

Compute percent point function (inverse of cdf) at q

prob_zero: bool = False
scale: float