Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: SARIMAX with time-varying coefficients works when model is (1,1,0) or (0,1,1), but raises an error when model set to (0,1,0) #8725

Open
fcela opened this issue Mar 9, 2023 · 2 comments

Comments

@fcela
Copy link

fcela commented Mar 9, 2023

Call used:

SARIMAX(endog=endog, exog=exog, order=order
    seasonal_order= (0,0,0,4),
    trend= 'n',
enforce_stationarity=True,
enforce_invertibility=True,
time_varying_regression=True,
concentrate_scale = False,
measurement_error = False,
mle_regression = False)

Endog has 6 covariates.

Works when order = (1,1,0) (however state.1 is all zero); also works for order = (0,1,1). However when using order=(1,1,0) I get the following error:

    524     self.ssm._time_invariant = False
    526 # Initialize the fixed components of the statespace model
--> 527 self.ssm['design'] = self.initial_design
    528 self.ssm['state_intercept'] = self.initial_state_intercept
    529 self.ssm['transition'] = self.initial_transition

File C:\Developer\venv\lab\lib\site-packages\statsmodels\tsa\statespace\representation.py:420, in Representation.__setitem__(self, key, value)
    417     if key not in self.shapes:
    418         raise IndexError('"%s" is an invalid state space matrix name'
    419                          % key)
--> 420     setattr(self, key, value)
    421 # If it's a tuple (with a string as the first element) then we must be
    422 # setting a slice of a matrix
    423 elif _type is tuple:

File C:\Developer\venv\lab\lib\site-packages\statsmodels\tsa\statespace\representation.py:54, in MatrixWrapper.__set__(self, obj, value)
     51 shape = obj.shapes[self.attribute]
     53 if len(shape) == 3:
---> 54     value = self._set_matrix(obj, value, shape)
     55 else:
     56     value = self._set_vector(obj, value, shape)

File C:\Developer\venv\lab\lib\site-packages\statsmodels\tsa\statespace\representation.py:68, in MatrixWrapper._set_matrix(self, obj, value, shape)
     65     value = value[None, :]
     67 # Enforce that the matrix is appropriate size
---> 68 validate_matrix_shape(
     69     self.name, value.shape, shape[0], shape[1], obj.nobs
     70 )
     72 # Expand time-invariant matrix
     73 if value.ndim == 2:

File C:\Developer\venv\lab\lib\site-packages\statsmodels\tsa\statespace\tools.py:1477, in validate_matrix_shape(name, shape, nrows, ncols, nobs)
   1474     raise ValueError('Invalid dimensions for %s matrix: requires %d'
   1475                      ' rows, got %d' % (name, nrows, shape[0]))
   1476 if not shape[1] == ncols:
-> 1477     raise ValueError('Invalid dimensions for %s matrix: requires %d'
   1478                      ' columns, got %d' % (name, ncols, shape[1]))
   1480 # If we do not yet know `nobs`, do not allow time-varying arrays
   1481 if nobs is None and not (ndim == 2 or shape[-1] == 1):

ValueError: Invalid dimensions for design matrix: requires 7 columns, got 6

@fcela fcela changed the title SARIMAX with time-varying coefficients works when model is (0,1,0), but raises an error when model set to (0,1,0) SARIMAX with time-varying coefficients works when model is (1,1,0) or (0,1,1), but raises an error when model set to (0,1,0) Mar 9, 2023
@ChadFulton
Copy link
Member

Thanks for reporting this!

@ChadFulton ChadFulton changed the title SARIMAX with time-varying coefficients works when model is (1,1,0) or (0,1,1), but raises an error when model set to (0,1,0) BUG: SARIMAX with time-varying coefficients works when model is (1,1,0) or (0,1,1), but raises an error when model set to (0,1,0) Mar 12, 2023
@ChadFulton
Copy link
Member

ChadFulton commented Mar 12, 2023

Here's a minimum reproducible example:

import numpy as np
import statsmodels.api as sm

np.random.seed(1234)
endog = np.random.normal(size=100)
exog = np.random.normal(size=(100, 1))

mod = sm.tsa.SARIMAX(endog=endog, exog=exog, order=(0, 1, 0), trend='n',
                     time_varying_regression=True, mle_regression=False)

res = mod.fit(disp=False)

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

No branches or pull requests

2 participants