Hi Chad, I'll try to be a bit more clear:
I'm trying to draw "samples of state or disturbance vectors conditional on
the observations held fixed" (quoting Durbin and Koopman).
Ultimately the use case I have in mind is a Bayesian analysis. Using pymc3
I will take draws from the posterior distribution of the error covariance
parameters and then, conditional on these parameters and the observations,
I wish to simulate the evolution of the latent state parameters.
Ignoring the Bayesian application here's some reproducible code:
%matplotlib inline
import numpy as np
import pandas as pd
import statsmodels.api as sm
import matplotlib.pyplot as plt
# Get some data
nile = sm.datasets.nile.load_pandas().data['volume']
nile.index = pd.DatetimeIndex(start="1871",end="1971", freq='y')
# Estimate the parameters of the model
mod = sm.tsa.UnobservedComponents(nile, 'llevel')
res = mod.fit()
# Get the simulation smoother and simulate
sim = res.model.simulation_smoother()
sim.simulate()
# Plot the filtered state and the state produced by the simulation smoother
pd.Series(sim.generated_obs[0,:]).plot(observed=False)
res.plot_components()
I would have expected state produced by the simulation smoother to look
similar to the estimated state from the fitted model. However, as far as I
can see this is just simulating a local level process with the given
parameters.
I have built statsmodels from the version on github (0.10.0 according to
the output of "conda list")
Best,
Alastair
Post by Chad FultonPost by Alastair HeggieI am having trouble getting simulation smoothing of state space models to
work.
Suppose I have an UnobservedComponents model.
fitted = mod.fit()
sim = mod.simulation_smoother()
sim.simulate(initial_state_variates=fitted.smoothed_state[:,0],
pretransformed_variates=True)
However the resulting output does not seem to be conditional on the
observations. Is there a kwarg I need to pass to the simulation_smoother to
get this to work.
I have tried to figure this out from studying the source but to no avail.
Best wishes,
Alastair
There are no kwargs that you should have to pass.
It's hard to say more based on your e-mail, though. Can you describe what
you're trying to do in more detail, e.g. what you're expecting and what's
actually happening, and the version of Statsmodels that you're using?