{"id":20989740,"url":"https://github.com/robtillaart/statistic","last_synced_at":"2025-05-14T18:32:05.634Z","repository":{"id":43213500,"uuid":"263598767","full_name":"RobTillaart/Statistic","owner":"RobTillaart","description":"Statistic library for Arduino includes sum, average, variance and std deviation","archived":false,"fork":false,"pushed_at":"2024-08-27T07:16:26.000Z","size":49,"stargazers_count":27,"open_issues_count":0,"forks_count":11,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-27T21:32:22.807Z","etag":null,"topics":["arduino","statistics"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobTillaart.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"RobTillaart","custom":"https://www.paypal.me/robtillaart"}},"created_at":"2020-05-13T10:32:56.000Z","updated_at":"2024-08-27T07:15:22.000Z","dependencies_parsed_at":"2023-11-22T11:27:30.586Z","dependency_job_id":"bc390697-8fa7-42b1-aae1-1e69f0681675","html_url":"https://github.com/RobTillaart/Statistic","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FStatistic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FStatistic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FStatistic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FStatistic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobTillaart","download_url":"https://codeload.github.com/RobTillaart/Statistic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225305575,"owners_count":17453409,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","statistics"],"created_at":"2024-11-19T06:26:00.278Z","updated_at":"2024-11-19T06:26:00.855Z","avatar_url":"https://github.com/RobTillaart.png","language":"C++","funding_links":["https://github.com/sponsors/RobTillaart","https://www.paypal.me/robtillaart"],"categories":[],"sub_categories":[],"readme":"\n[![Arduino CI](https://github.com/RobTillaart/Statistic/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)\n[![Arduino-lint](https://github.com/RobTillaart/Statistic/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/Statistic/actions/workflows/arduino-lint.yml)\n[![JSON check](https://github.com/RobTillaart/Statistic/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/Statistic/actions/workflows/jsoncheck.yml)\n[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/Statistic.svg)](https://github.com/RobTillaart/Statistic/issues)\n\n[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/Statistic/blob/master/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/RobTillaart/Statistic.svg?maxAge=3600)](https://github.com/RobTillaart/Statistic/releases)\n[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/Statistic.svg)](https://registry.platformio.org/libraries/robtillaart/Statistic)\n\n\n# Statistic\n\nHeader-only statistic library for Arduino includes sum, average, variance and standard deviation.\n\nThe `statistic::Statistic\u003cT, C, bool _useStdDev\u003e` class template accepts 3 arguments:\n\n* **`typename T`:** The floating point type used to represent the statistics.\n* **`typename C`:** The unsigned integer type to store the number of values.\n* **`typename _useStdDev`:** Compile-time flag for using variance and standard deviation.\n\nTo maintain backwards compatibility with API \u003c= 0.4.4, the `Statistic`\nclass implementation has been moved to the `statistic` namespace and a\n`typedef statistic::Statistic\u003cfloat, uint32_t, true\u003e Statistic` type\ndefinition has been created at global scope.\n\nThe `useStdDev` boolean was moved from a run-time to a compile-time\noption for two reasons.  First, the compile-time option allows the\noptimizer to eliminate dead code (calculating standard deviation and\nvariances) for a slightly smaller code size.  Second, it was observed\nin uses of the library that the `useStdDev` boolean was set once in\nthe class constructor and was never modified at run-time.\n\n\n## Description\n\nThe statistic library is made to get basic statistical information from a \none dimensional set of data, e.g. a stream of values of a sensor.\n\nThe stability of the formulas is improved by the help of Gil Ross (Thanks!).\n\nThe template version (1.0.0) is created by Glen Cornell  (Thanks!).\n\n\n#### Related\n\n- https://github.com/RobTillaart/Correlation\n- https://github.com/RobTillaart/GST - Golden standard test metrics\n- https://github.com/RobTillaart/Histogram\n- https://github.com/RobTillaart/RunningAngle\n- https://github.com/RobTillaart/RunningAverage\n- https://github.com/RobTillaart/RunningMedian\n- https://github.com/RobTillaart/statHelpers - combinations \u0026 permutations\n- https://github.com/RobTillaart/Statistic\n- https://github.com/RobTillaart/Student\n\n\n## Interface\n\n```cpp\n#include \"Statistic.h\"\n```\n\n#### Constructor\n\n- **Statistic(void)** Default constructor.\n- **statistic::Statistic\u003cfloat, uint32_t, true\u003e** Constructor, with value type, count type, and standard deviation flag.\nThe types mentioned are the defaults of the template. \nYou can override e.g. **statistic::Statistic\u003cdouble, uint64_t, false\u003e** for many high precision values. \n(assumes double \u003e\u003e float).\n- **void clear()** resets all internal variables and counters.\n\n\n#### Core\n\n- **typename T add(const typename T value)** returns value actually added to internal sum.\nIf this differs from what should have been added, or even zero, the internal administration is running out of precision.\nIf this happens after a lot of **add()** calls, it might become time to call **clear()**.\nAlternatively one need to define the statistic object with a more precise data type (typical double instead of float).\n- **typename C count()**    returns zero if count == zero (of course). Must be checked to interpret other values.\n- **typename T sum()**      returns zero if count == zero.\n- **typename T minimum()**  returns zero if count == zero.\n- **typename T maximum()**  returns zero if count == zero.\n- **typename T range()**    returns maximum - minimum. \n- **typename T middle()**   returns (minimum + maximum)/2. If T is an integer type rounding errors are possible.\n- **typename T average()**  returns NAN if count == zero.\n\nThese three functions only work if **useStdDev == true** (in the template).\n\n- **typename T variance()**      returns NAN if count == zero.\n- **typename T pop_stdev()**     returns NAN if count == zero.\npop_stdev = population standard deviation, \n- **typename T unbiased_stdev()** returns NAN if count == zero.\n- **typename T getCoefficientOfVariation()** returns coefficient of variation.\nThis is defined as standardDeviation / Average. \nIt indicates if the distribution is relative small ( \u003c 1) or relative wide ( \u003e 1).\nNote it has no meaning when the average is zero (or close to zero).\n\n\n#### Deprecated methods\n\n- **Statistic(bool)** Constructor previously used to enable/disable the standard deviation functions. \nThis argument now has no effect.  It is recommended to migrate your code to the default constructor \n(which now also implicitly calls `clear()`).\n- **void clear(bool)** resets all variables.  The boolean argument is ignored. \nIt is recommended to migrate your code to `clear()` (with no arguments).\n\n\n#### Range() and middle()\n\n**Range()** and **middle()** are fast functions with limited statistical value. \nStill they have their uses.\n\nGiven enough samples (e.g. 100+) and a normal distribution of the samples the **range()** is expected \nto be 3 to 4 times the **pop_stdev()**. \nIf the range is larger than 4 standard deviations one might have added one or more outliers.\n\nGiven enough samples (e.g. 100+) and a normal distribution, the **middle()** and **average()** are \nexpected to be close to each other.\nNote: outliers can disrupt the **middle()**, Several non-normal distributions do too.\n\n\n## Operational\n\nSee examples.\n\n\n## Faq\n\nSee https://github.com/RobTillaart/Statistic/blob/master/FAQ.md\n\n\n## Future\n\n#### Must\n\n- update documentation\n  - links that explain statistics in more depth\n\n#### Should\n\n- remove deprecated methods. (1.1.0)\n\n#### Could\n\n- add **expected average EA** compensation trick\n  - every add will subtract EA before added to sum, \n  - this will keep the **\\_sum** to around zero.\n  - this will move **average()** to around zero.\n  - do not forget to add **EA** to average.\n  - do not forget to add **EA** times count for sum.\n  - does not affect the **std_dev()**\n  - all functions will become slightly slower.\n  - maybe in a derived class?\n- **lastTimeAdd()** convenience, user can track timestamp\n- **largestDelta()** largest difference between two consecutive additions.\n  - need lastValue + delta so far.\n\n#### Wont\n\n- return values of **sum(), minimum(), maximum()** when **count()** == zero\n  - should these be NaN, which is technically more correct?\n  - does it exist for all value types? =\u003e No!\n  - user responsibility to check **count()** first.\n\n\n## Support\n\nIf you appreciate my libraries, you can support the development and maintenance.\nImprove the quality of the libraries by providing issues and Pull Requests, or\ndonate through PayPal or GitHub sponsors.\n\nThank you,\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobtillaart%2Fstatistic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobtillaart%2Fstatistic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobtillaart%2Fstatistic/lists"}