statistics
Statistics package for easy and efficient data manipulation with many built-in mathematical functions and units.
Usage
Numeric extension:
import 'package:statistics/statistics.dart';
void main() {
var ns = [10, 20.0, 30];
print('ns: $ns');
var mean = ns.mean;
print('mean: $mean');
var sdv = ns.standardDeviation;
print('sdv: $sdv');
var squares = ns.square;
print('squares: $squares');
}
OUTPUT:
ns: [10, 20.0, 30]
mean: 20.0
sdv: 8.16496580927726
squares: [100.0, 400.0, 900.0]
Statistics
import 'package:statistics/statistics.dart';
void main() {
var ns = [10, 20.0, 30];
var statistics = ns.statistics;
print('Statistics.max: ${ statistics.max }');
print('Statistics.min: ${ statistics.min }');
print('Statistics.mean: ${ statistics.mean }');
print('Statistics.standardDeviation: ${ statistics.standardDeviation }');
print('Statistics.sum: ${ statistics.sum }');
print('Statistics.center: ${ statistics.center }');
print('Statistics.squaresSum: ${ statistics.squaresSum }');
print('Statistics: $statistics');
}
OUTPUT:
Statistics.max: 30
Statistics.min: 10
Statistics.mean: 20.0
Statistics.standardDeviation: 21.602468994692867
Statistics.sum: 60.0
Statistics.center: 20.0
Statistics.squaresSum: 1400.0
Statistics: {~20 +-21.6024 [10..(20)..30] #3.0}
CSV
import 'package:statistics/statistics.dart';
void main() {
var categories = <String, List<double?>>{
'a': [10.0, 20.0, null],
'b': [100.0, 200.0, 300.0]
};
var csv = categories.generateCSV();
print(csv);
}
OUTPUT:
#,a,b
1,10.0,100.0
2,20.0,200.0
3,0.0,300.0
Source
The official source code is hosted @ GitHub:
Features and bugs
Please file feature requests and bugs at the issue tracker.
Contribution
Any help from the open-source community is always welcome and needed:
- Found an issue?
- Please fill a bug report with details.
- Wish a feature?
- Open a feature request with use cases.
- Are you using and liking the project?
- Promote the project: create an article, do a post or make a donation.
- Are you a developer?
- Fix a bug and send a pull request.
- Implement a new feature.
- Improve the Unit Tests.
- Have you already helped in any way?
- Many thanks from me, the contributors and everybody that uses this project!
Statistics Dart package GitHub repo
Statistics Dart package for easy and efficient data manipulation with many built-in functions and units.
https://github.com/gmpassos/statistics
3 forks.
22 stars.
0 open issues.
Recent commits:
- Merge v1.2.2, GitHub
- Fix dart2js compilation of the new testsTwo `int` literals added by the audit tests exceed 2^53, which `dart2js`rejects outright ("can't be represented exactly in JavaScript"), failingthe whole file to compile and taking `statistics_base_test.dart` and`statistics_dynamic_int_test.dart` out of the Chrome run.- `statistics_base_test.dart`: compare against `squaresSumBigInt.toInt()` (the clamped value on the running platform) instead of the hard-coded int64 maximum. This also makes the assertion correct on the web, where the clamp is at 2^53, not 2^63.- `statistics_dynamic_int_test.dart`: build the large `int` at runtime. The values beyond the platform `int` range are already covered by the `DynamicInt.parse` cases in the test above.Verified with `dart test –platform chrome`: 352 tests pass.Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>Claude-Session: https://claude.ai/code/session_01SeKd27KB9LvaHFDodiDzPC, Graciliano M. P.
- Fix 7 bugs found auditing the packageFound by differential fuzzing (Decimal vs double, DynamicInt vs BigInt,the three numeric extension families against each other and againstreference implementations) plus targeted review. Each fix has aregression test that fails without it.`Decimal` modulo: `DynamicNumber.operator %` is documented as Euclideanand a whole `Decimal` delivers it (delegating to `DynamicInt`), but afractional one used a truncated division, taking the sign of thedividend. So `-7 % 3` was `2` while `-7.5 % 3` was `-1.5`. 14203 of30000 fuzzed pairs disagreed with `num.operator %`; now 0.`DynamicInt.digits`: the `toString()` fallback (values with 10+ digits)counted the `-` sign, while the fast path discarded it via `abs()`.`digits` sets the precision of the division remainder refinement, so`(-a) / b` and `-(a / b)` returned results of different precision in 18%of sampled pairs.`Statistics.compute`, three defects in the `BigInt` branch:- It truncated fractional values. The branch is selected automatically when `max > (maxSafeIntSqrt ~/ length)`, so an ordinary `List<double>` of values above ~31.6M was silently truncated: `[100000000.5, 100000001.25, 100000002.75].statistics.sum` gave `300000003` instead of `300000004.5`. `useBigIntToCompute: true` did it at any magnitude.- The overflow guard only checked `max`, so a collection of large negative ints overflowed the `int` squares sum, yielding a negative `squaresSum` and `squaresMean`.- `BigInt.toInt()` clamped `sum`/`squaresSum` to the maximum `int` – the very overflow the branch exists to avoid.`UnitLength`: `mi` to `mm`/`mic`/`nm` used a mile of 1609 m instead ofthe exact 1609.344 m, a 2.1e-4 relative error where every other mileconversion is at ~6 significant digits. The reverse factors are exact,so round trips through a mile lost 0.02%.CSV: values were quoted when they contained the separator but an inner`"` was never escaped, so `both, "x"` was written as `"both, "x""` andread back as 2 corrupted fields. Column names were never quoted, so aname containing the separator made the header declare more columns thanthe rows carry. Both now follow RFC 4180.Also verified clean (no defects found): combinations, primes, thenum/double/int extension families, and Bayes net inference.Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>Claude-Session: https://claude.ai/code/session_01SeKd27KB9LvaHFDodiDzPC, Graciliano M. P.
- Fix Decimal division by a value < 1 and NaN standardDeviationIssue #14: `Decimal._divideOperationByDecimalImpl` computed the resultprecision as `d.precision – other.precision` and asserted it wasnon-negative. When the division by `other._n` is exact (e.g. `5 / 0.5`,where `d` is `1.0` with precision `0` and `other.precision` is `1`) thevalue is negative, throwing an `assert`/`ArgumentError`. It now uses`_multiplyOperationByPrecisionShift`, which handles both directions ofthe shift.Issue #12: `Statistics.compute` and `StandardDeviationComputerNum`computed the variance as `squaresSum – sum²/length`, which sufferscatastrophic cancellation: for a collection of equal `double` values thevariance can be slightly negative, so `sqrt` returns `NaN` (7239 of20000 swept values of a 7-element collection). Both now use Welford'sonline algorithm, which is numerically stable and returns exactly `0.0`for equal elements. The `_compute(sum, squaresSum, length)` fallback,used when only the sums are available, clamps a negative variance at `0`(the `NaN` of an empty set is preserved).`Statistics.operator +` merged the deviation from the `BigInt` sums,which are truncated for a non-integer collection, yielding a wrongresult (`4.626895640200471` instead of `0.0` when merging two identical`double` collections). It now uses the parallel variance algorithm(Chan et al.) over the already computed deviations and means.Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>Claude-Session: https://claude.ai/code/session_01SeKd27KB9LvaHFDodiDzPC, Graciliano M. P.
- Merge v1.2.1, GitHub
Provides the list of the opensource Flutter apps collection with GitHub repository.