biosppy.stats¶
biosppy.stats¶
This module provides statistical functions and related tools.
- copyright:
2015-2026 by Instituto de Telecomunicacoes
- license:
BSD 3-clause, see LICENSE for more details.
Functions
|
Compute statistical features from the first signal differences, second signal differences and absolute signal differences. |
|
Compute histogram of the input signal. |
|
Plot the linear regression between two signals and get the equation coefficients. |
|
Perform the Student's paired t-test on the arrays x and y. |
|
Compute the Pearson Correlation Coefficient between two signals. |
|
Compute quartile features of the signal. |
|
Perform the Student's unpaired t-test on the arrays x and y. |
- biosppy.stats.diff_stats(signal=None, stats_only=True)[source]¶
Compute statistical features from the first signal differences, second signal differences and absolute signal differences.
- Parameters:
signal (array) – Input signal.
stats_only (bool, optional) – Whether to output only statistical features. Default is True.
- Returns:
{diff} (array) – Difference signal. {diff} can be ‘diff’, ‘diff2’ or ‘abs_diff’.
{diff}_mean (float) – Mean of the difference signal.
{diff}_median (float) – Median of the difference signal.
{diff}_min (float) – Minimum of the difference signal.
{diff}_max (float) – Maximum of the difference signal.
{diff}_max_amp (float) – Maximum amplitude of the difference signal.
{diff}_range (float) – Range of the difference signal.
{diff}_var (float) – Variance of the difference signal.
{diff}_std (float) – Standard deviation of the difference signal.
{diff}_sum (float) – Sum of the difference signal.
- biosppy.stats.histogram(signal=None, bins=5, normalize=True)[source]¶
Compute histogram of the input signal.
- Parameters:
signal (array) – Input signal.
bins (int, optional) – Number of histogram bins. Default is 5.
normalize (bool, optional) – Whether to normalize the histogram counts. Default is True.
- Returns:
hist{bin}_bins (float) – Number of counts of the bin. If normalize is True, the counts are normalized.
- biosppy.stats.linear_regression(x=None, y=None, show=True)[source]¶
Plot the linear regression between two signals and get the equation coefficients.
The linear regression uses the least squares method.
- Parameters:
x (array) – First input signal.
y (array) – Second input signal.
show (bool) – If True, show the plot.
- Returns:
coeffs (array) – Linear regression coefficients: [m, b].
- Raises:
ValueError – If the input signals do not have the same length.
- biosppy.stats.paired_test(x=None, y=None)[source]¶
Perform the Student’s paired t-test on the arrays x and y. This is a two-sided test for the null hypothesis that 2 related or repeated samples have identical average (expected) values.
- Parameters:
x (array) – First input signal.
y (array) – Second input signal.
- Returns:
statistic (float) – t-statistic. The t-statistic is used in a t-test to determine if you should support or reject the null hypothesis.
pvalue (float) – Two-sided p-value.
- Raises:
ValueError – If the input signals do not have the same length.
- biosppy.stats.pearson_correlation(x=None, y=None)[source]¶
Compute the Pearson Correlation Coefficient between two signals.
The coefficient is given by:
![r_{xy} = \frac{E[(X - \mu_X) (Y - \mu_Y)]}{\sigma_X \sigma_Y}](../_images/math/25984ac0b99af0b57d7d197c63928096548adcb5.png)
- Parameters:
x (array) – First input signal.
y (array) – Second input signal.
- Returns:
r (float) – Pearson correlation coefficient, ranging between -1 and +1.
pvalue (float) – Two-tailed p-value. The p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Pearson correlation at least as extreme as the one computed from these datasets.
- Raises:
ValueError – If the input signals do not have the same length.
- biosppy.stats.quartiles(signal=None)[source]¶
Compute quartile features of the signal.
- Parameters:
signal (array) – Input signal.
- Returns:
q1 (float) – First quartile.
q2 (float) – Second quartile, also known as median.
q3 (float) – Third quartile.
iqr (float) – Interquartile range.
midhinge (float) – Midhinge.
trimean (float) – Trimean.
- biosppy.stats.unpaired_test(x=None, y=None)[source]¶
Perform the Student’s unpaired t-test on the arrays x and y. This is a two-sided test for the null hypothesis that 2 independent samples have identical average (expected) values. This test assumes that the populations have identical variances by default.
- Parameters:
x (array) – First input signal.
y (array) – Second input signal.
- Returns:
statistic (float) – t-statistic. The t-statistic is used in a t-test to determine if you should support or reject the null hypothesis.
pvalue (float) – Two-sided p-value.
- Raises:
ValueError – If the input signals do not have the same length.