smpl.stat

Simplified statistics.

Submodules

Package Contents

Functions

R2(y, f)

R2 - Coefficient of determination

Chi2(y, f[, sigmas])

Chi2 - Goodness of Fit

average_deviation(y, f)

fft(y)

Compute the FFT of y.

get_interesting_domain(f[, min_ch])

Return interesting xmin and xmax of function f.

mean(n)

Return mean of n with combined error of variance and unvertainties of n.

no_dist(N)

Return N with no uncertainties.

noisy(x[, mean, std])

Add gaussian noise to x.

normalize(ydata)

Return normalized ydata.

novar_mean(n)

Return mean of n with only the uncertainties of n and no variance.

poisson_dist(N)

Return N with added poissonian uncertainties.

unv_lambda(f)

Returns a function which applies unv() on the result of f.

Attributes

unv

usd

smpl.stat.R2(y, f)[source]

R2 - Coefficient of determination

In the best case, the modeled values exactly match the observed values, which results in R2 = 1. A baseline model, which always predicts the mean of y, will have R2 = 0. Models that have worse predictions than this baseline will have a negative R2.

References

https://en.wikipedia.org/wiki/Coefficient_of_determination

smpl.stat.Chi2(y, f, sigmas=None)[source]

Chi2 - Goodness of Fit

In general, if Chi-squared/Nd is of order 1.0, then the fit is reasonably good. Coversely, if Chi-squared/Nd >> 1.0, then the fit is a poor one.

References

https://www.phys.hawaii.edu/~varner/PHYS305-Spr12/DataFitting.html

smpl.stat.average_deviation(y, f)[source]
smpl.stat.fft(y)[source]

Compute the FFT of y.

Parameters

yarray_like

Data to be transformed.

Returns

array_like

smpl.stat.get_interesting_domain(f, min_ch=1e-06)[source]

Return interesting xmin and xmax of function f.

Examples

>>> def f(x):
...     return np.sin(x)
>>> get_interesting_domain(f)
(-3.141625000000003, 3.141625000000003)
smpl.stat.mean(n)[source]

Return mean of n with combined error of variance and unvertainties of n.

Parameters

narray_like

Data to be averaged.

Returns

uncertainties.unumpy.uarray

Mean of n.

Examples

>>> n = np.array([1, 2, 3, 4, 5])
>>> mean(n)
3.0+/-1.5811388300841898
smpl.stat.no_dist(N)[source]

Return N with no uncertainties.

smpl.stat.noisy(x, mean=1, std=0.1)[source]

Add gaussian noise to x.

Parameters

xarray_like

Data to be smeared.

meanfloat

Mean of gaussian noise.

stdfloat

Standard deviation of gaussian noise.

Returns

array_like

Smeared data.

Examples

>>> x = np.array([1, 2, 3, 4, 5])
>>> noisy(x,std=0)
array([1., 2., 3., 4., 5.])
smpl.stat.normalize(ydata)[source]

Return normalized ydata.

Parameters

ydataarray_like

Data to be normalized.

Returns

array_like

Normalized data.

Examples

>>> ydata = np.array([1, 2, 3, 4, 5])
>>> normalize(ydata)
array([0.  , 0.25, 0.5 , 0.75, 1.  ])
smpl.stat.novar_mean(n)[source]

Return mean of n with only the uncertainties of n and no variance.

smpl.stat.poisson_dist(N)[source]

Return N with added poissonian uncertainties.

Parameters

Nfloat or array_like of floats

Number of events.

Returns

uncertainties.unumpy.uarray

Number of events with uncertainties.

Examples

>>> poisson_dist(100)
array(100.0+/-10.0, dtype=object)
smpl.stat.unv[source]
smpl.stat.unv_lambda(f)[source]

Returns a function which applies unv() on the result of f.

smpl.stat.usd[source]