From b6731184738b6b00923031ae8f6a2c45cc47d294 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Sun, 23 Nov 2014 00:27:59 -0800 Subject: [PATCH] added simple confidence interval calc --- ostat.go | 7 +++++++ 1 file changed, 7 insertions(+) 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",