SciDart
Normal distribution
Density, cumulative probability, quantiles, intervals and random samples of a normal distribution.
Like scipy.stats.norm
NormalDistribution(mean: m, std: s) is the equivalent of scipy.stats.norm(loc=m, scale=s).
| Method | Meaning |
|---|---|
pdf, logPdf |
density at x |
cdf |
P(X ≤ x) |
sf |
P(X > x), precise in the upper tail |
ppf |
quantile: the x with cdf(x) = p |
isf |
inverse of sf |
interval |
central interval with the given probability |
sample |
random values, with an optional Random for a fixed seed |
import 'dart:math' as math;
import 'package:scidart/numdart.dart';
import 'package:scidart/scidart.dart';
void main() {
// adult height in cm
var height = NormalDistribution(mean: 170, std: 8);
print('density at 170: ${height.pdf(170)}');
print('P(height < 180): ${height.cdf(180)}');
print('P(height > 190): ${height.sf(190)}');
print('95th percentile: ${height.ppf(0.95)}');
print('central 95%: ${height.interval(0.95).toList()}');
var s = height.sample(10000, random: math.Random(42));
print(
'sample mean: ${mean(s).toStringAsFixed(2)}, std: ${standardDeviation(s).toStringAsFixed(2)}');
}
Output
density at 170: 0.04986778505017909 P(height < 180): 0.8943502263331448 P(height > 190): 0.0062096653257761375 95th percentile: 183.1588290156118 central 95%: [154.32028812367957, 185.67971187632043] sample mean: 169.93, std: 7.92
ppf stays accurate in the extreme tails: ppf(1e-300) and even ppf(5e-324) match SciPy.
Loading the interactive demo…