stdDevTruncatedNormal function

num stdDevTruncatedNormal(
  1. num min,
  2. num max,
  3. num mean,
  4. num stdDev
)

Returns the standard deviation of a truncated normal distribution with minimum value min, maximum value max, mean mean, and standard deviation stdDev.

Implementation

num stdDevTruncatedNormal(num min, num max, num mean, num stdDev) {
  final alpha = (min - mean) / stdDev;
  final beta = (max - mean) / stdDev;
  final z = stdNormalCdf(beta) - stdNormalCdf(alpha);

  return stdDev *
      math.sqrt(1.0 +
          (alpha * stdNormalPdf(alpha) - beta * stdNormalPdf(beta)) / z -
          math.pow((stdNormalPdf(alpha) - stdNormalPdf(beta)) / z, 2));
}