spm1d

spm1d.util

Utility module

This module contains a variety of convenience functions, including:

  • get_dataset

  • interp

  • p_corrected_bonf

  • p_critical_bonf

  • smooth


get_dataset

spm1d.util.get_dataset(*args)[source]

Warning

Deprecated

get_dataset is deprecated and will be removed from future versions of spm1d. Please access datasets using the “spm1d.data” interface.


interp

spm1d.util.interp(y, Q=101)[source]

Simple linear interpolation to n values.

Parameters

  • y — a 1D array or list of J separate 1D arrays

  • Q — number of nodes in the interpolated continuum

Returns

  • Q-component 1D array or a (J x Q) array

Example

>>> y0 = np.random.rand(51)
>>> y1 = np.random.rand(87)
>>> y2 = np.random.rand(68)
>>> Y  = [y0, y1, y2]
>>> Y  = spm1d.util.interp(Y, Q=101)

p_corrected_bonf

spm1d.util.p_corrected_bonf(p, n)[source]

Bonferroni-corrected p value.

Warning

This correction assumes independence amongst multiple tests.

Parameters

  • p — probability value computed from one of multiple tests

  • n — number of tests

Returns

  • Bonferroni-corrected p value.

Example

>>> p = spm1d.util.p_corrected_bonf(0.03, 8)    # yields p = 0.216

p_critical_bonf

spm1d.util.p_critical_bonf(alpha, n)[source]

Bonferroni-corrected critical Type I error rate.

Warning

This crticial threshold assumes independence amongst multiple tests.

Parameters

  • alpha — original Type I error rate (usually 0.05)

  • n — number of tests

Returns

  • Bonferroni-corrected critical p value; retains alpha across all tests.

Example

>>> p = spm1d.util.p_critical_bonf(0.05, 20)    # yields p = 0.00256

smooth

spm1d.util.smooth(Y, fwhm=5.0)[source]

Smooth a set of 1D continua. This method uses scipy.ndimage.filters.gaussian_filter1d but uses the fwhm instead of the standard deviation.

Parameters

  • Y — a (J x Q) numpy array

  • fwhm — Full-width at half-maximum of a Gaussian kernel used for smoothing.

Returns

  • (J x Q) numpy array

Example

>>> Y0  = np.random.rand(5, 101)
>>> Y   = spm1d.util.smooth(Y0, fwhm=10.0)

Note

A Gaussian kernel’s fwhm is related to its standard deviation (sd) as follows:

>>> fwhm = sd * sqrt(8*log(2))