%matplotlib inline
import numpy as np
import pandas as pd
import statsmodels.api as sm
from statsmodels.tsa.statespace import mlemodel
from statsmodels.tsa.statespace.tests import test_representation as t
import matplotlib.pyplot as plt
np.set_printoptions(precision=4, suppress=True, linewidth=120)
# Get the multiple endog test case
# Note: it directly uses a KalmanFilter instance...
test = t.Clark1989()
test.run_filter()
# ...so wrap it into an MLEModel instance
# Note: zero parameters here
x = mlemodel.MLEModel(endog=test.model.endog.T, k_states=test.model.k_states)
x.ssm = test.model
res = x.filter([])
# Summary: note that the diagnostics table shows two
# numbers for each test corresponding to the two endog
print res.summary()
# Diagnostics for the first endog
fig1 = res.plot_diagnostics(0, figsize=(10,6))
fig1.suptitle('Diagnostics for y1', fontsize='xx-large')
fig1.subplots_adjust(top=0.87)
# Diagnostics for the second endog
fig2 = res.plot_diagnostics(1, figsize=(10,6))
fig2.suptitle('Diagnostics for y2', fontsize='xx-large')
fig2.subplots_adjust(top=0.87);
Statespace Model Results ============================================================================== Dep. Variable: ['y1', 'y2'] No. Observations: 191 Model: MLEModel Log Likelihood 1485.419 Date: Fri, 17 Jul 2015 AIC -2970.839 Time: 10:30:18 BIC -2970.839 Sample: 0 HQIC -2970.839 - 191 Covariance Type: opg =================================================================================== Ljung-Box (Q): 21.53, 41.66 Jarque-Bera (JB): 15290.76, 2182.88 Prob(Q): 0.99, 0.40 Prob(JB): 0.00, 0.00 Heteroskedasticity (H): 0.16, 0.28 Skew: -4.59, -1.81 Prob(H) (two-sided): 0.00, 0.00 Kurtosis: 45.86, 19.16 ===================================================================================