func incrementalDemo() { var d stats.Stats fmt.Printf("\n**** Descriptive Statistics, Incremental Updates **\n") fmt.Printf("** create a new descriptive stats struct:\n") fmt.Printf("var d stats.Stats\n") fmt.Printf("** update it with new values:\n") for i := 0; i < NUM_SAMPLES; i++ { x := rand.Float64()*100.0 - 25.0 // uniform samples in {-25, 75} fmt.Printf("d.Update(%v)\n", x) d.Update(x) } fmt.Printf("then request stats, for example: d.Count()\n") fmt.Printf("\n** Descriptive Statistics:\n") fmt.Printf("count = %v\n", d.Count()) fmt.Printf("min = %v\n", d.Min()) fmt.Printf("max = %v\n", d.Max()) fmt.Printf("sum = %v\n", d.Sum()) fmt.Printf("mean = %v\n", d.Mean()) fmt.Printf("standard deviation = %v\n", d.SampleStandardDeviation()) fmt.Printf("variance = %v\n", d.SampleVariance()) skew := d.SampleSkew() fmt.Printf("skew = %v\n", skew) // // The rand functions return uniformly distributed values. Therefore, with // enough samples, the skew should be 0. Try increasing NUM_SAMPLES if skew < 0.0 { fmt.Printf(" The sample is skews left (longer tail to left).\n") } else if skew > 0.0 { fmt.Printf(" The sample is skews right (longer tail to right).\n") } kurtosis := d.SampleKurtosis() fmt.Printf("kurtosis = %v\n", kurtosis) // // The rand functions return uniformly distributed values. Therefore, with // enough of them, our sample should be flat, or platykurtic. if kurtosis < 0.0 { fmt.Printf(" The sample is platykurtic.\n") } else if kurtosis > 0.0 { fmt.Printf(" The sample is leptokurtic.\n") } }