pyhctsa.operations.distribution.compare_ks_fit

pyhctsa.operations.distribution.compare_ks_fit(x, what_distn)

Compares a fitted distribution with the smoothed distribution of the data.

Fits a standard distribution to the data (by maximum likelihood) and compares it with a kernel-smoothed estimate of the distribution of the values. (“KS” here means kernel-smoothed, not Kolmogorov-Smirnov.) Both curves are evaluated on a common grid of 1000 points that covers the smoothed distribution and the body of the fitted distribution (out to where it falls to 1/100 of its peak, found by root finding; or, for a positive-only distribution whose density is unbounded or maximal at 0, from 0 to its 0.99 quantile). The smoothed distribution is evaluated at the grid points, and the fitted distribution as its mean density over each grid cell (its probability in the cell divided by the cell width), which stays finite where the density diverges. They are then compared by the area between them, the separation of their peaks, their overlap, and the relative entropy.

The exponential and Rayleigh distributions require non-negative values, and the gamma, log-normal and Weibull distributions require positive values; NaN is returned if the data do not satisfy this (and for a constant series in the Rayleigh and exponential cases). For the beta distribution, the data are first rescaled to lie inside (0, 1), and all outputs are then in rescaled units.

Parameters:
x : array-like

The input data vector.

what_distn : str

The type of distribution to fit to the data:
  • ’norm’: Gaussian

  • ’ev’: extreme value

  • ’uni’: uniform

  • ’beta’: beta

  • ’rayleigh’: Rayleigh

  • ’exp’: exponential

  • ’gamma’: gamma

  • ’logn’: log-normal

  • ’wbl’: Weibull

Returns:

adiff: the absolute area between the two distributions (0 for a perfect match, at most 2); peaksepy: the maximum of the fitted distribution minus that of the smoothed distribution; peaksepx: the position of the peak of the fitted distribution minus that of the smoothed distribution (NaN for the uniform, which has no peak); olapint: the overlap integral of the two distributions, multiplied by the standard deviation of the data so that it does not depend on their scale; relent: the relative entropy (Kullback-Leibler divergence), in nats, of the fitted distribution from the smoothed distribution.

Return type:

dict

Notes

adiff, olapint and relent do not depend on the scale of the data, but peaksepy and peaksepx do.