github.com/gopherd/gonum@v0.0.4/stat/distuv/norm_example_test.go (about) 1 // Copyright ©2017 The Gonum Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package distuv_test 6 7 import ( 8 "fmt" 9 10 "github.com/gopherd/gonum/stat" 11 "github.com/gopherd/gonum/stat/distuv" 12 ) 13 14 func ExampleNormal() { 15 // Create a normal distribution 16 dist := distuv.Normal{ 17 Mu: 2, 18 Sigma: 5, 19 } 20 21 data := make([]float64, 1e5) 22 23 // Draw some random values from the standard normal distribution 24 for i := range data { 25 data[i] = dist.Rand() 26 } 27 28 mean, std := stat.MeanStdDev(data, nil) 29 meanErr := stat.StdErr(std, float64(len(data))) 30 31 fmt.Printf("mean= %1.1f ± %0.1v\n", mean, meanErr) 32 33 // Output: 34 // mean= 2.0 ± 0.02 35 }