MCPcopy Index your code
hub / github.com/gonum/plot / newFiveStat

Function newFiveStat

plotter/boxplot.go:134–177  ·  view source on GitHub ↗
(w vg.Length, loc float64, values Valuer)

Source from the content-addressed store, hash-verified

132}
133
134func newFiveStat(w vg.Length, loc float64, values Valuer) (fiveStatPlot, error) {
135 var b fiveStatPlot
136 b.Location = loc
137
138 var err error
139 if b.Values, err = CopyValues(values); err != nil {
140 return fiveStatPlot{}, err
141 }
142
143 sorted := make(Values, len(b.Values))
144 copy(sorted, b.Values)
145 sort.Float64s(sorted)
146
147 if len(sorted) == 1 {
148 b.Median = sorted[0]
149 b.Quartile1 = sorted[0]
150 b.Quartile3 = sorted[0]
151 } else {
152 b.Median = median(sorted)
153 b.Quartile1 = median(sorted[:len(sorted)/2])
154 b.Quartile3 = median(sorted[len(sorted)/2:])
155 }
156 b.Min = sorted[0]
157 b.Max = sorted[len(sorted)-1]
158
159 low := b.Quartile1 - 1.5*(b.Quartile3-b.Quartile1)
160 high := b.Quartile3 + 1.5*(b.Quartile3-b.Quartile1)
161 b.AdjLow = math.Inf(1)
162 b.AdjHigh = math.Inf(-1)
163 for i, v := range b.Values {
164 if v > high || v < low {
165 b.Outside = append(b.Outside, i)
166 continue
167 }
168 if v < b.AdjLow {
169 b.AdjLow = v
170 }
171 if v > b.AdjHigh {
172 b.AdjHigh = v
173 }
174 }
175
176 return b, nil
177}
178
179// median returns the median value from a
180// sorted Values.

Callers 2

NewQuartPlotFunction · 0.85
NewBoxPlotFunction · 0.85

Calls 2

CopyValuesFunction · 0.85
medianFunction · 0.85

Tested by

no test coverage detected