Search code examples
pythonstatsmodels

statsmodels user-defined parameter ordering in simulate()


In statsmodels, how is the element order of input parameter params in VARMAX.simulate defined?

One would assume the ordering corresponds to what is given by attribute param_names of the created object, but this seems not to be the case. See examples below.

import statsmodels as statsmodels 
import statsmodels.api as sm
import pandas as pd
import numpy as np
endog = pd.DataFrame({"y":[np.nan, np.nan], "y2":[np.nan, np.nan]}, index=[0, 1])
statsmodels.__version__
>>>>>>>>>
'0.11.1'

Example 1: Two-variable VAR(1) with intercepts and drifts, all parameters fixed to 0 except for intercept of y set to 1. Yields expected results.

params = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
mod1 = sm.tsa.VARMAX(endog, order=(1, 0), trend=[1, 1], trend_offset=0)
print('\n'.join('{} :{}'.format(*k) for k in zip(mod1.param_names, params)))
print(mod1.simulate(params=params, nsimulations=5, initial_state=[0, 0]))

>>>>>>>>>
intercept.y :1
intercept.y2 :0
drift.y :0
drift.y2 :0
L1.y.y :0
L1.y2.y :0
L1.y.y2 :0
L1.y2.y2 :0
sqrt.var.y :0
sqrt.cov.y.y2 :0
sqrt.var.y2 :0

     y   y2
0  0.0  0.0
1  1.0  0.0
2  1.0  0.0
3  1.0  0.0
4  1.0  0.0 

Example 2: Same as in Example 1 but now intercept of variable y is set to 0 and intercept of variables y2 is set to 1. Rather than yielding the expected result it seems that the second element in params actually controls the drift parameter of y rather than the intercept term of y2. This contradicts the parameter ordering given by mod2.param_names.

params = [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]
mod2 = sm.tsa.VARMAX(endog, order=(1, 0), trend=[1, 1], trend_offset=0)
print('\n'.join('{} :{}'.format(*k) for k in zip(mod2.param_names, params)))
print(mod2.simulate(params=params, nsimulations=5, initial_state=[0, 0]))

>>>>>>>>>
intercept.y :0
intercept.y2 :1
drift.y :0
drift.y2 :0
L1.y.y :0
L1.y2.y :0
L1.y.y2 :0
L1.y2.y2 :0
sqrt.var.y :0
sqrt.cov.y.y2 :0
sqrt.var.y2 :0

     y   y2
0  0.0  0.0
1  1.0  0.0
2  2.0  0.0
3  3.0  0.0
4  4.0  0.0

Solution

  • This looks like a bug in Statsmodels in the ordering of the parameter names.