removeOutliers method Null safety
- [num factor = 1.5]
Removes and returns list entries with a value satisfying the condition:
value < (q1 - factor * iqr) || (q3 + factor * iqr) < value
where iqr = q3 - q1
is the inter-quartile range,
q1
is the first quartile,
and q3
is the third quartile.
Note: The default value of factor
is 1.5.
Implementation
List<T> removeOutliers([num factor = 1.5]) {
final stats = Stats(this);
final outliers = <T>[];
factor = factor.abs();
final iqr = stats.quartile3 - stats.quartile1;
final lowerFence = stats.quartile1 - factor * iqr;
final upperFence = stats.quartile3 + factor * iqr;
removeWhere((current) {
if (current < lowerFence || current > upperFence) {
outliers.add(current);
return true;
} else {
return false;
}
});
return outliers;
}