Dear David,
Thank you very much for your prompt and useful reply. Agree hat code is no magic and modifications are needed to my data/code. So, before making many transformations I'm trying to understand what your code does and how it does it.
From your code and using your proposed data and dataframe, I'm trying to learn the next few things. I would appreciate your comments:
# Create the multivariate ARIMA model
model = sm.tsa.VARMAX(data, order=(order_x, order_y))
results = model.fit(maxiter=1000, disp=False)
Here, I'm getting
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[5], line 2
1 # Create the multivariate ARIMA model
----> 2 model = sm.tsa.VARMAX(data, order=(order_x, order_y))
3 results = model.fit(maxiter=1000, disp=False)
File ~\AppData\Local\miniconda3\envs\cadet\lib\site-packages\statsmodels\tsa\statespace\varmax.py:148, in VARMAX.__init__(self, endog, exog, order, trend, error_cov_type, measurement_error, enforce_stationarity, enforce_invertibility, trend_offset, **kwargs)
145 self.order = order
147 # Model orders
--> 148 self.k_ar = int(order[0])
149 self.k_ma = int(order[1])
151 # Check for valid model
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'tuple'
---------------------
** I'm using statsmodels v0.14.0.. Why can't it use the "order" parameter as you defined it?
For the augmented state, your code does not augment with an additional state. Instead I'm using,
# Augment the data with t_1 observed variables
y_t_1 = np.roll(y,-1)
data_augmented = pd.DataFrame({'x': x, 'y': y, 'Y_t_1': y_t_1})
so, it transforms data from (100 rows × 2 columns) to data_augmented with (100 rows × 3 columns). ** Does this make sense to you?
Nevertheless, when moving to building the state space with SARIMAX using the endog as data_augmented
# Set up the state space representation with augmented states
mod = sm.tsa.statespace.SARIMAX(data_augmented, order=(order_x, order_y), k_states =3)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[11], line 2
1 # Set up the state space representation with augmented states
----> 2 mod = sm.tsa.statespace.SARIMAX(data_augmented, order=(order_x, order_y), k_states =3)
File ~\AppData\Local\miniconda3\envs\cadet\lib\site-packages\statsmodels\tsa\statespace\sarimax.py:328, in SARIMAX.__init__(self, endog, exog, order, seasonal_order, trend, measurement_error, time_varying_regression, mle_regression, simple_differencing, enforce_stationarity, enforce_invertibility, hamilton_representation, concentrate_scale, trend_offset, use_exact_diffuse, dates, freq, missing, validate_specification, **kwargs)
318 def __init__(self, endog, exog=None, order=(1, 0, 0),
319 seasonal_order=(0, 0, 0, 0), trend=None,
320 measurement_error=False, time_varying_regression=False,
(...)
325 freq=None, missing='none', validate_specification=True,
326 **kwargs):
--> 328 self._spec = SARIMAXSpecification(
329 endog, exog=exog, order=order, seasonal_order=seasonal_order,
330 trend=trend, enforce_stationarity=None, enforce_invertibility=None,
331 concentrate_scale=concentrate_scale, dates=dates, freq=freq,
332 missing=missing, validate_specification=validate_specification)
333 self._params = SARIMAXParams(self._spec)
335 # Save given orders
File ~\AppData\Local\miniconda3\envs\cadet\lib\site-packages\statsmodels\tsa\arima\specification.py:267, in SARIMAXSpecification.__init__(self, endog, exog, order, seasonal_order, ar_order, diff, ma_order, seasonal_ar_order, seasonal_diff, seasonal_ma_order, seasonal_periods, trend, enforce_stationarity, enforce_invertibility, concentrate_scale, trend_offset, dates, freq, missing, validate_specification)
265 # Validate shapes of `order`, `seasonal_order`
266 if len(order) != 3:
--> 267 raise ValueError('`order` argument must be an iterable with three'
268 ' elements.')
269 if len(seasonal_order) != 4:
270 raise ValueError('`seasonal_order` argument must be an iterable'
271 ' with four elements.')
ValueError: `order` argument must be an iterable with three elements.
-------------------------------
I have not been able to find in the User's guide the parameters for SARIMAX with the parameter order the way your are suggesting. Also, k_states does not seem to be a paramete for SARIMAX.
I really appreciate your time. If there is something I should to learn better, please let me know.
Regards,
Victor S.