Animal movement is central to many ecological processes and considered essential to our understanding of animal behaviour, population dynamics, and the impacts of global change. Coupled with advances in animal‐borne biologging technology, there has been a recent explosion in analytical methods for inferring animal movement, behaviour, space use, and resource selection from telemetry data (Hooten, Johnson, McClintock, & Morales, ). Largely attributable to their ease of implementation and interpretation, discrete‐time hidden Markov models (HMMs) have become immensely popular for characterizing animal movement behaviour (e.g. Jonsen, Flemming, & Myers, ; Langrock et al., ; McClintock et al., ; Morales, Haydon, Frair, Holsinger, & Fryxell, ).

In short, an HMM is a time series model composed of a (possibly multivariate) observation process (**Z**_{1},…,**Z**_{T}), in which each data stream is generated by *N* state‐dependent probability distributions, and where the unobservable (hidden) state sequence *i*,*j* = 1,…,*N*, and an initial distribution *δ*^{(0)}. The likelihood of an HMM can be succinctly expressed using the forward algorithm:*N* × *N* transition probability matrix, **P**(**z**_{t}) = diag(*p*_{1}(**z**_{t}),…,*p*_{N}(**z**_{t})), *p*_{s}(**z**_{t}) is the conditional probability density of **z**_{t} given *S*_{t} = *s*, and **1**^{N} is a *N*‐vector of ones. For a thorough introduction to HMMs, see Zucchini, MacDonald, and Langrock ().

The most common discrete‐time animal movement HMMs for telemetry location data are composed of two data streams (e.g. step length and turning angle) and *N* = 2 hidden states (Jonsen et al., ; Morales et al., ). These states are often considered as proxies for animal behaviour and characterized by area‐restricted‐search‐type movements (“encamped” or “foraging”) and migratory‐type movements (“exploratory” or “transit”). Some common probability distributions for the step length data stream are the gamma or Weibull distributions, while the wrapped Cauchy or von Mises distributions are often employed for the turning angle (e.g. Langrock et al., ). While HMMs based solely on location data are somewhat limited in the number and type of biologically meaningful movement behaviour states they are able to accurately identify, auxiliary biotelemetry and environmental data allow for multivariate HMMs that can incorporate much more behavioural realism and facilitate inferences about complex ecological relationships that would otherwise be difficult or impossible to infer from location data alone (e.g. DeRuiter et al., ; McClintock, London, Cameron, & Boveng, ; McClintock, Russell, Matthiopoulos, & King, ).

When data streams are observed without error and at regular time intervals, a major advantage of HMMs is the relatively fast and efficient maximization of the likelihood using the forward algorithm (Equation ) and computation of the most likely sequence of hidden states using the Viterbi algorithm (Zucchini et al., ). In movement HMMs, the decoded state sequence can be useful for determining when and where changes in behaviour occur, identifying habitats associated with particular behaviours (e.g. foraging “hotspots”), and calculating the proportion of time steps allocated to each state (i.e. “activity budgets”). However, location measurement error is rarely non‐existent in animal‐borne telemetry studies and depends on both the device and the system under study (e.g. Costa et al., ). Furthermore, telemetry data are often obtained with little or no temporal regularity, as in many marine mammal telemetry studies (e.g. Jonsen et al., ), such that observations do not align with the regular time steps required by discrete‐time HMMs. When explicitly accounting for uncertainty attributable to location measurement error, temporally‐irregular observations, or other forms of missing data, one must typically fit HMMs using computationally intensive (and often time‐consuming) model fitting techniques such as Markov chain Monte Carlo (e.g. Jonsen et al., ; McClintock et al., ). Unfortunately, complex analyses requiring novel statistical methods and custom model‐fitting algorithms are not practical for many practitioners.

While statisticians have been applying HMMs to telemetry data for decades, *N* = 2 states and two data streams (e.g. step length and turning angle). While moveHMM does permit *N* > 2, it is typically difficult to identify > 2 biologically‐meaningful behaviour states from only two data streams (e.g. Morales et al., ; Beyer, Morales, Murray & Fortin, ; McClintock et al., ). Both moveHMM and swim require temporally‐regular location data with negligible measurement error. Other notable deficiencies of existing software include limited abilities to incorporate spatio‐temporal environmental or individual covariates on parameters, biased movements in response to attractive, repulsive, or environmental forces (e.g. McClintock et al., ), group dynamic models (Langrock et al., ), cyclical (e.g. daily, seasonal) and other more complicated behavioural patterns, or constraints on parameters.

To address these deficiencies in existing software, we introduce a new user‐friendly

The workflow for momentuHMM analyses consists of several steps (Figure ). These include data preparation, data visualization, model specification and fitting, results visualization, and model checking. The workhorse functions of the package are listed in Table . Usage of several of these functions is deliberately similar to equivalent functions in moveHMM (Michelot et al., ), but the momentuHMM arguments have been generalized and expanded to accommodate a much more flexible framework for data pre‐processing, model specification, parameterization, visualization, and simulation.

A key feature of momentuHMM is the ability to include an unlimited number of HMM data streams (e.g. step length, turning angle, dive activity, heart rate) arising from a broad range of commonly used probability distributions (e.g. beta, gamma, normal, Poisson, von Mises, Weibull). Using model formulas familiar to most R users, any of the data stream probability distribution parameters can be modelled as functions of environmental and individual covariates via link functions (e.g. McCullagh & Nelder, , and see Table ). The initial distribution (*δ*^{(0)}) and state transition probabilities

^{a}Link functions (*g*) relate natural scale parameters (** θ**) to a

For temporally regular location data with negligible measurement error, the prepData function returns a momentuHMMData object (i.e. a data frame of class momentuHMMData) that can be used for data visualization and further analysis. Summary plots of momentuHMMData objects can be created for any data stream or covariate using the generic plot function. If location data are temporally irregular or subject to measurement error, then a two‐stage multiple imputation approach can be performed (Hooten et al., ; McClintock, ). We discuss this pragmatic approach to incorporating location uncertainty into HMMs of animal movement in Section 2.3.

The function fitHMM is used to specify and fit a (multivariate) HMM using maximum likelihood methods. There are many different options for fitHMM, so here we will only focus on several of the most important and useful features. The bare essentials of fitHMM include the arguments:*(N)**δ*^{(0)}) is considered equal to the stationary distribution

These seven arguments are all that are needed in order to fit the HMMs currently supported in moveHMM (Michelot et al., ), but the similarities between the packages largely end here. Many of the arguments in fitHMM and other momentuHMM functions are lists, with each element of the list corresponding to a data stream. Additional data streams can be added to HMMs by simply adding additional elements to these list arguments (see Section 3.2).

The formula argument can include many of the functions and operators commonly used to construct terms in **Γ**^{(t)}), but special functions allow for state‐ and parameter‐specific formulas to be specified. Specific state transition probabilities can also be fixed to zero (or any other value), which can be useful for incorporating more behavioural realism by prohibiting or enforcing switching from one particular state to another (possibly as a function of spatio‐temporal covariates). Similar arguments are available for initial distribution parameters .

The DM argument of fitHMM allows covariate models to be specified for the state‐dependent probability distribution parameters of each data stream. DM formulas are just as flexible as the formula argument. In lieu of formulas, DM can also be specified as a “pseudo‐design” matrix with rows and columns corresponding to the natural and working scale parameters, respectively (Table ). Pseudo‐design matrices allow working parameters to be shared among natural parameters for imposing relational constraints (e.g. μ_{1} = μ_{2}, μ_{1} ≤ μ_{2}). Probability distribution parameters can also be fixed to user‐specified values.

Another noteworthy fitHMM argument, circularAngleMean, enables circular–circular regression models for the mean direction of angular distributions, such as the wrapped Cauchy and von Mises, instead of circular‐linear models based on the tangent link function (Table ). As a trade‐off between biased and correlated movements, circular–circular regression models can weigh the attractive (or repulsive) strengths of angular covariates relative to short‐term directional persistence, using a special link function based on Rivest, Duchesne, Nicosia, and Fortin (). Many interesting hypotheses can be addressed using circular‐circular regression, including the effects of wind, sea surface currents, and centres of attraction on animal movement direction (see Sections 3.3 and 3.4).

When location data are temporally‐irregular or subject to measurement error, momentuHMM can be used to perform the two‐stage multiple imputation approach of McClintock (). There are three primary functions for performing multiple imputation HMM analyses: crawlWrap, MIfitHMM, and MIpool. Based on the *m* imputed datasets using maximum likelihood . Based on the *m* model fits, the MIpool function calculates pooled estimates, standard errors, and confidence intervals using standard multiple imputation formulae. Data streams or covariates that are dependent on location (e.g. step length, turning angle, habitat type, snow depth, sea surface temperature) will of course vary among the *m* realizations of the position process, and the pooled inferences across the fitted HMMs therefore reflect location uncertainty.

The generic plot function for momentuHMM model objects plots the data stream histograms along with their corresponding estimated probability distributions, the estimated natural parameters and state transition probabilities as a function of any covariates included in the model, and the tracks of all individuals (colour‐coded by the most likely state sequence). Confidence intervals for the natural parameters and state transition probabilities can also be plotted. For multiple imputation analyses, estimated 95% location error ellipses can be included in plots of individual tracks. Diagnostic tools include the calculation and plotting of pseudo‐residuals (Zucchini et al., ) using the pseudoRes and plotPR functions, respectively. Akaike's Information Criterion (AIC) and AIC weights can be calculated for one or more models using the AIC.momentuHMM and AICweights functions, respectively.

The function simData can be used to simulate multivariate HMMs from scratch or from a fitted model. The arguments are very similar to those used for data preparation and model specification, but they include additional arguments for simulating location data subject to temporal irregularity and measurement error. Among other features, activity centres and rasters of spatio‐temporal covariates can be utilized (see Section 3.4). simData can therefore simulate more ecologically realistic tracks (potentially subject to observation error) for study design, power analyses, and assessing model performance or goodness‐of‐fit (Morales et al., ).

We now demonstrate some of the capabilities of momentuHMM using real telemetry data. Intended for demonstration purposes only, we do not claim these represent improvements relative to previous or alternative analyses for these datasets. While space limits us to only a few key elements here, complete details and code for reproducing all examples described herein are provided in the “vignettes” source directory.

As our first example, we use an African elephant *Loxodonta africana* bull track described in Wall, Wittemyer, LeMay, Douglas‐Hamilton, and Klinkenberg (). In addition to hourly locations, the tag collected external temperature data. Using fitHMM, we fitted a two‐state HMM assuming a wrapped Cauchy distribution for turning angle and a gamma distribution for step length. Autocorrelation function estimates suggest there are 24 hr cycles in the step length data (Figure ), and this presents an opportunity to demonstrate the cosinor model for incorporating cyclical behaviour in model parameters. We therefore specified temperature effects on the turning angle concentration parameters and cycling temperature effects (with a 24 hr periodicity) on the step length and state transition probability parameters using the DM and formula arguments.

The model identifed a state of slow undirected movement (“encamped”), and a state of faster and more directed movement (“exploratory”) (Figure ). Interestingly, this model suggests step lengths and directional persistence for the “encamped” state decreased as temperature increased, step lengths for both states tended to decrease in the late evening and early morning, and transition probabilities from the “encamped” to “exploratory” state decreased as temperature increased (Figure ). This model was overwhelmingly supported by AIC when compared to alternative models with fewer covariates, but model fit can be further assessed using pseudo‐residuals. In this case, the pseudo‐residuals indicate the model explained much of the periodicity in step length, although there does still appear to be some room for improvement (Figure ).

We use the northern fur seal *Callorhinus ursinus* example from McClintock et al. () to demonstrate the use of additional data streams for distinguishing behaviours with similar horizontal trajectories (e.g. “resting” and “foraging”) in a multivariate HMM. The data consist of 241 temporally irregular Fastloc GPS locations obtained during a foraging trip of a nursing female near the Pribilof Islands of Alaska, USA. The tag included time‐depth recording capabilities, and the dive activity data were summarized as the number of foraging dives over *T* = 228 temporally‐regular 1 hr time steps. To fit the *N* = 3 state (1 = “resting”, 2 = “foraging”, 3 = “transit”) model of McClintock et al. (), we first used crawlWrap to predict temporally regular locations at 1 hr time steps assuming a bivariate normal location measurement error model. We then used multiple imputation to account for location uncertainty by repeatedly fitting the three‐state HMM to *m* = 100 realizations of the position process using MIfitHMM. We specified a gamma distribution for step length, wrapped Cauchy distribution for turning angle, and Poisson distribution for the number of foraging dives.

Our results were very similar to those of the discrete‐time Bayesian model of McClintock *et al*. (), with periods of “foraging” often followed by “resting” at sea (Figure ). Activity budgets based on the estimated state sequences for each imputation were 0.31 (95% CI: 0.23–0.4) for “resting”, 0.28 (95% CI: 0.23–0.34) for “foraging”, and 0.41 (95% CI: 0.31–0.51) for “transit”.

Using hitherto unpublished loggerhead turtle *Caretta caretta* data for a captive‐raised juvenile released on the coast of North Carolina, USA, we now demonstrate how movement direction and step length can be easily modelled as a function of angular covariates in momentuHMM. The data consist of temporally irregular Argos locations and rasters of daily ocean surface currents collected between 20 November and 19 December 2012. Assuming a gamma distribution for step length and a wrapped Cauchy distribution for turning angle, we modelled the mean step length parameter as a function of ocean surface current speed (*w*_{t}) and direction (*r*_{t}) relative to the bearing of movement (*b*_{t}) at time *t*. We also modelled the turning angle mean parameter as a trade‐off between short‐term directional persistence and bias in the direction of ocean surface currents using the circular‐circular regression link function.

Using multiple imputation, we fitted a two‐state HMM including a “foraging” state unaffected by currents and a “transit” state potentially influenced by ocean surface currents. After preparing the data, this rather complicated HMM can be specified, fitted, and visualized in only a few lines of code (see package vignette for complete details). For the “transit” state, pooled parameter estimates indicated step lengths increased with ocean surface current speed and as the bearing of movement aligned with ocean surface current direction (Figure ). The estimated wrapped Cauchy distribution for turning angle had mean angles (μ_{t}) biased towards the direction of ocean surface currents for each time step, with concentration parameter ρ = 0.86 (95% CI: 0.8–0.92) indicating turning angles were highly concentrated around μ_{t}. Thus, movement during the “transit” state appears to strongly follow ocean surface currents, while movement during the “foraging” state exhibited shorter step lengths perpendicular to ocean surface currents with no directional persistence .

We now revisit an analysis of a grey seal *Halichoerus grypus* track that was originally conducted by McClintock et al. () using Bayesian methods and computationally intensive Markov chain Monte Carlo. This seal tended to move in a clockwise fashion between two terrestrial “haul‐out” sites and a foraging area in the North Sea. Because the seal repeatedly visited the same haul‐out and foraging locations, it provides an excellent example for demonstrating how biased movements relative to activity centres can be modelled using momentuHMM. McClintock et al. () fitted a five‐state HMM to these data that included three “centre of attraction” states, with movement biased towards two haul‐out sites (“Abertay” and “Farne Islands”) and a foraging area (“Dogger Bank”), and two “exploratory” states that were unassociated with an activity centre. After using crawlWrap to predict *T* = 1,515 temporally regular locations at 2 hr time steps, we performed a very similar analysis to McClintock et al. () using MIfitHMM .

Each model fit required about 4 min on a standard desktop computer (macOS El Capitan, 16 GB RAM, 2.8 GHz Intel Core i7). Estimated activity budgets for the 5 states of this multiple‐imputation HMM were 0.28 (0.28–0.29) for the “Abertay” haul‐out state, 0.12 (0.11–0.14) for the “Farne Islands” haul‐out state, 0.37 (0.35–0.38) for the “Dogger Bank” foraging state, 0.09 (0.04–0.18) for a low‐speed “exploratory” state, and 0.14 (0.09–0.22) for a high‐speed “exploratory” state. All three activity centre states exhibited shorter step lengths and less biased movements when within the vicinity of these targets. Results from this analysis were thus very similar to McClintock et al. (), but this implementation required far less computation time and no custom model‐fitting algorithms. A simulated track generated using simData is presented along with the fitted track in Figure .

We have introduced the

Model fitting is relatively fast because the forward algorithm (Equation ) is coded in C++. Because multiple imputations are completely parallelizable, with sufficient processing power computation times for analyses that account for measurement error, temporal irregularity, or other forms of missing data need not be longer than that required to fit a single HMM. However, computation times will necessarily be longer as the number of states and/or parameters increase. For example, on a standard desktop computer (macOS El Capitan, 16 GB RAM, 2.8 GHz Intel Core i7), momentuHMM required about 1 hr to fit a single HMM with *N* = 6 states, seven data streams, and *T* = 7,414 time steps (McClintock, ).

As in any maximum likelihood analysis based on numerical optimization, computation times will also depend on starting values. Specifying “good” starting values is arguably the most challenging aspect of model fitting, and the package includes functions that are designed to help with the specification of starting values (e.g. checkPar0, getPar, getPar0, and getParDM). It also includes options for re‐optimization based on random perturbations of the parameters to help explore the likelihood surface and diagnose convergence to local maxima.

While momentuHMM includes functions for drawing realizations of the position process based on the CTCRW model of Johnson et al. (), this is but one of many methods for performing multiple imputation. Realizations of the position process from any movement model that accounts for measurement error and/or temporal irregularity (e.g. Calabrese, Fleming, & Gurarie, ) can be passed to MIfitHMM. Multiple imputation methods also need not be limited to these telemetry error scenarios. For example, other forms of missing data could be imputed, thereby allowing investigation of non‐random mechanisms for missingness that can be problematic if left unaccounted for in HMMs.

There remains many potential avenues for refinement and extension. Computation times could likely be improved by further optimizing the code for speed. Notable extensions include hidden semi‐Markov models and random effects (Zucchini et al., ). It is straightforward to add additional data stream probability distributions, and practitioners interested in additional features are encouraged to contact the authors.

We are grateful to R. Scott, B. Godley, M. Godfrey, J. Sudre, and North Carolina Aquariums for providing the data used in our turtle example. We thank S. Goslee, J. London, J. Sterling, and two anonymous referees for helpful comments on an earlier draft of this paper. The findings and conclusions in the manuscript are those of the author(s) and do not necessarily represent the views of the National Marine Fisheries Service, NOAA. Any use of trade, product, or firm names does not imply an endorsement by the US Government.

B.T.M. and T.M. developed the package and wrote the manuscript.

All code mentioned here is available in the momentuHMM package for R hosted on CRAN at