diff --git a/ostat.go b/ostat.go index ecbbad8..002ed27 100644 --- a/ostat.go +++ b/ostat.go @@ -95,6 +95,13 @@ func (os *OnlineStat) StdDev() float64 { return math.Sqrt(os.Variance()) } +func (os *OnlineStat) CI() (float64, float64) { + // 95% from http://mathworld.wolfram.com/ConfidenceInterval.html + conf := 1.95996 + dev := os.StdDev() / math.Sqrt(float64(os.n)) + return os.mean - dev*conf, os.mean + dev*conf +} + func (os *OnlineStat) String() string { return fmt.Sprintf( "%+v",