MyStatistic is a wrapper class for Rob Tillaart's Statistic
that is a recursive statistical library for Arduino IDE.
This library only adds a few methods to the original.
-
Data types
This library uses
floattype for input, output and internal variables to keep intermediate values. Please notice that the precision of the type is very limited as follows.-
Floating-point Data Types
In many MCU, typefloatanddoublehave storage of 32 bits (4 bytes), so the numbers can be as large as 3.4028235E+38 and as low as -3.4028235E+38, and have only 6-7 decimal digits of precision.
Please refer Arduino Reference. -
Integer Data Types
In many MCU, typelonghave storage of only 32 bits (4 bytes), so the numbers can be as large as 2,147,483,647 and as low as -2,147,483,648.
Please refer Arduino Reference.
-
-
Algorithm for calculation of variance and standard deviation
The original Statistic library uses a numarically stable, single-pass (online) algorithm like Welford's method.
-
- Input and output values has only 6-7 decimal digits of precision due to using
floattype (i.e., they have round-off error). - Results of sum, average, variance, and standard deviation are not free from the accumulation of small errors, such that the round-off error grows propotional to sample size n in worst case, when it sums sample values or squares of difference of sample values from the mean.
- Input and output values has only 6-7 decimal digits of precision due to using
MyStatistic stat;
MyStatistic stat(100.0, 0.1); // for backward compatibility. The arguments have no effect.
stat.clear();
Remove all the sampled values.
stat.add(120.11); // value is sampled as float type
unsigned long c = stat.count();
double su = stat.sum();
double mi = stat.minimum();
double ma = stat.maximum();
double av = stat.average();
Returns the number of samples, sum, minimum, maximum, and average value of the sampled values.
double s = stat.stdev(); // alias of pop_stdev()
double s = stat.pop_stdev();
stdev() or pop_stdev() retruns the standard deviation of the sampled values.
It is called as population standard deviation, or as uncorrected or biased sample stadard deviation
since it is a downward-biased estimator for the standard deviation of the population
(its value tends to be lower than the the standard deviation of the population when the sample size is small).
Please refer wiki.
double v = stat.variance();
variance() retruns the variance of the sampled values.
This is a biased estimator for the variance of the population.
Please refer wiki.
double s2 = stat.unbiased_stdev();
unbiased_stdev() retruns (unbiased) sample standard deviation.
This is nearly-unbiased estimator for the standard deviation of the population.
String text = stat.summary();
summary() returns a formated text like ave 4.5, min 2.3, max 5.6, cnt 213, stdev 0.32.
to be seen