smpl.stat

Simplified statistics.

Chi2(y, f[, sigmas])

Chi2 - Goodness of Fit

R2(y, f)

R2 - Coefficient of determination

fft(y)

fft(y,t,sp,freq) = Compute the FFT of y.

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(arr)

Return the nominal values of the numbers in NumPy array arr.

unv_lambda(f)

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

usd(arr)

Return the standard deviations of the numbers in NumPy array arr.

Functions

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.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.fft(y)[source]

fft(y,t,sp,freq) = Compute the FFT of y.

Parameters
yarray_like

Data to be transformed.

Returns
array_like
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(arr)

Return the nominal values of the numbers in NumPy array arr.

Elements that are not numbers with uncertainties (derived from a class from this module) are passed through untouched (because a numpy.array can contain numbers with uncertainties and pure floats simultaneously).

If arr is of type unumpy.matrix, the returned array is a numpy.matrix, because the resulting matrix does not contain numbers with uncertainties.

smpl.stat.unv_lambda(f)[source]

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

smpl.stat.usd(arr)

Return the standard deviations of the numbers in NumPy array arr.

Elements that are not numbers with uncertainties (derived from a class from this module) are passed through untouched (because a numpy.array can contain numbers with uncertainties and pure floats simultaneously).

If arr is of type unumpy.matrix, the returned array is a numpy.matrix, because the resulting matrix does not contain numbers with uncertainties.