Is there anyone here who tried to use Julia for HMM-GLM models using Expectation Maximization?
I’m looking for good references to try it out. I looked at HiddenMarkovModels.jl but I’m not sure how to use it to learn the GLM parameters.

Would be great to hear if someone tried it already.

Hi, I’m the developer of HiddenMarkovModels.jl. Did you see the tutorial on Markov-switching regression? There’s a lot of different terminology but it seems to be close to what you need.
There’s also a dedicated package called MarSwitching.jl, whose interface might be easier to work with for you (but perhaps less flexible).

Yes, if you have a regression y_t = f(x_t, \theta[i_t]) whose parameters \theta depend on the hidden state i_t of a Markov model, then in my package docs the “controls” are the regression inputs x_t and the “observations” are the regression outputs y_t.

Yes, but unfortunately for every new controlled model you have to code the estimation procedure yourself. The “learning” section of the tutorial demonstrates this:

the first part of the fit! function is standard transition estimation for HMMs,

the second part of the fit! function estimates \theta[i] for each possible value of i.

The key here is that to recover \theta[i], you use every pair (x_t, y_t) but you weigh them individually by the posterior probability of being in state i, which is stored in \gamma_{i,t}. In the case of linear regression there is an explicit formula (which I hope I got right), for logistic regression you have to use numerical optimization with a slightly adjusted loss function. Does that make sense?

Yes, this is alluded to in the “model” section of the tutorial. By overloading HMMs.transition_matrix(hmm, control), you can impose this additional dependency. But then the transition estimation in the fit! function must also be adapted manually.

Perfect! This is a great answer that got me the info to get started!
I will read how to optimize the logistic parameters and will try to use your package as it seems like a great ecosystem for it. Thank you for the informative answer!

Awesome! Ping me again if you struggle.
The logistic regression alone should be straightforward to code, you just need to find a package that allows you to estimate it with weighted samples (you can do it in MJL.jl for example, see Weights · MLJ).
However, if you let your transition matrix depend on the controls, you need to make sure that the resulting model allows easy estimation, because gradient descent is much harder for stochastic matrices.