pythonstatsmodelsstate-space

Statsmodels state space representation of stochastic process with nonzero mean


I would like to define a state space representation of a model with a nonzero drift term in statsmodels. The documentation for the state state representation framework appears to assume that the stochastic terms (epsilon and eta) have zero mean:

statsmodels documentation for state space representations

Is there a way to introduce (and then set as parameters) a mean drift term to these stochastic processes in the state space representation? Perhaps by adding them to the intercept matrices c_t and d_t?

Thank you!


Solution

  • Yes, you can add a constant term to either equation by placing values into obs_intercept or state_intercept.

    self.ssm['obs_intercept', 0] = 1.4
    

    If the parameter is being estimated, then you would do this in the update method.

    def update(self, params, **kwargs):
        params = super().update(params, **kwargs)
    
        self.ssm['obs_intercept, 0] = params[0]
    

    Finally, the intercepts can be time-varying, so if you wanted the constant term to show a linear trend, you could do:

    def __init__(self, endog, ...):
        ...
    
        # (note that by default the intercept terms are not time-varying.
        # If you want to set them to be time-varying, it is usually best
        # to do that in the constructor)
        self['obs_intercept'] = np.zeros((self.k_endog, self.nobs))
    
        ...
    
    def update(self, params, **kwargs):
        params = super().update(params, **kwargs)
    
        self.ssm['obs_intercept', 0, :] = (
            params[0] * np.arange(1, self.nobs + 1))