5

So I am trying to fit a hidden markov model to this fictional data but I am curious to know why do I get an NaN when I include the first data point and not when I exclude it? here is the code I am running:

library(RHmm)

y = c(100,rnorm(10000))

plot(y,type='l')


fit1 = HMMFit(y[-1],nStates=2)
fit2 = HMMFit(y,nStates=2)

And here is the output:

> fit1

Call:
----
HMMFit(obs = y[-1], nStates = 2)

Model:
------
2 states HMM with univariate gaussian distribution

Baum-Welch algorithm status:
----------------------------
Number of iterations : 47
Last relative variation of LLH function: 0.000001

Estimation:
-----------

Initial probabilities:
          Pi 1 Pi 2
  7.143032e-11    1

Transition matrix:
          State 1   State 2
State 1 0.6508174 0.3491826
State 2 0.8722256 0.1277744

Conditionnal distribution parameters:

Distribution parameters:
              mean       var
State 1 -0.1003040 0.9404932
State 2  0.2457188 1.0636770

Log-likelihood: -14189.94
BIC criterium: 28444.35
AIC criterium: 28393.88
> fit2

Call:
----
HMMFit(obs = y, nStates = 2)

Model:
------
2 states HMM with univariate gaussian distribution

Baum-Welch algorithm status:
----------------------------

NO CONVERGENCE AFTER 1 ITERATIONS

PROBLEM IN BAUM-WELCH'S ALGORITHM

Last Estimation:
----------------

Initial probabilities:
  Pi 1 Pi 2
   NaN  NaN

Transition matrix:
        State 1 State 2
State 1     NaN     NaN
State 2     NaN     NaN

Conditionnal distribution parameters:

Distribution parameters:
        mean var
State 1  NaN NaN
State 2  NaN NaN

Log-likelihood: NaN
BIC criterium: NaN
AIC criterium: NaN
4

0 回答 0