{"id":18521761,"url":"https://github.com/simphotonics/sample_statistics","last_synced_at":"2026-04-02T02:53:38.400Z","repository":{"id":56838490,"uuid":"307851285","full_name":"simphotonics/sample_statistics","owner":"simphotonics","description":"Sample statistics, histograms, probability distributions, and random sample generators for Dart. ","archived":false,"fork":false,"pushed_at":"2024-05-30T17:32:27.000Z","size":855,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T04:43:25.693Z","etag":null,"topics":["error-function","probability-distribution","random","random-number-generators","sample","statistics"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/sample_statistics","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simphotonics.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"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}},"created_at":"2020-10-27T23:15:40.000Z","updated_at":"2024-05-30T17:32:30.000Z","dependencies_parsed_at":"2024-05-30T20:28:55.811Z","dependency_job_id":null,"html_url":"https://github.com/simphotonics/sample_statistics","commit_stats":{"total_commits":104,"total_committers":1,"mean_commits":104.0,"dds":0.0,"last_synced_commit":"909d4344f26fd4e8912cd4e4c8c00eaa0016b738"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Fsample_statistics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Fsample_statistics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Fsample_statistics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simphotonics%2Fsample_statistics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simphotonics","download_url":"https://codeload.github.com/simphotonics/sample_statistics/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248012864,"owners_count":21033254,"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":["error-function","probability-distribution","random","random-number-generators","sample","statistics"],"created_at":"2024-11-06T17:27:31.212Z","updated_at":"2026-04-02T02:53:38.353Z","avatar_url":"https://github.com/simphotonics.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Sample Statistics\n[![Dart](https://github.com/simphotonics/sample_statistics/actions/workflows/dart.yml/badge.svg)](https://github.com/simphotonics/sample_statistics/actions/workflows/dart.yml)\n\n\n## Introduction\n\nThe package [`sample_statistics`][sample_statistics] provides helpers for\ncalculating *statistics* of numerical samples and generating/exporting\n*histograms*. It includes common *probability\ndistribution* functions, an approximation of the *error function*,\nand random sample *generators*.\n\nThroughout the library the acronym *Pdf* stands for *Probability Distribution\nFunction*, while *Cdf* stands for *Cummulative Distribution Function*.\n\n## Usage\n\nTo use this package include [`sample_statistics`][sample_statistics]\nas a dependency in your `pubspec.yaml` file.\n\n### 1. Sample Statistics\n\nTo access sample statistics use the class [`Stats`][Stats].\nIt calculates sample statistics in a lazy fashion and caches results\nto avoid expensive calculations if the\nsame quantity is accessed repeatedly. Data points can be added using the\nmethod `addDataPoints()`. A call to `addDataPoint` triggers a call to\n`updateCache()` to recalculate the sample statistics.\n\nTo remove outliers use the method `removeOutliers`.\n\n```Dart\n import 'package:sample_statistics/sample_statistics.dart'\n\n void main() {\n\n   final sample = \u003cnum\u003e[-10, 0, 1, 2, 3, 4, 5, 6, 20];\n   final stats = Stats(sample);\n\n   print('\\nRunning statistic_example.dart ...')\n   print('Sample: $sample');\n   print('min: ${stats.min}');\n   print('max:  ${stats.max}');\n   print('mean: ${stats.mean}');\n   print('median: ${stats.median}');\n   print('first quartile:  ${stats.quartile1}');\n   print('third quartile:  ${stats.quartile3}');\n   print('interquartile range:  ${stats.iqr}');\n   print('standard deviation:  ${stats.stdDev}');\n\n   final outliers = sample.removeOutliers();\n   print('outliers: $outliers');\n   print('sample with outliers removed:  $sample');\n   stats.addDataPoints([-2, 7]);\n   print('Sample with additional data points: ${stats.sample}');\n   print('Sorted sample: ${stats.sortedSample}');\n }\n```\n\n\u003cdetails\u003e  \u003csummary\u003e Click to show console output. \u003c/summary\u003e\n\n ```Console\n  $ dart  sample_statistics_example.dart\n  Running sample_statistics_example.dart ...\n  Sample: [-10, 0, 1, 2, 3, 4, 5, 6, 20]\n  min: -10\n  max: 20\n  mean: 3.4444444444444446\n  median: 3\n  first quartile: 1\n  third quartile: 5\n  inter-quartile-range:4\n  standard deviation: 7.779960011322538\n  outliers:[-10, 20]\n  Sample without outliers: [0, 1, 2, 3, 4, 5, 6]\n  Sample with additional data points: [0, 1, 2, 3, 4, 5, 6, -2, 7]\n  Sorted sample: [-2, 0, 1, 2, 3, 4, 5, 6, 7]\n\n ```\n\u003c/details\u003e\n\n### 2. Random Sample Generators\n\nThe library `sample_generators` includes functions for generating random samples\nthat follow the probability distribution functions listed below:\n * normal distribution,\n * truncated normal distribution,\n * exponential distribution,\n * uniform distribution,\n * triangular distribution.\n\nAdditionally, the library includes the function [`randomSample`][randomSample]\nwhich is based on the [rejection sampling][rejection-sampling] method.\nIt expects a callback of type [`ProbabilityDensity`][ProbabilityDensity]\nand can be used to generate random samples that follow\nan *arbitrary* probability distribution function.\n\nThe program listed below demonstrates how to generated a random sample\nand write a histogram to a file.\n\n```Dart\nimport 'dart:io';\n\n import 'package:sample_statistics/sample_statistics.dart';\n\n void main(List\u003cString\u003e args) async{\n   final xMmin = 1.0;\n   final xMmax = 9.0;\n   final meanOfParent = 5.0;\n   final stdDevOfParent = 2.0;\n   final sampleSize = 1000;\n\n   // Generating the random sample with 1000 entries.\n   final sample = truncatedNormalSample(\n     sampleSize,\n     xMmin,\n     xMmax,\n     meanOfParent,\n     stdDevOfParent,\n   );\n\n   final stats = Stats(sample);\n   print(stats.mean);\n   print(stats.stdDev);\n   print(stats.min);\n\n   // Exporting a histogram.\n   // Export histogram\n   await File('example/data/truncated_normal$sampleSize.hist').writeAsString(\n     sample.exportHistogram(\n       pdf: (x) =\u003e\n           truncatedNormalPdf(x, xMin, xMax, meanOfParent, stdDevOfParent),\n     ),\n   );\n\n }\n```\n\n### 3. Generating Histograms\n\nTo generate a histogram, the first step consists in dividing the random\nsample range into a suitable number of intervals.\nThe second step consists in counting how many sample entries fall into each\ninterval.\n\nThe figures below show the histograms obtained from two random samples that\nfollow a truncated normal distribution with\n`xMin = 2.0`, `xMax = 6.0` and normal parent distribution\nwith `meanOfParent = 3.0`, and `stdDevOfParent = 1.0`.\nThe random samples were generated using the function\n[`truncatedNormalSample`][truncatedNormalSample].\nThe histograms were generated using the extension method\n[`exportHistogram`][exportHistogram], see source code above.\n\n![Histogram](https://raw.githubusercontent.com/simphotonics/sample_statistics/main/images/histogram_truncated_normal.png)\n\n\nThe figure on the left shows the histogram of a sample with size 150.\nThe figure on the right shows the histogram of a sample with size 600.\nIncreasing the random sample size leads to an increasingly\ncloser match between the shape of the histogram and\nthe underlying probability distribution.\n\nUsing the distribution parameters mentioned above with the function\n[`meanTruncatedNormal`][meanTruncatedNormal],  one can determine\na theoretical mean of 3.2828. It can be seen that in the limit of a\nlarge sample size the *sample mean* approaches\nthe *mean* of the underlying probability distribution.\n\n\n\n## Examples\n\nFor further examples on how to generate random samples, export histograms,\nand access sample statistics see folder [example].\n\n\n\n## Features and bugs\n\nPlease file feature requests and bugs at the [issue tracker].\n\n[issue tracker]: https://github.com/simphotonics/sample_statistics/issues\n\n[example]: https://github.com/simphotonics/sample_statistics/tree/main/example\n\n[exportHistogram]:https://pub.dev/documentation/sample_statistics/latest/sample_statistics/StatisticsUtils/exportHistogram.html\n\n[histogram]: https://pub.dev/documentation/sample_statistics/latest/sample_statistics/Stats/histogram.html\n\n[meanTruncatedNormal]: https://pub.dev/documentation/sample_statistics/latest/sample_statistics/meanTruncatedNormal.html\n\n[ProbabilityDensity]: https://pub.dev/documentation/sample_statistics/latest/sample_statistics/ProbabilityDensity.html\n\n[normalPdf]: https://pub.dev/documentation/sample_statistics/latest/sample_statistics/normalPdf.html\n\n[randomSample]: https://pub.dev/documentation/sample_statistics/latest/sample_statistics/randomSample.html\n\n[rejection-sampling]: https://en.wikipedia.org/wiki/Rejection_sampling\n\n[sample_statistics]: https://pub.dev/packages/sample_statistics\n\n[samplePdf]: https://pub.dev/documentation/sample_statistics/latest/sample_statistics/samplePdf.html\n\n[Stats]: https://pub.dev/documentation/sample_statistics/latest/sample_statistics/Stats-class.html\n\n[truncatedNormalSample]: https://pub.dev/documentation/sample_statistics/latest/sample_statistics/truncatedNormalSample.html","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimphotonics%2Fsample_statistics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimphotonics%2Fsample_statistics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimphotonics%2Fsample_statistics/lists"}