[R] depmixs4 standardError() issue

Rolf Turner ro||turner @end|ng |rom po@teo@net
Sun Jun 25 03:36:40 CEST 2023


On Tue, 30 May 2023 17:43:31 +0000
Heather Lucas <hlucas2 using lsu.edu> wrote:

> Hello,
> 
> I've been enjoying using the "Mixture and Hidden Markov Models in R"
> by Visser & Speekenbrink to learn how to apply these analyses to my
> own data using depmixS4.
> 
> I currently have a fitted 4-state mixture model with three emissions
> variables and one binomial covariate (HS). I am trying to compute
> confidence intervals using the following code, where fmms4s is the
> model:
> 
> fmms4Svov <- vcov(fmms4S)$vcov  #this line runs fine
> fmms4Sse <- standardError(fmms4S)  #this is where I get the error
> fmms4SCI <- confint(fmms4S)
> 
> This worked fine before I added the covariate, but with the covariate
> I receive a warning message: In sqrt(diag(vc$vcov)) : NaNs produced.
> As a result, several of my parameters have NaNs as CIs.  In general,
> I get this error more frequently for more complex models (even when
> these models converge and show a better fit than simpler models) but
> I cannot find any information as to why this happens.  Getting rid of
> one of the emissions variables but leaving the covariate also seems
> to �fix� the issue but it crops up quite often for me in general.
> 
> Many thanks,

Greetings.  I hope, given the very belated nature of my response, that
you are still interested in this issue.  I have seen no answers to your
enquiry, so I am chipping in, despite my woeful lack of expertise.

Basically my guess would be that the NaNs result from  the covariance
matrix vc$vcov having negative diagonal entries --- negative variance
estimates.  I believe that vc$vcov would have been produced, at some
level, by inverting the negative of the Hessian matrix of the parameter
estimates.  In my experience, the Hessian matrices that arise in the
hidden Markov model context can be, shall we say, a bit delicate.
(Downright flaky, not to put too fine a point on it.) It may be the
case that the Hessian is not negative definite.

Theoretically the Hessian matrix will be negative definite at the
maximum (or at a local maximum) of the log likelihood of the model.
Convergence issues may be such that, even though the algorithm is judged
to have converged, the parameter estimates are sufficiently far from
the maximum point so that the Hessian will have some positive
eigenvalues (equivalently its negative will have some negative
eigenvalues) leading to the negative variance estimates.  If you could
look at it, you would probably find that the gradient vector (which
should theoretically be zero at the maximum) has some unacceptably
large entries.

The numerical analysis considerations that arise in maximising the log
likelihood of a hidden Markov model are fraught with difficulties and
subtleties.  The more complex the model, the more likely it is that
these difficulties will rear their ugly little heads.  When they do,
it seems to me, there is not much that an ordinary mortal can do about
it.

A couple of other comments.

(a) In the past I have communicated a bit with the maintainer of the
depmixS4 package (Ingmar Visser <i.visser using uva.nl>) and found him to be
reasonably helpful and responsive.  You might try contacting him
directly and see if he has any useful suggestions.  You would of course
have to make your data available to him, in order for him to get
anywhere.

(b) You might like to try experimenting with my package "eglhmm"
("extended generalised linear hidden Markov models").  This package has
considerable overlap with depmixS4, but has a very different syntax and
a different set of bells an whistles.  However I note that in your
enquiry you say that you have "three emission variables" so it appears
that you are dealing with a multivariate problem.  My package does not
do multivariate stuff, except in one restricted (and rather récherché)
context so my package probably won't be of any real use to you.

Also my package does not do mixtures as such.

If you *should* be interested in trying my package, you can get it from
my web page (https://www.stat.auckland.ac.nz/~rolf; scroll to the
bottom and click on "Eglhmm").  The source package and a Windoze binary
are available.  I have not yet submitted my package to CRAN, although I
hope to do so in the fairly (???) near future.

My package may well have a fair few bugs lurking in its innards.  (But
then, don't they all?)  If you do experiment with eglhmm, please let me
know about any bugs that you encounter.

I hope this of some help and interest.

cheers,

Rolf Turner

-- 
Honorary Research Fellow
Department of Statistics
University of Auckland
Stats. Dep't. (secretaries) phone:
         +64-9-373-7599 ext. 89622
Home phone: +64-9-480-4619



More information about the R-help mailing list