Skip to content

Fast non-linear non-Gaussian State Space models estimation feature #9706

Open

Description

@nguymin-theonlyone

Background
As far as I understand, the current Statsmodels library does not natively support non-Gaussian or non-linear State Space models. Incorporating this capability would be highly beneficial.

Possible solution
One promising approach is the fast Modified Efficient Importance Sampling (MEIS) method described by Koopman, Lit, and Nguyen (2018). This technique, detailed in their paper

Statistica.Neerlandica.-.2018.-.Koopman.-.Modified.efficient.importance.sampling.for.partially.non.Gaussian.state.space (1).pdf

is computationally efficient and could be relatively straightforward to implement by leveraging existing Linear Gaussian State Space model tools, such as the Kalman filter and State smoothing algorithms.

Activity

  1. changed the title [-]Fast Nonlinear non-Gaussian State Space models estimation feature[/-] [+]Fast non-linear non-Gaussian State Space models estimation feature[/+] on Dec 9, 2025
  2. nguymin-theonlyone commented on Dec 9, 2025

    @nguymin-theonlyone
    Author

    The method is more elaborately described in the below document

    non_linear_non_Gaussian_State_Space_Models.pdf

  3. ChadFulton commented on Dec 10, 2025

    @ChadFulton
    Member

    Thanks! This would be a great addition. I have only briefly read the citations, so maybe you can help me understand what implementation would look like.

    1. It seems that this would be a new model class, where the user would need to specify:
    • Link function Z_t
    • Distribution of the error term
    • Parameterization of the transition equation
    1. Then am I right in thinking that the main issue is to use the linked results to define a loglike method, which would use the simulation smoother to estimate the likelihood function via what the 2018 paper refers to as the MEIS method? And then we would use a typical non-linear solver to maximize that likelihood function?

    2. And as a byproduct (if I am reading the paper correctly), I guess we would get simulations of the state vector (from the smoothed distribution?), the signal, and perhaps some other estimates (?). (It's not entirely clear what estimates are available from this method)?

    Please feel free to correct me, or propose a completely different setup.

    Questions:

    1. It seems like it would make sense to first start with the linear transition equation case, is that right?
    2. It seems like it would make sense to first start with a univariate observation equation (as in the 2018 paper), is that right? Or would it be better to just go ahead and do the multivariate case (which it looks like is developed in the 2007 monograph)?
  4. nguymin-theonlyone commented on Dec 11, 2025

    @nguymin-theonlyone
    Author

    MEIS_implementation_in_statsmodels_brainstorm.docx

    Hi Chad,

    Thank you so much for your quick and positive response! It's great to hear that this could be a valuable addition to statsmodels. I'd be happy to clarify the implementation concept further.

    I’ve added a conceptional laye-out. Feel free to correct me too or suggest something different because I am not very familiar with the statsmodels set-up, so far it looks very impressive. I tried it out and the design is very neat and variable names are consistent with the Durbin and Koopman book, which is nice.

    Your understanding of the setup is largely spot-on, and I can confirm your initial thoughts:

    1. It seems that this would be a new model class, where the user would need to specify:
    • Link function Z_t
    • Distribution of the error term
    • Parameterization of the transition equation

    Yes, you are exactly right. The proposed approach would be a new model class, let's call it MEISModel, inheriting from MLEModel. This would require all points you specific above.

    1. Then am I right in thinking that the main issue is to use the linked results to define a loglike method, which would use the simulation smoother to estimate the likelihood function via what the 2018 paper refers to as the MEIS method? And then we would use a typical non-linear solver to maximize that likelihood function?

    I agree with your thinking and tried to include it in the proposed conceptual layout. The MEISModel would indeed override the standard loglike method (which I've termed _loglikelihood_meis internally) to implement the entire MEIS procedure. This _loglikelihood_meis method would:

    1. Leverage the State Smoother to efficiently sample state trajectories from the iteratively refined Linear Gaussian proposal model.
    2. Compute importance weights by comparing the true non-Gaussian observation likelihood (user-defined) to that of the proposal.
    3. Aggregate these to return the Simulated Log-Likelihood. And yes, a typical solver would then be used in the outer loop to maximize this simulated likelihood function for the parameters.
    1. And as a byproduct (if I am reading the paper correctly), I guess we would get simulations of the state vector (from the smoothed distribution?), the signal, and perhaps some other estimates (?). (It's not entirely clear what estimates are available from this method)?> > Please feel free to correct me, or propose a completely different setup.

    Correct. Because you obtain simulation of the state vector and weight them with the importance weights, you obtain estimates of the states and therefore observations y. Also, you can obtain forecasts for y. I described it more clearly in the conceptional laye-out including the relevant section references.

    Questions:

    1. It seems like it would make sense to first start with the linear transition equation case, is that right?

    Good point. When we did research on MEIS, we mainly looked at cases where the observation equation is non-Gaussian. It was assumed that the state equation is linear and Gaussian. It would be easier to start with this assumption indeed.

    1. It seems like it would make sense to first start with a univariate observation equation (as in the 2018 paper), is that right? Or would it be better to just go ahead and do the multivariate case (which it looks like is developed in the 2007 monograph)?

    It would be beneficial to support multivariate analysis. However, testing is simpler with univariate initially. I plan to start by implementing a proof of concept for some univariate cases.

  5. ChadFulton commented on Dec 12, 2025

    @ChadFulton
    Member

    Thank you for posting that document, that was very helpful in understanding the steps.

    One other question that came to my mind was how to test the implementation.

    1. Are there other packages that implement MEIS that we could test against?
    2. If the link function is actually linear and the error is actually Gaussian, then should the simulated likelihood be arbitrarily close to the typical Kalman filter likelihood if we compute it using a large enough number of trajectories?
    3. Are there special cases that come to mind where we can compute the result in some other way to check that this is behaving as expected?
  6. nguymin-theonlyone commented on Dec 12, 2025

    @nguymin-theonlyone
    Author

    Thank you very much for the suggestions and questions, this really helps.

    As far as I am ware off the MEIS is not implemented in a library. For the thesis, I used the programming language Ox with the SSfpack, but used my own functions to obtain the MEIS simulated likelihood. The code for the thesis hasn't been thoroughly reviewed, so I'd prefer to start fresh in Python for any new work.

    Yes, I completely agree that for initial testing, the absolute first step has to be validating the trivial case where everything is Linear Gaussian. That's our foundational check.

    Just thinking through some initial testing ideas for the MEIS implementation, here’s a quick summary of what I think would make sense to cover:

    1. Linear Gaussian Baseline (your suggestion):
      This is super important. We'd want to set up a plain old Linear Gaussian model (e.g., a Local Level model with Gaussian errors) within the MEISModel framework. Then, using a large number of simulations, the MEISModel's likelihood should basically match the exact Kalman Filter likelihood from MLEModel. We'd simulate the data ourselves so we know exactly what parameters to expect.

    2. Non-Gaussian playgrounds (simulated use cases):

    • Local Level + Poisson observations: A good test for count data.
    • Stochastic Volatility (SV) model + Student's t innovations: This is straight from the MEIS paper itself, so it's a critical real-world test case. For both of these, we'd simulate data with known parameters and see if MEISModel can accurately estimate them back. (By the way, Rutger Lit actually implemented the SV model for the paper; I've asked him if he can share the code.)
    1. "Health checks" for the Likelihood and Importance sampling weights:
    • Likelihood plotting:
      For simpler models, we can plot the simulated likelihood function. We'd hope to see it smooth and peak in the right place, not all bumpy or weird.
    • Importance sampling weight diagnostics:
      The weights must have finite variance. We should probably have the code log a warning (or even raise an error) if the Importance sampling weights show signs of large outliers or effectively "infinite" variance, indicating a breakdown in the sampling efficiency.
    • Inner loop (iterative OLS) convergence:
      It should be checked that the (b_t, C_t) estimation loop converges nicely and isn't just bouncing around.
    1. Robustness & Performance:
    • Missing data treatment
    • Stress testing: Throw some extreme parameter values at it to see if it breaks gracefully, e.g. add relevant exception messages.

    Let me know what you think.

    Best,
    Minh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions