rstatisticshidden-markov-modelsmarkov-chains

Error during MoveHMM for location data


I am using MoveHMM package (https://cran.r-project.org/web/packages/moveHMM/vignettes/moveHMM-guide.pdf) for HMM analysis but i am getting below mentioned error when i plot.

      Error in if (max(stepDensities[[state]][, 2]) > maxdens) maxdens <- 
      max(stepDensities[[state]][,  : 
      missing value where TRUE/FALSE needed

Code:

data <- prepData(output2,type="UTM",coordNames=c("Longitudes","Latitudes"));
 ## initial parameters for gamma and von Mises distributions
 mu0 <- c(0.1,1) # step mean (two parameters: one for each state)
 sigma0 <- c(0.1,1) # step SD
 zeromass0 <- c(0.1,0.05) # step zero-mass
 stepPar0 <- c(mu0,sigma0,zeromass0)
 angleMean0 <- c(pi,0) # angle mean
 kappa0 <- c(1,1) # angle concentration
 anglePar0 <- c(angleMean0,kappa0)
 ## call to fitting function
 m <- fitHMM(data=data,nbStates=2,stepPar0=stepPar0,
        anglePar0=anglePar0,formula=~1)
 plot(m)

Output2 Vector Data Vector


Solution

  • This error usually arises when the optimiser failed to converge, and returned extreme parameter estimates (e.g. Inf). You can see this if you print the fitted model object.

    The solution to such numerical issues is usually to try different initial parameter values ("stepPar0" and "anglePar0" in fitHMM; see Section 3.2.2 of the package vignette).

    Your problem seems to come from the initial parameters you chose for the step length distribution. The step lengths in your data set are values of the order of 1e-4, so your initial step length parameters should reflect that. Rather than using the values given in the vignette, you could try something like:

    mu0 <- c(5e-5,5e-4) # step length mean
    sigma0 <- c(5e-5,5e-4) # step length SD
    

    The idea is to choose "plausible" parameter values, given the observed step lengths and turning angles. You wouldn't expect a mean step length of one kilometre if the observed steps are all shorter than a metre.

    Edit: There is now a vignette giving some guidance for the selection of initial parameter values: A short guide to choosing initial parameter values for the estimation in moveHMM.