A Java implementation of STL: A Seasonal-Trend Decomposition Procedure Based on Loess
To include this library in your project, add the following dependency
<dependency>
<groupId>com.github.brandtg</groupId>
<artifactId>stl-java</artifactId>
<version>0.0.1</version>
</dependency>
Assuming we have a time series of monthly data that is periodic with respect to years
double[] ts;
double[] ys; // some dependent variable on ts
We can run STL as follows
StlConfig config = new StlConfig();
config.setNumberOfObservations(12); // 12 months in a year
config.setNumberOfDataPoints(ts.length);
StlDecomposition stl = new StlDecomposition(config);
StlResult res = stl.decompose(ts, ys);
And optionally plot the results (n.b. StlPlotter
is in test scope)
StlPlotter.plot(res);