TheoMichelot / moveHMM

R package - Animal movement modelling using hidden Markov models
https://cran.r-project.org/package=moveHMM
38 stars 11 forks source link

Analysis for multiple animals and partial pooling #13

Closed bniebuhr closed 5 years ago

bniebuhr commented 5 years ago

Hello,

I have been using moveHMM to perform some movement analysis. When I have several animals from a population to analyze, and I prepare data for all of them, as I understand, the analysis is performed for all of them simultaneously, i.e., they are completely pooled in a single dataset for the analysis, although the classification of behavioral states may be inferred for each one (but based on a single set of distributions of step length and turning angle for all). Am I correct?

Based on that, I have two questions:

(please tell me if something is not clear in my questions)

TheoMichelot commented 5 years ago

[Edit 05/07/2019: The formulas suggested here are incorrect. Please see my response at the end of this thread.]

Dear Bernardo,

Indeed, if you provide a data set with several tracks (possibly from different individuals) to fitHMM, a single set of parameters will be estimated for all of them.

If you want different parameters to be estimated for the different individuals, then you could fit a separate model to each (e.g. with a loop, as you suggest). If you are mostly interested in individual heterogeneity in the behavioural dynamics, you could also include the ID as a "fixed effect", i.e. as a covariate in the transition probabilities. For example, using the argument formula of fitHMM, you could estimate different transition probabilities for each animal, using

formula = ~ animalID

Here, animalID is a column of your data, which identifies the individual animals. You could do something similar to estimate different covariate effects for the different animals, with something like

formula = ~ animalID * temp

With this interaction term, the effect of the covariate temp on the transition probabilities is estimated separately for the different individual animals.

Unfortunately, random effects are not available in moveHMM. A few papers have used random effects in HMMs for animal movement (McKellar et al., 2014; Towner et al., 2016; DeRuiter et al., 2017), but you would need to use custom code to implement them.

I hope this helps; please let me know if anything is unclear.

Théo

References:

bniebuhr commented 5 years ago

Hi, @TheoMichelot ,

thanks a lot for your answer. Yes, considering the animal ID as a fixed effect is a good idea for the "no pooling" I mentioned, and considering the differential effect of covariates in different individuals using the argument formula is a great idea. Thanks for that!

Thanks for the additional literature, also.

I'll make some tests here and I tell you if I find any problem.

TheoMichelot commented 5 years ago

Following from @windstorm13's related question (#15), I realised that the code that I suggested was incorrect.

The animal ID is a categorical covariate and, in moveHMM, it should be included using dummy variables. That is, for K individuals, K - 1 binary variables need to be included in the data set. Each takes value 1 if the row comes from the corresponding animal, and 0 otherwise. Then, the K - 1 dummy variables should be included as covariates in the model.

Sorry about the confusion.

Théo

bniebuhr commented 5 years ago

Hi @TheoMichelot

Thanks for adding that to the answer. However, I didn't get why one would need so many dummy variables instead of a single categorical factor representing individual ID (which, as I understand, would define the same number of parameters). Maybe in general lmand glm, this trick of transforming categorical into dummy variables is already implemented, but it need to be addressed explicitly in moveHMM?

Anyway, in this case, the formula would be something like formula ~ K1 + K2 + ... + Kn-1?

Thanks Bernardo

TheoMichelot commented 5 years ago

Maybe in general lm and glm, this trick of transforming categorical into dummy variables is already implemented, but it need to be addressed explicitly in moveHMM?

Yes, that's exactly right. The problem is that moveHMM doesn't deal with categorical covariates automatically.

The formula would look something like what you suggest, if you wanted to estimate different transition probabilities for the different individuals.

Best wishes, Théo