Documentation ¶
Overview ¶
Package regression provides online linear regression calculation.
Example ¶
r := New(7) r.Add(1.5, 4.4) r.Add(2.9, 1.56) slope, intercept, stdError := r.CalculateWithStdError() fmt.Printf("slope %f\n", slope) fmt.Printf("intercept %f\n", intercept) fmt.Printf("standard error %f\n", stdError) r.Add(7.2, 10.5) r.Add(9, 7.6) slope, intercept, stdError = r.CalculateWithStdError() fmt.Printf("slope %f\n", slope) fmt.Printf("intercept %f\n", intercept) fmt.Printf("standard error %f\n", stdError)
Output: slope -2.028571 intercept 7.442857 standard error NaN slope 1.188768 intercept -1.015158 standard error 3.720348
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Regression ¶
type Regression struct {
// contains filtered or unexported fields
}
Regression represents a queue of past points. Use New() to initialize.
func New ¶
func New(xDelta float64) *Regression
New returns a Regression that keeps points back as far as xDelta from the last added point.
func (*Regression) Add ¶
func (r *Regression) Add(x, y float64)
Add adds the new x and y as a point into the queue. Panics if given an x value less than the last.
func (*Regression) Calculate ¶
func (r *Regression) Calculate() (slope, intercept float64)
Calculate returns the slope, intercept and standard error of a best fit line to the added points. Returns a cached value if called between adds. Deprecated in favor of CalculateWithStdError.
func (*Regression) CalculateWithStdError ¶
func (r *Regression) CalculateWithStdError() (slope, intercept, stdError float64)
Calculate returns the slope, intercept and standard error of a best fit line to the added points. Returns a cached value if called between adds.