Categorygithub.com/chewxy/stl
modulepackage
1.3.1
Repository: https://github.com/chewxy/stl.git
Documentation: pkg.go.dev

# README

stl GoDoc Build Status Coverage Status Go Report Card

package stl implements Seasonal-Trend Decompositions by LOESS of time series. It is a direct implementation of Cleveland et al (1990), which was written in Fortran '77.

This package does not implement the KD-Tree indexing for nearest neighbour search for the LOESS component as implemented in the original Netlib library. Instead, a straightforwards algorithm is implemented, focusing on clarity and understandability.

There were some parts that were "inlined" and unrolled manually for performance purposes - the tricube function and local neighbour functions for example. The original more mathematical implemetnations have been left in there for future reference.

Additionally, because multiplicative models are common in time series decompositions, Box-Cox transform functions (and generator) have also been provided.

Installation

This package has very minimal dependencies. These are the listing of the dependencies:

This package uses dep to manage dependencies - in particular, at this point, it uses an unstable version of Gorgonia. This will be rectified upon the release of v0.9.0 of Gorgonia.

Automated testing only tests up from Go 1.8 onwards. While I'm fairly confident that this package will work on those lower versions as well

Usage

import (
	"encoding/csv"
	"os"
	"fmt"

	"github.com/chewxy/stl"
)

func main() {
	var data []float64
	f, _ := os.Open("testdata/co2.csv")
	r := csv.NewReader(f)

	r.Read() // read header
	for rec, err := r.Read(); err == nil; rec, err = r.Read() {
		// here we're ignoring errors because we know the file to be correct
		if co2, err := strconv.ParseFloat(rec[0], 64); err == nil {
			data = append(data, co2)
		}
	}

	// The main function: 
	res := stl.Decompose(data, 12, 35, stl.Additive(), stl.WithRobustIter(2), stl.WithIter(2))
	fmt.Printf("%v", res.Seasonal)
	fmt.Printf("%v", res.Trens)
	fmt.Printf("%v", res.Resid)

Licence

This package is licenced with a MIT licence. I thank Rob Hyndman for writing a very excellent guide to STL, both in the R standard lib and in principle.

# Packages

No description provided by the author

# Functions

Additive returns a BoxCox transform that does nothing.
Decompose performs a STL decomposition.
DefaultLowPass returns the default configuration for the operation that works on the lowpass component.
DefaultSeasonal returns the default configuration for the operation that works on the seasonal component.
DefaultTrend returns the default configuration for the operation that works on the trend component.
Multiplicative returns a BoxCox transform that performs and unsafe transform of the input slice.
UnsafeTransform creates a transformation function that is somewhere between an additive and multiplicative model.
WithIter indicates how many iterations to run.
WithLowpassConfig configures the operation that performs the lowpass filter in the decomposition process.
WithRobustIter indicates how many iterations of "robust" (i.e.
WithSeasonalConfig configures the seasonal component of the decomposition process.
WithTrendConfig configures the trend component of the decomposition process.

# Structs

Config is a configuration structure.
ModelType is the type of STL model we would like to perform.
Result is the result of a decompositon.

# Type aliases

BoxCox is any function that performs a box cox transform.
IsoBoxCox is the invese of the BoxCox.
Opt is a function that helps build the conf.