pyhctsa.operations.distribution.simple_fit¶
-
pyhctsa.operations.distribution.simple_fit(x, dmodel, num_bins=
'sqrt')¶ Fits a simple curve to the distribution of the values.
Fits a simple parametric curve to an estimate of the distribution of values in the time series, ignoring their temporal ordering. The distribution is estimated either as a histogram, with a specified number of bins, or as a kernel-smoothed density. The outputs measure the goodness of fit, and test the residuals (in order of increasing value) for remaining structure. The curve is fitted by least squares to the density in a deterministic way, with no random starts and no optimizer defaults (
pyhctsa.robust.bf_fit_density_curve()).- Parameters:¶
- x : array-like¶
The input data vector.
- dmodel : {'gauss1', 'gauss2', 'exp1', 'power1'}¶
The curve to fit: a Gaussian, the sum of two Gaussians, an exponential
a*exp(b*x), or a power lawa * x ** b(cannot be fit if any bin center is not positive; NaN is returned). NaN is also returned if there are no more bins than parameters of the model. (hctsa’s time-series models, the sinusoids and Fourier series, are fitted bysinusoid_fitin the spectral module; the names ‘sin1’, ‘sin2’, ‘sin3’ are passed on to it, as hctsa does.)- num_bins : int or str, optional¶
How to estimate the distribution: the name of a rule for the number of histogram bins (default
'sqrt'), the number of histogram bins, or 0 for a kernel-smoothed density.
- Returns:¶
r2: R-squared of the fit; adjr2: R-squared adjusted for the number of coefficients; rmse: root-mean-square error of the fit, in units of probability density of the standardized series (multiplied by the standard deviation of the data); resAC1, resAC2: autocorrelations of the residuals, in order of increasing value, at lags 1 and 2; resrunsz: the signed z-statistic of a runs test on the residuals (
pyhctsa.robust.bf_runs_z(); negative when the residuals have fewer runs about their median than expected for a random order); resAC1, resAC2 and resrunsz are NaN if the residuals have no variation beyond floating-point round-off, as for an exact fit (pyhctsa.robust.bf_residual_stats()). NaN (not a dict) if the model cannot be fitted, or for a constant series withnum_bins = 0.- Return type:¶
dict
Notes
The histogram has equal-width bins spanning the data with explicit edges (
pyhctsa.robust.bf_hist_edges(); a number of bins or a rule:'auto','fd','sqrt','sturges'), and the kernel-smoothed density ispyhctsa.robust.bf_ks_density(), so neither depends on the rounding of a histogram or kernel-density routine’s defaults.