Statistics#

The aim of the descriptive statistics is to provide

(Source code, html)

Number of Sample#

You can compute the number of the signal samples with the built-in function len().

>>> # number of signal samples
>>> len(Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]))
6

Sum of the Samples#

You can compute the sum \(x_{sum} = \sum\limits_{i=0}^{N}{x_i}\) of the signal samples \(N\) by calling the method sum().

>>> # sum of the signal samples
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).sum()
10.0

You can compute the sum \(x_{sum}\) of the signal samples with the built-in function sum().

>>> # sum of the signal samples
>>> sum(Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]))
10.0

Count Occurrences in the Samples#

You can count the occurrences of a sample \(x\) in the signal samples \(N\) by calling the method count().

>>> # count occurrences in the signal samples
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).count(1.5)
1

Sort the Samples#

You can sort the signal samples in ascending order by calling the method sort().

A new Trace instance labeled with the performed transformation 'sort' is returned.

>>> Trace('Signal', [1.3, 1.4, 1.5, 1.6, 1.7, 2.5]).sort()
Trace(label='Signal:sort', samples=[1.3, 1.4, 1.5, 1.6, 1.7, 2.5])

You can sort the signal samples in ascending order with the built-in function sorted().

>>> sorted(Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]))
[1.3, 1.4, 1.5, 1.6, 1.7, 2.5]

Winsorize the Samples#

You can winsorize the signal samples by calling the method winsorize(), either with the percentage limits of the number of samples shall be “trimmed” for each side of the ascending sorted signal samples, or with the percentage limit of the number of samples shall be “trimmed” from both sides.

>>> # winsorized signal samples with 20% of the largest samples trimmed
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).winsorize((None, 0.2))
Trace(label='Signal:winsorize', samples=[1.5, 1.6, 1.4, 1.7, 1.3, 1.7])
>>> # winsorized signal samples with 20% of the smallest samples trimmed
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).winsorize((0.2, None))
Trace(label='Signal:winsorize', samples=[1.5, 1.6, 1.4, 2.5, 1.4, 1.7])
>>> # winsorized signal samples with 20% of smallest and largest samples trimmed
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).winsorize(0.2)
Trace(label='Signal:winsorize', samples=[1.5, 1.6, 1.4, 1.7, 1.4, 1.7])

(Source code, html)

Mean of the Samples#

Note

The mean \(\overline{x}\) is the 1st common moment \(\mu_1\) in the descriptive statistics.

You can compute the arithmetic mean \(\overline{x} = \frac{1}{N} \cdot \sum\limits_{i=0}^{N}{x_i}\) of the signal samples \(N\) by calling the method mean().

>>> # arithmetic mean of the signal samples
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).mean()
1.6666666666666667

You can compute the arithmetic mean \(\overline{x}\) of the signal samples \(N\) with the function mean() of the statistics module.

>>> import statistics as stats
>>> # arithmetic mean of the signal samples
>>> stats.mean(list(Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7])))
1.6666666666666667

(Source code, html)

Weighted Mean of the Samples#

You can compute the linear weighted mean \(\overline{x_w} = \frac{2}{N \cdot (N + 1)} \cdot \sum\limits_{i=0}^{N}{(i+1) \cdot x_i}\) of the signal samples \(N\) by calling the method weighted_mean().

>>> # linear weighted mean of the signal samples
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).weighted_mean()
1.6952380952380948

(Source code, html)

Winsor Mean of the Samples#

You can compute the winsor mean \(\overline{x}_{w\alpha}\) of the signal samples \(N\) by calling the method winsor_mean(), either with the percentage limits of the number of samples shall be “trimmed” for each side of the ascending sorted signal samples, or with the percentage limit of the number of samples shall be “trimmed” from both sides.

>>> # mean of the signal samples with 20% of the largest samples trimmed
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).winsor_mean((None, 0.2))
1.5333333333333332
>>> # mean of the signal samples with 20% of the smallest samples trimmed
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).winsor_mean((0.2, None))
1.6833333333333333
>>> # mean of the signal samples with 20% of smallest and largest samples trimmed
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).winsor_mean(0.2)
1.55

(Source code, html)

Median of the Samples#

You can compute the median \(\overline{x}_{med}\) of the signal samples \(N\) by calling the method median().

>>> # median of the signal samples
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).median()
1.55

You can compute the median \(\overline{x}_{med}\) of the signal samples \(N\) with the function median() of the statistics module.

>>> import statistics as stats
>>> # median of the signal samples
>>> stats.median(Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]))
1.55

(Source code, html)

Mode of the Samples#

You can compute the mode \(\overline{x}_{mod}\) of the signal samples \(N\) by calling the method mode().

>>> # mode of the signal samples
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).mode()
1.5

You can compute the mode \(\overline{x}_{mod}\) of the signal samples \(N\) with the function mode() of the statistics module.

>>> import statistics as stats
>>> # mode of the signal samples
>>> stats.mode(Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]))
1.5

(Source code, html)

Root mean square of the Samples#

You can compute the root mean square \(x_{rms} = \sqrt{\frac{1}{N} \cdot \sum\limits_{i=0}^{N}{x_i^2}}\) of the signal samples \(N\) by calling the method rms().

>>> # median of the signal samples
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).rms()
1.7126976771553504

(Source code, html)

Minimum Sample#

You can get the minimum \(x_{min}\) within the signal samples \(N\) by calling the method min().

>>> # minimum signal value in the signal samples
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).min()
1.3

You can get the minimum \(x_{min}\) within the signal samples \(N\) with the built-in function min().

>>> # minimum signal value in the signal samples
>>> min(Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]))
1.3

Maximum Sample#

You can get the maximum \(x_{max}\) within the signal samples \(N\) by calling the method max().

>>> # maximum signal value in the signal samples
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).max()
2.5

You can get the maximum \(x_{max}\) within the signal samples \(N\) with the built-in function max().

>>> # maximum signal value in the signal samples
>>> max(Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]))
2.5

Range of the Samples#

You can compute the range \(x_{max} - x_{min}\) of the signal samples \(N\) by calling the method range().

>>> # range of the signal samples
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).range()
1.2

(Source code, html)

Mid-Range of the Samples#

You can compute the midrange \(\frac{x_{max} + x_{min}}{2}\) of the signal samples \(N\) by calling the method midrange().

>>> # mid-range of the signal samples
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).midrange()
1.9

(Source code, html)

Average Absolute Deviation of the Samples#

Note

The average absolute deviation is the 1st central moment \(m_1\) in the descriptive statistics.

You can compute the absolute error or average absolute deviation \(D_{mean} = m_1 = \frac{1}{N} \cdot \sum\limits_{i=0}^{N} {\left| x_i - \overline{x} \right|}\) of the signal samples \(N\) distribution.

>>> # average absolute deviation of the distribution
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).aad()
0.2888888888888889

(Source code, html)

Median Absolute Deviation of the Samples#

You can compute the median absolute deviation \(D_{med} = \frac{1}{N} \cdot \sum\limits_{i=0}^{N} {\left| x_i - \overline{x}_{med} \right|}\) of the signal samples \(N\) distribution.

>>> # median absolute deviation of the distribution
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).mad()
0.26666666666666666

(Source code, html)

Variance of the Samples#

Note

The variance \(\sigma^2\) is the 2nd central moment \(m_2\) in the descriptive statistics.

You can compute the biased sample variance \(s^2 = \sigma^2 = m_2 = \frac{1}{N} \cdot \sum\limits_{i=0}^{N} {(x_i - \overline{x})^2}\) of the signal samples \(N\) distribution by calling the method variance().

>>> # biased sample variance
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).variance()
0.15555555555555553

You can compute the biased sample variance \(s^2\) of the signal samples \(N\) distribution with the function pvariance() of the statistics module.

>>> import statistics as stats
>>> # biased sample variance
>>> stats.pvariance(Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]))
0.15555555555555556

You can compute the unbiased sample variance \(s^2\) of the signal samples \(N - 1\) distribution with the function variance() of the statistics module.

>>> import statistics as stats
>>> # unbiased sample variance
>>> stats.variance(Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]))
0.18666666666666668

(Source code, html)

Standard deviation of the Samples#

You can compute the biased sample standard deviation \(s = \sigma= \sqrt{\sigma^2} = \sqrt{m_2}\) of the signal samples \(N\) distribution by calling the method std().

>>> # biased sample standard deviation
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).std()
0.3944053188733077

You can compute the unbiased sample standard deviation \(s\) of the signal samples \(N - 1\) distribution with the function stdev() of the statistics module.

>>> import statistics as stats
>>> # unbiased sample standard deviation
>>> stats.stdev(Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]))
0.43204937989385733

(Source code, html)

Coefficient of Variation of the Samples#

You can compute the coefficient of variation \(c_v = \frac{\sigma}{\overline{x}}\) of the signal samples \(N\) distribution by calling the method coefficient().

>>> # coefficient of variation of the distribution
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).coefficient()
0.23664319132398462

(Source code, html)

Skew of the Samples#

Note

The skew is the 3rd central moment \(m_3\) in the descriptive statistics.

You can compute the biased sample skew \({m}_3 = \sum\limits_{i=0}^{N}{(\frac{x_i - \overline{x}}{\sigma})^3}\) of the signal samples \(N\) distribution by calling the method skew().

>>> # biased sample skew
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).skew()
1.3733756639338395

(Source code, html)

Kurtosis of the Samples#

Note

The kurtosis is the 4th central moment \(m_4\) in the descriptive statistics.

You can compute the biased sample kurtosis \({m}_4 = \sum\limits_{i=0}^{N}{(\frac{x_i - \overline{x}}{\sigma})^4}\) of the signal samples \(N\) distribution by calling the method kurtosis().

>>> # biased sample kurtosis
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).kurtosis()
3.4864285714285725

(Source code, html)

Distribution of the Samples#

Histogram Plot#

(Source code, html)

Empirical Cumulative Distribution Plot#

(Source code, html)

Distribution Plot#

(Source code, html)

Quantiles of the Samples#

You can compute the nth-quantile \(q_n\) of the signal samples with the function quantiles() of the statistics module.

>>> import statistics as stats
>>> # quartiles of the samples maximal value excluded
>>> stats.quantiles(Trace('Signal', range(11)))
[2.0, 5.0, 8.0]
>>> # quartiles of the samples maximal value included
>>> stats.quantiles(Trace('Signal', range(11)), method='inclusive')
[2.5, 5.0, 7.5]
>>> # deciles of the samples maximal value excluded
>>> stats.quantiles(Trace('Signal', range(11)), n=10)
[0.2, 1.4, 2.6, 3.8, 5.0, 6.2, 7.4, 8.6, 9.8]

Quartiles: Box Plot#

(Source code, html)

Quartiles: Violin Plot#

(Source code, html)

Z-Score of the Samples#

You can compute for each signal sample \(x\) the zscore \(z = \frac{x - \bar{x}}{\sigma}\) by calling the method zscore().

A new Trace instance labeled with the performed transformation 'zscore' is returned.

>>> # score for each signal sample
>>> Trace('Signal', [1.5, 1.6, 1.4, 2.5, 1.3, 1.7]).zscore()
Trace(label='Signal:zscore',
      samples=[-0.4225771273642585, -0.16903085094570328, -0.6761234037828138,
               2.1128856368212916, -0.9296696802013684, 0.08451542547285136])

(Source code, html)

Z-Score: Histogram Plot#

(Source code, html)