Ejemplo n.º 1
0
func (o *OLS) String() string {
	q, _ := govector.AsVector(o.residuals)
	points := []float64{0.0, 0.25, 0.5, 0.75, 1.0}
	p, _ := govector.AsVector(points)
	qnt := q.Quantiles(p)
	f, fp := o.F_Statistic()

	return fmt.Sprintf(`
		Residuals: 
		Min  25  50t 75  Max: 
		%v
		
		Coefficients: 
		%v

		RSS: %v 
		MSE: %v
		Adjusted R-Squared: %v
		R-squared: %v
		F-statistic: %v with P-value: %v`,
		roundAll(qnt),
		roundAll(o.betas),
		round(o.ResidualSumofSquares(), 3),
		round(o.MeanSquaredError(), 3),
		round(o.AdjustedRSquared(), 3),
		round(o.RSquared(), 3),
		round(f, 4), round(fp, 10),
	)
}
Ejemplo n.º 2
0
func (o *OLS) TotalSumofSquares() float64 {
	// no chance this could error
	y, _ := govector.AsVector(o.response)
	ybar := mean(o.response)

	squaredDiff := func(x float64) float64 {
		return math.Pow(x-ybar, 2.0)
	}

	return y.Apply(squaredDiff).Sum()
}
Ejemplo n.º 3
0
// Durbin Watson Test for Autocorrelatoin of the Residuals
// d = \sum_i=2 ^ n (e_i  - e_i-1)^2 / \sum_i=1^n e_i^2
//
// Does not calculate the p-value
func (o *OLS) DW_Test() float64 {
	e, err := govector.AsVector(o.residuals)
	if err != nil {
		panic(err)
	}

	square := func(x float64) float64 { return math.Pow(x, 2) }

	d := e.Diff().Apply(square).Sum()
	d /= e.Apply(square).Sum()

	return d
}
Ejemplo n.º 4
0
func NewAnomalyzer(conf *AnomalyzerConf, data []float64) (Anomalyzer, error) {
	err := validateConf(conf)
	if err != nil {
		return Anomalyzer{}, err
	}

	vector, err := govector.AsVector(data)
	if err != nil {
		return Anomalyzer{}, err
	}

	return Anomalyzer{conf, vector}, nil
}