
Session 8 — Behavioural states, the research frontier, mini-project pitches
University of Rome Tor Vergata
2026-10-06
Internal state Motion capacity Navigation capacity External factors Movement path
A hidden Markov model is the most direct attempt in the course to infer the internal state from the path — and to let external factors drive it.
Imagine the animal has a hidden label at each time step — say “encamped” or “travelling”.
The model asks: what sequence of hidden states, and what state-specific distributions, would make the observed steps most likely?
Teal: an encamped state, short steps and random turns. Red: a travelling state, long and directed. The HMM sees only the path and has to work out the colours.
Cilla and Toni, hourly. Grey: all their steps. Coloured: the two fitted state distributions, weighted by how often each state occurs; dashed: their sum.
A clustering method looks at each step in isolation. An HMM knows that behaviour persists: an animal that was resting is probably still resting.
The same steps labelled two ways: a fixed threshold (dashed line) switches 35 times; the HMM, which knows that behaviour persists, 27 times.
An HMM fitted to hourly buffalo data returns two states: state 1 with mean step 45 m, state 2 with mean step 780 m. The diagonal of the transition matrix is 0.93 and 0.86. What is the expected dwell time in state 2?
For a Markov chain the expected number of consecutive steps in state \(i\) is \(1/(1-\gamma_{ii})\). Here \(1/(1-0.86) \approx 7.1\) steps, and since steps are hourly, about 7 hours.
State 1 gives \(1/(1-0.93) \approx 14\) steps, i.e. ~14 hours — plausibly the resting/ruminating state.
Note two things. First, the dwell time depends on the sampling interval: the same animal sampled every 2 hours would give a different \(\gamma_{ii}\) but a similar dwell time in hours. Second, this is a real, checkable prediction — if the model says foraging bouts last 7 hours and you know from direct observation they last 45 minutes, the model is telling you your states are not what you think.
In Session 4 the buffalo’s hourly speeds had no valley to cut at. That is exactly the situation an HMM was built for.
For two Kruger buffalo, a 2-state HMM with a daily cosinor on the transitions (hourly fixes, local time):

| Local time | P(moving) |
|---|---|
| 05:00 | ~0.69 |
| 11:00 | ~0.80 |
| 15:00–18:00 | ~0.86 |
| 23:00 | ~0.78 |
The covariate is on the switching, not on the step lengths: the buffalo do not walk differently in the afternoon, they are more likely to be walking. You fit this model in today’s practical.
HMMs as normally fitted assume a constant time step.
ctmm, momentuHMM with crawlWrap)This is why the bat dataset cannot be given an HMM: 165 bursts with a median of 4 fixes cannot inform a transition matrix (Session 3).
Choose the number of states from biology and the question, then check the fit. Pseudo-residuals and state-dependent distribution plots tell you far more than a table of AICs. Two or three states are almost always enough for what a tracking dataset can actually resolve.
You fit 2-, 3-, 4- and 5-state HMMs. AIC decreases every time. Which do you report?
AIC will keep improving because extra states always fit the shape of the data better — they mop up outliers and the tails of the step-length distribution. That is a statement about the flexibility of mixture models, not about the animal’s ethogram.
The defensible procedure: decide how many behavioural modes your data could plausibly resolve given the sampling interval, fit that model, and then check it — pseudo-residuals, state-dependent densities against the data, and dwell times against what you know about the species.
If a 4-state model gives you two states with nearly identical parameters, that is the model telling you it has run out of behaviour to find. Report the simpler one, and say why.
The model returns state 1 and state 2. It does not return “foraging” and “travelling”.
State the evidence for your labels, or call them “state 1” and “state 2” and describe them by their parameters.
Your 2-state HMM gives state 1 a mean step of 15 m with near-uniform turning angles. You want to call it “foraging”. What is the minimum you need?
The model returns state 1, not foraging. Short steps with unstructured turning angles are consistent with foraging — and equally with resting, ruminating, sheltering from heat, a collar that fell off, and an animal that has died. At 15 m, a good part of the apparent movement is GPS error.
To turn the label into a measurement you need something outside the trajectory: accelerometer or activity data, direct observation, known diel patterns, or a validation subset with ground-truthed behaviour.
Where you have none, the honest write-up describes states by their parameters — “a low-displacement state (mean step 15 m, dwell time ~14 h)” — and discusses the plausible behaviours without asserting one.
momentuHMM one zero-mass parameter per state: a zero-inflated gammaplotPR) — they are the residual plot of the HMM worldThe two-state buffalo model. Points on the line mean the model describes the data; the bent tails of the step residuals say two states do not capture the full range of step lengths.
crawl: Johnson et al. 2008) handle irregular sampling and predict positions with uncertainty — the honest version of interpolation from Session 3Motion capacity becomes a map — and a covariate you can put in an SSF.
A classifier is only as good as its labelled training data, and it transfers poorly between individuals, seasons and populations. Validate on animals it has not seen.
The skills of this course — cleaning, regularising, honest uncertainty — are what make pooled data trustworthy. At scale, errors compound too.
You classify foraging behaviour of a seabird from accelerometer data with a random forest trained on birds filmed at one colony, and it scores 94% accuracy on held-out segments from those same birds. What should you worry about before applying it to a different colony?
Held-out segments from the same birds share each bird’s idiosyncrasies — tag placement, body size, local conditions — so the test is not independent. Performance typically drops, sometimes sharply, on new individuals, seasons or colonies. Validate with whole individuals (and ideally whole sites) left out, exactly as for the habitat-selection models of Session 7.
buffer= was silently ignored; group_by() was silently ignored. Both cost us most of a dataset..qmd and the rendered HTMLThe paragraph on limitations is worth more marks than the analysis. Anyone can run fit_issf(). Knowing what it cannot tell you is the skill.
3–5 minutes each, no more than three slides
Examples: “compare home-range estimates under two fix rates using simulated data”; “SSF for a second fisher — does forest selection hold?”; “do the buffalo’s HMM states match day and night?”
All material: github.com/GiulianoColosimo/animtrack-2627
Go and track something.