+// Ds, throwaways and drops can happen multiple times per point,
+// so they are Poisson distributed.
+//
+// Modified Wald (recommended by http://www.ine.pt/revstat/pdf/rs120203.pdf
+// since our rates are definitely below 2 per point).
+function make_poisson_ci(val, num, z, inverted)
+{
+ let low = (val == 0) ? 0.0 : ((val - 0.5) - Math.sqrt(val - 0.5)) / num;
+ let high = (val == 0) ? -Math.log(0.025) / num : ((val + 0.5) + Math.sqrt(val + 0.5)) / num;
+
+ // Fix the signs so that we don't get -0.00.
+ low = Math.max(low, 0.0);
+
+ // The display range of 0 to 0.25 is fairly arbitrary. So is the desired 0.05 per point.
+ let avg = val / num;
+ return {
+ 'val': avg,
+ 'lower_ci': low,
+ 'upper_ci': high,
+ 'min': 0.0,
+ 'max': 0.25,
+ 'desired': 0.05,
+ 'inverted': inverted,
+ };
+}
+