Skip to content

BUG: stochastic trend in tsa.statespace.UnobservedComponents #7613

Open

Description

@devindg

Documentation for this function is here: https://www.statsmodels.org/devel/generated/statsmodels.tsa.statespace.structural.UnobservedComponents.html

Problem
The argument combinations (trend=False,stochastic_trend=True) and (trend=False,stochastic_trend=False) output different forecast results.

Expectation
If trend=False, then the boolean passed to stochastic_trend should not matter.

Sample code

mod1 = statsmodels.tsa.UnobservedComponents(y, level=True, trend=False, seasonal=12,
                                    cycle=True, irregular=True, stochastic_level=True,
                                    stochastic_trend=True, stochastic_seasonal=True,
                                    stochastic_cycle=True)

res1 = mod1.fit(disp=False)
forecast1 = res1.forecast(12)

mod2 = statsmodels.tsa.UnobservedComponents(y, level=True, trend=False, seasonal=12,
                                    cycle=True, irregular=True, stochastic_level=True,
                                    stochastic_trend=False, stochastic_seasonal=True,
                                    stochastic_cycle=True)

res2 = mod2.fit(disp=False)
forecast2 = res2.forecast(12)

For some reason I can't upload a *.csv file. GitHub is complaining that it's not supported.

Activity

  1. changed the title [-][Possible bug] stochastic trend in tsa.statespace.UnobservedComponents[/-] [+]BUG: stochastic trend in tsa.statespace.UnobservedComponents[/+] on Jul 30, 2021
  2. added this to the 0.13 milestone on Aug 1, 2021
  3. ChadFulton commented on Aug 1, 2021

    @ChadFulton
    Member

    Thanks for this report!

    It looks like this is just an issue with choosing starting parameters for maximum likelihood estimation, but not a bug in the model setup itself.

  4. devindg commented on Aug 2, 2021

    @devindg
    Author

    Thanks for this report!

    It looks like this is just an issue with choosing starting parameters for maximum likelihood estimation, but not a bug in the model setup itself.

    Thanks for the quick reply. I'm not sure I fully understand the issue. My gut is that the initial parameter values should have little impact on MLE convergence. If trend=False, why would the option for stochastic_trend have any effect?

  5. ChadFulton commented on Aug 2, 2021

    @ChadFulton
    Member

    If trend=False, why would the option for stochastic_trend have any effect?

    Yes, it should not have an effect, this is the issue with choosing starting parameters that I mentioned and which we can fix.

    My gut is that the initial parameter values should have little impact on MLE convergence.

    This depends on the situation. Here's an example where it matters a little bit, but not very much (so you would get similar forecasts, but they would be different). Of course there are other situations where it matters a lot more (especially if the series does have a strong trend).

    import statsmodels.api as sm
    y = sm.datasets.macrodata.load_pandas().data['infl']
    
    mod1 = sm.tsa.UnobservedComponents(y, level=True, trend=False, seasonal=12,
                                        cycle=True, irregular=True, stochastic_level=True,
                                        stochastic_trend=True, stochastic_seasonal=True,
                                        stochastic_cycle=True)
    
    res1 = mod1.fit(disp=False)
    
    mod2 = sm.tsa.UnobservedComponents(y, level=True, trend=False, seasonal=12,
                                        cycle=True, irregular=True, stochastic_level=True,
                                        stochastic_trend=False, stochastic_seasonal=True,
                                        stochastic_cycle=True)
    
    res2 = mod2.fit(disp=False)
    
    print('Parameter names')
    print(mod2.param_names, '\n')
    print('Starting parameters')
    print(np.array(mod1.start_params).round(4))
    print(np.array(mod2.start_params).round(4), '\n')
    print('Estimated parameters')
    print(res1.params.values.round(4))
    print(res2.params.values.round(4), '\n')
    print('Log-likelihood at estimated parameters')
    print(res1.llf)
    print(res2.llf)

    yields:

    Parameter names
    ['sigma2.irregular', 'sigma2.level', 'sigma2.seasonal', 'sigma2.cycle', 'frequency.cycle'] 
    
    Starting parameters
    [4.6909 0.0582 4.6909 4.6909 1.5708]
    [4.6909 5.1153 4.6909 4.6909 1.5708] 
    
    Estimated parameters
    [3.3403 0.7478 0.     0.     0.716 ]
    [3.3488 0.7757 0.     0.     0.057 ] 
    
    Log-likelihood at estimated parameters
    -446.4233803364292
    -447.9242648519106
    
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions