# Is there a Julia package that can decompose a time series data into trend, seasonality and random?

**URL:** <https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518>\
**Category:** Statistics\
**Tags:** first-steps, time-series\
**Created:** [March 5, 2018, 8:29pm UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518 "2018-03-05T20:29:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [March 5, 2018, 8:29pm UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/1 "2018-03-05T20:29:00Z")

</div>

I was trying to do some time series analysis. In R, there is a `decompose` function that can decompose a time series into trend, seasonality, and random noise.

Is there an equivalent in Julia?

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [March 5, 2018, 8:49pm UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/2 "2018-03-05T20:49:44Z")

</div>

[https://github.com/baggepinnen/SingularSpectrumAnalysis.jl](https://github.com/baggepinnen/SingularSpectrumAnalysis.jl) does this, but in a perhaps slightly different way than what you are looking for.

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [March 5, 2018, 9:07pm UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/3 "2018-03-05T21:07:25Z")

</div>

It’s not clear how to do it from the readme. Feels like it’s not beginner friendly yet and it requires much higher level of maths and skills to understand.

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [March 6, 2018, 3:39am UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/4 "2018-03-06T03:39:23Z")

</div>

Sounds like an idea for a new package? 😆

R [implements](https://github.com/wch/r-source/blob/af7f52f70101960861e5d995d3a4bec010bc89e6/src/library/stats/R/HoltWinters.R) holt winters method. This [paper](https://labs.omniti.com/people/jesus/papers/holtwinters.pdf) may be helpful.

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [March 6, 2018, 6:43am UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/5 "2018-03-06T06:43:11Z")

</div>

Time for a time series person to step in! I thought Julia sells alot to wall st. And they do time series alot. My needs are met by R for now. Data so small that I can just do it without thinking about performance

---

<div class="post-metadata">

**Author:** ![pkofod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkofod/32/2179_2.png) [@pkofod](https://discourse.julialang.org/u/pkofod)\
**Post date:** [March 6, 2018, 6:51am UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/6 "2018-03-06T06:51:17Z")

</div>

I don’t think a package to run this regression in what makes them choose programming language, tbh 🙂 Also, Julia doesn’t sell anything, Julia Computing does.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 6, 2018, 7:38am UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/7 "2018-03-06T07:38:03Z")

</div>

I asked a [similar question](https://discourse.julialang.org/t/package-for-deseasonalizing/9275) a while ago, and apparently there isn’t any. I have implemented [Hamilton (2017)](http://econweb.ucsd.edu/~jhamilto/hp.pdf) for detrending, and plan to release it soon. I also came up with a simple multilevel model-based deseasonalizer that seems to work surprisingly well, but that is still experimental.

As I said in the [other topic](https://discourse.julialang.org/t/interesting-observations-about-julia-language-google-trends-time-series/9519), most of these methods introduce spurious patterns, especially for the “trend”. Deseasonalizing with sophisticated algorithms (STL or X13-ARIMA-SEATS) is also prone to this, to a smaller extent. But of course they are OK for exploratory plotting, one just has to be aware of this.

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [March 6, 2018, 9:23am UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/8 "2018-03-06T09:23:05Z")

</div>

if times is what you do then yeah.

---

<div class="post-metadata">

**Author:** ![pkofod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkofod/32/2179_2.png) [@pkofod](https://discourse.julialang.org/u/pkofod)\
**Post date:** [March 6, 2018, 5:30pm UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/9 "2018-03-06T17:30:24Z")

</div>

My point is that they are probably able to build their own code base where something like this enters as a component, rather than relying on some public open source compromise. Of course if there’s a great solution out there they might use it, but it won’t hold them back.

---

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [May 1, 2019, 11:37am UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/10 "2019-05-01T11:37:55Z")

</div>

Has the landscape changed on this? I’m looking for the same thing and can’t find a solution that doesn’t involve using R : (

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [May 2, 2019, 12:45pm UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/11 "2019-05-02T12:45:56Z")

</div>

I added some additional documentation here  
[https://github.com/baggepinnen/SingularSpectrumAnalysis.jl#simple-usage](https://github.com/baggepinnen/SingularSpectrumAnalysis.jl#simple-usage)  
Let me know whether or not it works for you, I might be able to add more functionality if you miss something

---

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [May 2, 2019, 12:59pm UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/12 "2019-05-02T12:59:38Z")

</div>

👍 Thanks!

---

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [May 2, 2019, 2:49pm UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/13 "2019-05-02T14:49:15Z")

</div>

@baggepinnen Everything works great but it doesn’t look like the package is exporting a `fit_trend` function as indicated in the docs (I get `UndefVarError: fit_trend not defined`). Running `names(SingularSpectrumAnalysis)` yields the following output:

```julia
11-element Array{Symbol,1}:
 :SingularSpectrumAnalysis
 :analyze                 
 :autogroup               
 :elementary              
 :hankel                  
 :hankelize               
 :hsvd                    
 :pairplot                
 :pairplot!               
 :reconstruct             
 :sigmaplot 

```

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [May 2, 2019, 2:59pm UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/14 "2019-05-02T14:59:04Z")

</div>

Thanks! First try to update your packages: `] up` If that does not work, try `] add SingularSpectrumAnalysis#master`. I just added the functionality so it might not have made it into the registry yet

---

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [May 2, 2019, 3:06pm UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/15 "2019-05-02T15:06:32Z")

</div>

ah, got it. Thanks again!

---

<div class="post-metadata">

**Author:** ![DoktorMike](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/doktormike/32/2736_2.png) [@DoktorMike](https://discourse.julialang.org/u/DoktorMike)\
**Post date:** [May 2, 2019, 5:00pm UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/16 "2019-05-02T17:00:31Z")

</div>

STL in R has always been my go-to function for timeseries decomposition. I think I can safely replace that now. 😊 Thanks for making this package.

---

<div class="post-metadata">

**Author:** ![fipelle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fipelle/32/4772_2.png) [@fipelle](https://discourse.julialang.org/u/fipelle)\
**Post date:** [November 4, 2019, 1:16am UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/17 "2019-11-04T01:16:30Z")

</div>

Hi,

I just released the first version for TSAnalysis ([https://github.com/fipelle/TSAnalysis.jl](https://github.com/fipelle/TSAnalysis.jl)). It is a rather small package (at least, for now) but it can be used to decompose time series into trends, cycles and other components using linear state-space models.

I added an example with seasonality in the GitHub readme. I hope this can also help!

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [February 26, 2020, 8:40am UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/18 "2020-02-26T08:40:48Z")

</div>

[SingularSpectrumAnalysis](https://github.com/baggepinnen/SingularSpectrumAnalysis.jl) has been updated to support use of the robust factorizations provided by [TotalLeastSquares.jl](https://github.com/baggepinnen/TotalLeastSquares.jl). It should now be able to handle extremely large outliers and missing data quite well.

- [Notebook demoing robust filtering](https://github.com/baggepinnen/julia_examples/blob/master/identification_robust.ipynb)
- [Robust factorization vs. SVD comparison](https://github.com/baggepinnen/TotalLeastSquares.jl#robust-tls-analysis)
- [A note on missing data](https://github.com/baggepinnen/TotalLeastSquares.jl#missing-data-imputation)

---

<div class="post-metadata">

**Author:** ![atteson](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@atteson](https://discourse.julialang.org/u/atteson)\
**Post date:** [March 27, 2020, 10:20am UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/19 "2020-03-27T10:20:20Z")

</div>

It would be great if someone could make X13ARIMA-SEATS, public domain Fortran that the government uses for seasonal adjustment, available in julia:

[https://www.census.gov/ts/x13as/docX13AS.pdf](https://www.census.gov/ts/x13as/docX13AS.pdf)

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 27, 2020, 10:26am UTC](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518/20 "2020-03-27T10:26:20Z")

</div>

That someone could be you 🙂

If the code is public domain you can just port the whole thing, alternatively consider writing a [Julia wrapper around the FORTRAN library](https://docs.julialang.org/en/v1/manual/calling-c-and-fortran-code/#Fortran-Wrapper-Example-1)

[Next page](https://discourse.julialang.org/t/is-there-a-julia-package-that-can-decompose-a-time-series-data-into-trend-seasonality-and-random/9518.md?page=2)
