Skip to content

ENH: seasonal_decompose for 2-D  #2820

Closed

Description

@josef-pkt

The seasonal_decompose function works only for 1-dimensional data. All the unit test cases are 1-D.

see #2733 (comment) for report/question and current exception raised.
duplicate issue with more description #2821

Based on briefly browsing the code, I think the function can be made to work for 2-D.

AFAICS:

  • convolution_filter already works for 2-D on axis=0, according to docstring
  • seasonal mean: calculates the mean over all columns for a seasonal period, i.e. common seasonality
  • period_averages and creating seasonal assumes 1-d

Activity

  1. josef-pkt commented on Feb 17, 2016

    @josef-pkt
    MemberAuthor

    I got it to work on a numpy example just adding some axis=0, and 2d tiling.

    (I grabbed a random python on the wrong computer to edit. PR coming up)

  2. Irene-GM commented on Feb 17, 2016

    @Irene-GM

    Can I see the solution to the problem? Not sure on how (and where) to use the 2D tiling plus axis=0. Do you have a dummy test example you can share? Thanks a lot! :-)

  3. josef-pkt commented on Feb 17, 2016

    @josef-pkt
    MemberAuthor

    Soon I have a bit of a mess right now because I made the change on top of another old working branch.

    My example to try it out is very simple and just uses numpy

    import numpy as np
    from statsmodels.tsa.seasonal import seasonal_decompose
    
    
    nobs = 10 * 12
    x = np.random.randn(nobs, 4)
    s = np.tile((np.arange(12) - 6)**2, 10)
    y = s[:,None] + x
    
    res = seasonal_decompose(y[:,:], freq=12)
    res0 = seasonal_decompose(y[:,0], freq=12)
    print(res0.resid - res.resid[:,0])
    
  4. josef-pkt commented on Feb 17, 2016

    @josef-pkt
    MemberAuthor

    here are the changes. master...josef-pkt:seasonal_2d

    Note, this was very quickly done and only checked on the example.

  5. Irene-GM commented on Feb 17, 2016

    @Irene-GM

    Thanks Josef! I tried and it works like a charm also with my example. It nicely leaves the result of the 34 decompositions in a dataframe organized per columns, so now I can continue with my experiments with the seasonal components of the time-series. I am very grateful for your help and support, because the alternative was using R (RStudio) and its a platform "isolated" of my Python workflows, so I preferred to keep pythonic, like this. Kudos! :-)

  6. josef-pkt commented on Oct 27, 2017

    @josef-pkt
    MemberAuthor

    merged as part of #3031

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions