stdDev property
Returns the corrected sample standard deviation.
- The sample must contain at least 2 entries.
- The normalization constant for the corrected standard deviation is
sample.length - 1
.
Implementation
num get stdDev {
if (sample.length < 2) {
throw ExceptionOf<SampleStats>(
message: 'Sample standard deviation can not be calculated.',
invalidState: sample,
expectedState: 'A sample with at least 2 entries.',
);
}
if (_stdDev == null) {
_stdDev = Lazy<double>(() => math.sqrt(
sample.fold<num>(
0,
(sum, current) =>
sum + (current - mean) * (current - mean)) /
(sample.length - 1),
));
return _stdDev!();
} else {
return _stdDev!();
}
}