Hi All,

I am trying to expand Hidden Markov Models to fit to typical movement data. The starting point is based on earlier discussions between @bgoodri and @Ben_Lambert. One extension that I am trying is to fit one hierarchical model to several animals, allowing the parameters that govern movement (ie step length and turning angle) to vary between the individuals.

The issue that I am running into is that initialization fail despite setting constraints to parameters in the transformed parameter block.

Here is the model I tried: hmm_covariates_hier.stan (5.1 KB)

And some code to generate data:

```
library(moveHMM)
library(rstan)
n_obs <- 200
ss <- simData(nbAnimals = 5,nbStates = 2,stepDist = "exp",
angleDist = "wrpcauchy",stepPar = c(2,0.1),anglePar = c(0,1,0.15,0.75),
obsPerAnimal = n_obs)
data <- list(N=(n_obs-2)*5,turn=ss$angle[!is.na(ss$angle)],
dist=ss$step[!is.na(ss$angle)],K=2,nCovs=1,
X=matrix(rep(1,(n_obs-2)*5),ncol=1),S=5,Ind_ID=ss$ID[!is.na(ss$angle)])
m <- stan("hmm_covariates_hier.stan",data=data,control=list(adapt_delta=0.99))
#this result in many initial error:
Error evaluating the log probability at the initial value.
validate transformed params: rho_ind[3] is -4.38754, but must be greater than or equal to 0
Rejecting initial value:
Error evaluating the log probability at the initial value.
validate transformed params: mu_ind[5] is -4.66398, but must be greater than or equal to -3.14159
Initialization between (-2, 2) failed after 100 attempts.
Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
```

I tried to play a bit around setting an initialization function, but this did not solve anything.

Am I missing something?