I am getting this error, when using fitHMM() for animal movement data:
Error in n2w(Par0[i], p$bounds, NULL, NULL, nbStates, inputs$estAngleMean, :
Check the parameter bounds for angle (the initial parameters should be strictly between the bounds of their parameter space).
This is my code:
stateNames <- c("encamped", "exploratory")
dist = list(step = "gamma", angle = "vm")
Par0_m1=list(step=c(0.013,0.9216,0.01,1.11,0.01,0.004),
angle=c(1,1))
m1 <-fitHMM(data=dataM, nbStates=2,
dist=dist, Par0=Par0_m1,
estAngleMean = list(angle=FALSE),
stateNames = stateNames)
m1 has an output:
step parameters:
----------------
encamped exploratory
mean 0.013173673 0.915614546
sd 0.009823547 1.115597292
zeromass 0.010918283 0.004483016
angle parameters:
-----------------
encamped exploratory
mean 0 0
concentration 0 0
and then I try to use these values to fit the second more complex model:
# Formula for transition probabilities
formula <- ~ Temp*cosinor(hour, period = 24)
# initial parameters obtained from m1
Par0_m2 <- getPar0(model=m1, formula=formula)
m2 <- fitHMM(data=dataM, nbStates=2,
dist=dist, Par0=Par0_m2$Par,
beta0=Par0_m2$beta, stateNames = stateNames,
formula=formula)
It is at this point, in trying to create m2, that the error occurs.
I have tried adjusting the initial angleCon0 values and rerunning both models - if angleCon0 = (0,0) then the error also occurs when I try to run m1, if angleCon0 = (0,1) again the error occurs for m1, if anglecon0=(1,1) then I can successfully run m1 (but still can't run m2). I don't understand what is happening there, why can the concentration not run with 0 values? Moreover, why can't m2 run using the values that successfully allowed m1 to run?;
I have also inspected Par0_m2$Par:
print(Par0_m2$Par
$step
mean_1 mean_2 sd_1 sd_2 zeromass_1
0.013173673 0.915614546 0.009823547 1.115597292 0.010918283
zeromass_2
0.004483016
$angle
concentration_1 concentration_2
0 0
I don't understand what the error is saying, nor how to resolve it.
The concentration parameter for the von Mises distribution must be strictly positive, so the starting values passed to fitHMM()
cannot be zero. It is unclear why both turning angle concentrations were estimated to zero in the first model (m1
), but getPar0()
just copies those values and passes them to fitHMM()
for the second model. This causes the error you have.
One solution would be to manually edit Par0_m2$Par$angle
to set the starting values to something other than zero, e.g.:
Par0_m2$Par$angle <- c(0.1, 1)
However, it is probably also a good idea to investigate why the concentration is estimated to zero. My guess is that the turning angles in your data have a peak at pi (i.e., many reversals in directions), but this cannot be properly captured because, by default, the mean turning angle is fixed to zero in momentuHMM. You could change this in both your models by using the option estAngleMean = list(angle=TRUE)
. Then, you will also need to add two starting values for the mean turning angle in the two states. Perhaps something like:
Par0_m1=list(step=c(0.013,0.9216,0.01,1.11,0.01,0.004),
angle=c(pi, 0, 0.5, 0.5))
where the first two entries of angle
are means, and the last two entries are concentration parameters.