Recology
Recology

Reputation: 137

Error while using the plot function of the package moveHMM in R

I have fitted a Hidden Markov Model using the moveHMM library in R.

hmm_model <- fitHMM(data = move_data, nbStates = 3, stepPar0 = stepPar0, anglePar0 = anglePar0, formula = ~1)

The result makes sense biologically speaking and I do not have any warning issued.

As indicated in the package documentation (https://cran.r-project.org/web/packages/moveHMM/vignettes/moveHMM-guide.pdf) I tried to plot the object.

I tried the following commands:

plot(hmm_model, type = "states")
plot(hmm_model)

but I always get the same error message:

> plot(hmm_model, type = "states")
Decoding states sequence... DONE
Error in if (maxdens > ymax & maxdens < 1.5 * ymax) { : 
  missing value where TRUE/FALSE needed

Has anyone ever encountered this issue and would have any recommendations on how to solve it?

Here is the structure of the object that should be plotted:

> str(hmm_model)
List of 7
 $ data       :'data.frame':    16515 obs. of  6 variables:
  ..$ ID         : chr [1:16515] "1" "1" "1" "1" ...
  ..$ step       : num [1:16515] 0.327 0.346 0.346 0.346 0.346 ...
  ..$ angle      : num [1:16515] NA -0.156381 -0.004527 -0.001887 -0.000926 ...
  ..$ x          : num [1:16515] 582629 582629 582628 582628 582628 ...
  ..$ y          : num [1:16515] -2195359 -2195359 -2195358 -2195358 -2195358 ...
  ..$ (Intercept): num [1:16515] 1 1 1 1 1 1 1 1 1 1 ...
 $ mle        :List of 5
  ..$ stepPar : num [1:3, 1:3] 3.43e-15 8.36e+09 1.00 8.31e-02 1.13e-01 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:3] "mean" "sd" "zero-mass"
  .. .. ..$ : chr [1:3] "state 1" "state 2" "state 3"
  ..$ anglePar: num [1:2, 1:3] 1.31e-03 2.83 1.32e-03 2.23e+01 -3.31e-10 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr [1:2] "mean" "concentration"
  .. .. ..$ : chr [1:3] "state 1" "state 2" "state 3"
  ..$ beta    : num [1, 1:6] -6.91 -37.97 -9.65 -25.74 -0.43 ...
  .. ..- attr(*, "dimnames")=List of 2
  .. .. ..$ : chr "intercept"
  .. .. ..$ : chr [1:6] "1 -> 2" "1 -> 3" "2 -> 1" "2 -> 3" ...
  ..$ delta   : num [1:3] 2.67e-10 1.00 1.32e-14
  ..$ gamma   : num [1:3, 1:3] 9.99e-01 6.44e-05 3.38e-01 9.93e-04 1.00 ...
 $ mod        :List of 6
  ..$ minimum   : num -27526
  ..$ estimate  : num [1:23] -33.31 -2.49 1.61 22.85 -2.18 ...
  ..$ gradient  : num [1:23] 0 -0.00268 0 0 0.00216 ...
  ..$ hessian   : num [1:23, 1:23] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ code      : int 1
  ..$ iterations: int 73
 $ conditions :List of 6
  ..$ stepDist     : chr "gamma"
  ..$ angleDist    : chr "vm"
  ..$ zeroInflation: logi TRUE
  ..$ estAngleMean : logi TRUE
  ..$ stationary   : logi FALSE
  ..$ formula      :Class 'formula'  language ~1
  .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv> 
 $ rawCovs    :'data.frame':    16515 obs. of  0 variables
 $ knownStates: NULL
 $ nlmTime    : 'proc_time' Named num [1:5] 66.16 0.72 66.88 NA NA
  ..- attr(*, "names")= chr [1:5] "user.self" "sys.self" "elapsed" "user.child" ...
 - attr(*, "class")= chr [1:2] "moveHMM" "list"

Many thanks (I do not really know how to make this issue reproducible, so I am asking about the error message to get a first idea).

Upvotes: 0

Views: 75

Answers (0)

Related Questions