CMRnet: An r package to derive networks of social interactions and movement from mark–recapture data

Long‐term capture–mark–recapture data provide valuable information on the movements of individuals between locations, and the contemporary and/or co‐located captures of individuals can be used to approximate the social structure of populations. We introduce an r package (CMRnet) that generates social and movement networks from spatially explicit capture–mark–recapture data. It also provides functions for network and datastream permutations for these networks. Here we describe the package and key considerations for its application, providing two example case studies. The conversion of spatially explicit mark–recapture data into social and movement networks will provide insights into the interplay between demography and behaviour in wild animal populations, with important applications in their management and conservation.


| INTRODUC TI ON
Social structure and population dynamics are closely intertwined (Shizuka & Johnson, 2019). The social structure of populations is critical in shaping key ecological processes, such as the spread of information and infections (Allen et al., 2013;Aplin et al., 2015;White et al., 2017), and in driving patterns of evolutionary change (Fisher & McAdam, 2017). On the one hand, social relationships will be influenced by demographic changes; for example, individuals may interact more with others at higher population densities (O'Brien et al., 2018). On the other hand, social relationships may influence key demographic processes, such as reproductive rates (McDonald, 2007), dispersal (Blumstein et al., 2009) or survival (Ellis et al., 2017). Hence, the interplay between demography and social structure is of immediate relevance to tackling numerous important questions in behavioural and evolutionary ecology, and yet longterm demographic data are rarely associated with detailed social analyses.
Many long-term studies of wild animals involve the collection of data based on capture-mark-recapture (CMR) approaches, where individuals are given a unique identifier when first captured, allowing identification if subsequently recaptured. If CMR data are spatiotemporally referenced (i.e. the location, time and date of each capture are recorded), then under the assumption that co-located individuals tend to be social associates, co-captures could be used as a proxy for social associations (e.g. Gimenez et al., 2019;Perkins et al., 2009). Information on co-location also permits inference of a spatial network of the movement of individuals within a population (Jacoby & Freeman, 2016). Networks constructed using CMR data are less precise than those which use specific behavioural observations or bio-logging approaches. However, CMR data may allow networks to be constructed in situations where these approaches are not feasible, and particularly over the entire timeline of longer-term studies where the addition of further time input and costs may be impractical.
We present an r package (CMRnet) for the construction and analysis of social (co-capture) and movement networks from spatiotemporally referenced CMR data. We provide an overview of how the package functions and some of the key considerations when using it to analyse real-world populations.

| FUN C TI ON S TO CON S TRUC T AND PERMUTE MARK-REC AP TURE NE T WORK S
The r package CMRnet (https://github.com/matth ewsil k/CMRnet) outlined briefly here, and in Supporting Information S1, provides tools to construct and analyse networks from CMR data where individual identities are associated with times and locations ( Figure 1).
Three types of network can be constructed using CMRnet: cocapture networks (i.e. spatiotemporal co-occurrence of captured individuals as a proxy for social associations); movement networks that link locations used by the same individual and multiplex movement networks. Multiplex networks are a type of multilayer network in which inter-layer edges can only connect the same actor (in this case, the same location) in each layer (Kivelä et al., 2014;Silk et al., 2018). Constructing multiplex movement networks makes it possible to consider the movements of different types of individual as separate network layers, and so can help consider the roles of phenotypes, life-history stages and even among-individual variation, in structuring the movement network using multilayer measures (see Kivelä et al., 2014).
For most datasets, co-capture networks are constructed using the function DynamicNetCreate(), movement networks using MoveNetCreate() and multiplex movement networks using MultiMoveNetCreate(). When networks are being constructed for data with higher temporal resolution, then equivalent functions are available that use times as well as dates for interaction and network F I G U R E 1 A simple example of how CMRnet takes spatially referenced mark-recapture data (a) to produce (b) social and (c) movement networks. In the example social network generated here (b), the network window equates to the whole data collection period and the interaction window is 1 (hence only captures occurring on the same day result in an edge in the network). Edges are weighted by the number of co-occurrences. In the example movement network generated here (c), the interaction window is set at 35 days (so only captures in adjacent months are recorded as movements)

F I G U R E 2
The two types of permutation procedure provided by CMRnet: (a) node feature swaps (node permutations) and (b) datastream permutations (edge rewiring). (a) Node feature swaps can be used to account for non-independence while breaking the association between a feature of interest (in this case node colour) and network position. Swaps can be constrained to occur only between particular combinations of individuals (indicated here by the green dashed line). (b) Datastream permutations swap either individual identities (for cocapture networks) or locations (for movement networks) between capture events, potentially leading to changes in network structure. They can also be constrained (e.g. by capture date in this case) to produce different null models (see Supporting Information S1 for more detail) windows (see Supporting Information S1). Both co-capture and movement networks require data to be formatted as in Figure 1, with an additional column indicating layer ID if multiplex movement networks are being constructed. Additional arguments are then supplied to the network construction functions to define the time periods over which networks are constructed and the precise definitions of nodes and edges within them (Table 1). The resulting co-capture networks are undirected and weighted (with different options for edge weights possible; see Table 1  or constrained to occur between particular combinations of nodes (the latter; in our first case study, we constrain swaps to occur between individuals that have been captured at the same locations).
The DatastreamPermSoc() and DatastreamPermSpat() functions conduct datastream permutations (Bejder et al., 1998;Farine, 2017) for both social and movement networks constructed using the package. These approaches can be used to test whether co-capture or movement networks are different to a particular reference model while accounting for variation in sampling effort. A naive reference model in this case would be a comparison to random, but we allow temporal or spatial constraints to be imposed on these datastream permutations to enable more sophisticated comparisons. More details on the permutation approaches are provided in Supporting Information S1.

| C A S E S TUD IE S
We present two case studies in Supporting Information S2 to illustrate the use of the package and highlight some important considerations. We use data from a long-term study of European badgers

| K E Y CON S IDER ATI ON S WHEN US ING CMR n e t
The generation of co-capture and movement networks using CMRnet relies on a series of underlying assumptions that it is important to be aware of when using the software.

| Defining nodes
The definition of nodes is trivial for co-capture networks generated using the package. However, for movement networks, the definition of nodes can involve some subjectivity. Movement networks are constructed using pre-determined locations as nodes.
For some study systems, animals will be captured at clearly defined locations (e.g. burrow systems, breeding colonies, etc.) and nodes can be defined easily. These types of datasets lend themselves naturally to analysis using CMRnet. In other instances, capture locations may be less clearly associated with distinct landscape features and the definition of nodes in the movement network will therefore be more challenging. It may be possible to treat each capture location as a distinct node, to group locations based on shared environmental features or with existing behavioural knowledge. However, caution should be exercised when doing so and sensitivity analyses should be considered to assure the robustness of conclusions.

| Defining edges
Several important assumptions may underlie the definition of edges within the networks generated, particularly for co-capture networks in which the user infers a likely association or interaction from the data. We advocate a question-driven approach for defining the spatial and temporal tolerance used in defining co-captures.
For example, researchers using network approaches to study wildlife disease could set interaction windows that reflect the ability of the pathogen of interest to persist in the environment, therefore defining edges of immediate relevance to transmission (Godfrey et al., 2009). However, uncertainty caused by the assumption that co-capture equates to a relevant interaction should be acknowledged and sensitivity analyses should be considered. In some contexts, other solutions may be preferable, one example being the use of Gaussian mixture models to define what constitutes a co-capture (Psorakis et al., 2012).

| Scale
Co-captures or detected movements can occur with different probabilities in different study systems. Regardless of whether a user is studying co-capture or movement networks, it is essential to select spatial or temporal windows that are meaningful for the research questions of interest. If networks generated using these windows are very sparse, other approaches should be preferred to using networks. Conversely, if individuals are recorded sufficiently regularly, as might be the case during intensive resighting of flocks of banded birds (Farine & Milburn, 2013;Napper & Hatchwell, 2016), then very short interaction windows can be used to ensure edges only connect individuals seen at the same location at the same time. At this point, co-capture network construction from CMR data becomes analogous to using the Gambit of the Group assumption to construct association networks (Franks et al., 2010). In these contexts, existing social network software such as asnipe (Farine, 2013) may be preferred.

| Capture effort
The detection of co-captures and movements in CMR datasets will depend on capture effort. Spatial or temporal variation in capture effort could therefore lead to spurious differences in network structure being detected if not adequately controlled (Gimenez et al., 2019). Care should be taken when using the network approaches described here when this is likely to be the case. In these situations, the use of permutation-based approaches becomes more important; datastream permutations can be used to produce null models that account for any spatial or temporal variation in trapping effort.

| Detection
A related challenge is variation in detectability among individuals.
Systematic variation in detectability can cause bias in the inference of associations in co-capture networks (Gimenez et al., 2019), or may cause unwanted differences between layers in multiplex movement networks (e.g. if inter-group movements are more likely to be detected in males than females, then the network layer of male movements may appear more connected than that of females even if it is not). The risk of this bias should be acknowledged and using these approaches naively when differences in detectability are aligned with the research question should be avoided. The use of permutation approaches can help deal with these biases but will require system-specific constraints (beyond the generic functions provided). In the longer term, the integration of demographic models (with their ability to handle missing observations and account for differences in detection) with existing social network models should be a priority.

| Computational limitations
Long time series and short or highly overlapping network windows will be computationally demanding, especially when using datastream permutations and should be a consideration when using the package. We provide some tips in Supporting Informations S1 and S2.

| CON CLUS IONS
Using network approaches to analyse CMR data offers real potential to provide insights into the social and spatial behaviour of animals.
CMRnet can be used to construct and analyse social and movement networks from these datasets, to allow the integration of network structure with demographic studies (Shizuka & Johnson, 2019) and enable the application of network approaches over longer time periods than is possible using more time-or cost-intensive approaches. The potential to extend insights from social and movement networks to larger temporal scales and far greater diversity of study systems will be highly beneficial in understanding the wider ecological implications of animal behaviour.

PE E R R E V I E W
The peer review history for this article is available at https://publo ns.

DATA AVA I L A B I L I T Y S TAT E M E N T
The r package CMRnet is available at https://github.com/matth ewsil k/ CMRnet with test data. The version of the package described in this paper is archived at https://doi.org/10.5281/zenodo.4059325 (Silk & Padfield, 2020).