How to incorporate a diagonal noise covariance matrix in statsmodel unobserved components?

54 views
Skip to first unread message

Roland K

unread,
Sep 1, 2023, 8:35:20 AM9/1/23
to pystatsmodels
I frequently encounter data with time-varying a-priori noise standard deviations. I would like to preserve the ratio of the observation noise standard deviations and only estimate a joint scale factor as one of the SSM parameters. As far as I know I can't do this in the existing SSMs available in statsmodel - unobserved components. Can I do that in a custom state space model and if so, how does the implementation look like (e.g., for the local level model)?

Chad Fulton

unread,
Sep 3, 2023, 1:03:26 PM9/3/23
to pystat...@googlegroups.com
Hello,

Yes, you can do this in a custom state space model.  If I understand correctly, you want a model like:

image.png

where s_t is known?

Then that would look like:

class CustomLocalLevel(sm.tsa.statespace.MLEModel):
    def __init__(self, endog, s_t):
        super().__init__(endog, k_states=1)

        self.s_t = np.array(s_t).reshape(1, 1, self.nobs)

        self['design', 0, 0] = 1.
        self['transition', 0, 0] = 1.
        self['selection', 0, 0] = 1.

        self.ssm.initialize_diffuse()

    @property
    def param_names(self):
        return ['sigma_eps', 'sigma_eta']

    @property
    def start_params(self):
        var = np.var(np.diff(self.endog[:, 0]))
        return np.r_[var / 3, 2 * var / 3]

    def transform_params(self, params):
        return params**2

    def untransform_params(self, params):
        return params**0.5

    def update(self, params, **kwargs):
        params = super().update(params, **kwargs)

        self['obs_cov'] = params[0] * self.s_t
        self['state_cov', 0, 0] = params[1]


Best,
Chad

On Fri, Sep 1, 2023 at 8:35 AM Roland K <rkle...@gmail.com> wrote:
I frequently encounter data with time-varying a-priori noise standard deviations. I would like to preserve the ratio of the observation noise standard deviations and only estimate a joint scale factor as one of the SSM parameters. As far as I know I can't do this in the existing SSMs available in statsmodel - unobserved components. Can I do that in a custom state space model and if so, how does the implementation look like (e.g., for the local level model)?

--
You received this message because you are subscribed to the Google Groups "pystatsmodels" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pystatsmodel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pystatsmodels/16a3ce55-c9a5-4a89-8ddb-918754272515n%40googlegroups.com.

Roland K

unread,
Feb 21, 2024, 1:17:48 PMFeb 21
to pystatsmodels
Thanks a lot. Exactly what I was looking for.

Op zondag 3 september 2023 om 19:03:26 UTC+2 schreef chadf...@gmail.com:
Reply all
Reply to author
Forward
0 new messages