Introduction

The ability of groups of organisms to detect threats or predator attacks and then coordinate their collective movements to escape is observed in many species living in groups such as swarms of insects1, schools of fish2,3,4,5, flocks of birds6,7,8,9,10, and herds of mammals11,12,13. These patterns of collective motion often confuse the predator and increase the survival of the prey14,15,16,17,18,19,20 (for detailed review, see21).

These properties, sometimes referred to as a form of collective intelligence22,23, emerge at the group level from specific behavioral interactions between individuals24,25,26,27,28,29,30,31,32. Studying these interactions can provide insight into the way information spreads across groups of organisms in response to predator attacks and into the mechanisms by which animals coordinate their actions33,34,35,36,37,38. This knowledge is also fundamental to understanding how selective pressure acting at the individual level promotes flocking behaviors15,19,39,40,41,42,43.

Studying collective escape phenomena in the field is a challenging task. Predator attacks are not only unpredictable but also rare events. Simultaneously obtaining data on the trajectories of the predator and individuals within the group during these attacks can be extremely complex. To overcome these difficulties, some studies simulate threats and instigate collective responses via various methods, such as a human approaching antelopes13 or robotic models of predators approaching a flock of birds44 or a school of fish45.

Collective responses can also be investigated via the system of sheep herding, where interactions of a flock of sheep with a herding dog offer the opportunity to study the impact of a controlled threat on the collective movements of an animal group46. As a matter of fact, herding dogs have retained only some sequences of the predation behavior of wild canids. They display motor behavioral patterns such as searching and orienting, fixing, following, approaching, and finally chasing that are observed in related wild canids such as wolves and coyotes. But unlike the complete sequence characteristic of these species, the capture and killing of prey are absent in herding dogs47. Moreover, while predators typically aim to separate target individuals from the herd, sheepdogs are trained to maintain flock cohesion. However, several studies have reported that in the presence of a dog, sheep exhibit fearful behavior48,49 and their level of stress increases alongside an increase in plasma cortisol concentration50, suggesting that sheep perceive a herding dog as a threat. Since the behavior of the dog is controlled by the shepherd, it is thus possible to carry out a large number of replications of the same experimental situation.

Using a similar setup, King et al.46 studied the response of a sheep flock to a herding dog. The analyses of individuals’ trajectories, revealed that as the dog approaches, the sheep tend to move towards the center of the flock, a behavior consistent with the selfish-herd hypothesis. Moreover, in large sheep flocks (N = 100) without any external threat, sheep alternate between a slow grazing phase, during which the group spreads out, and fast packing events, during which sheep imitate the behavior of their neighbors and run toward the center of the group, thus increasing group density51. However, how exactly the directional information flows among sheep flock members remains unclear.

Here, we investigate the collective responses of a flock of sheep to the behavior of a herding dog focusing particularly on how directional information spreads within the flock. As the dog gets closer to the flock, it induces an avoidance reaction from the sheep. We analyze how this behavioral reaction to the perceived threat propagates within the flock and affects the collective movements of sheep. In our experiments, a trained border collie was responding to the verbal commands of the shepherd and used to guide a flock of sheep (N = 14) from an initial location to a target location (Fig. 1a). We collected the positions and orientation of all sheep, the dog and the shepherd with a Ultra wide band-based real-time location system during several dozen of trips performed by the flock. We first analyze the collective movements of the flock when interacting with the dog. We then analyze the directional correlation between the dog and the flock, as well as among the individual sheep, to determine how information propagates within the flock. We finally used a modified version of a shepherding model to show that simple interaction rules between sheep, and between sheep and the dog can reproduce key features of collective escape response and information flow observed in our data.

Fig. 1: Experimental design and quantitative analysis of the collective responses of a flock of sheep to a herding dog.
figure 1

a Flock of 14 females merino sheep (Ovis aries) and sheepdog (Border collie), equipped with Ubisense tags to track their positions while moving in a field of 80 m × 50 m, passing in front of a pole on which a Ubisense Ultra Wide Band sensor is fixed. b Trajectories (solid lines) of the 14 sheep (light blue) and the dog (red) along 26 seconds of a driving event, with their positions (circles) shown each 5 s and labeled from t1 to t6. The position of the barycenter of the flock and its instantaneous direction of motion for every 5 s are shown in dark blue. c Solid black dots represents the position of sheep obtained from the UWB tags and the sheep is shown only as a schematic. Velocity vectors \({\overrightarrow{v}}_{i}\) and \({\overrightarrow{v}}_{j}\), with their heading angles ϕi and ϕj, of two sheep i and j respectively; the angle, ψji, with which sheep j perceives sheep i, and the distance between them dij. d Velocity vector of barycenter of the flock \({\overrightarrow{v}}_{{{{\rm{B}}}}}\), velocity vector of the dog \({\overrightarrow{v}}_{{{{\rm{D}}}}}\), heading difference between both vectors ϕBD, angle the barycenter has to turn to perceive the dog ψBD, position of the dog \(({\bar{x}}_{{{{\rm{D}}}}},{\bar{y}}_{{{{\rm{D}}}}})\) in the system of reference of the barycenter and in the direction of motion of the flock (given by \({\overrightarrow{v}}_{{{{\rm{B}}}}}\)), and distance of the rear sheep of the flock (sheep in blue color) to the dog, in the direction of motion of the flock, \({\bar{y}}_{{{{\rm{RD}}}}}\).

Results

Collective behavior of sheep and their reaction to the dog

Figure 1 b shows the trajectories of the N = 14 sheep (blue lines) and the dog (red) over a 26-seconds herding event, and the instantaneous positions of each individual at 6 equispaced instants of time t1, …, t6. During this particular event, the sheep move away from the dog while remaining quite cohesive, with the dog staying behind the flock and exhibiting a zigzag motion (see also Supplementary video S1 and Supplementary video S2).

We characterize the sheep collective behavior using three observables: the group cohesion C, given by the mean radius of the group, the polarization P, which measures the degree of alignment of the individual sheep, and the elongation E, which measures the ratio length/width of the sheep flock with respect to its direction of motion (see Supplementary Fig. 1). The position of the dog is described by the relative position of the dog with respect to the barycenter (or group centroid) of the flock in the direction of motion of the flock, and the distance of the dog to the rear sheep in the flock in the direction of motion of the group (Fig. 1d).

We are first interested in describing how the sheep respond to the presence and the movements of the dog. Fig. 2a shows that, during the sequence depicted in Fig. 1b, sheep speed is about 1.3 ms−1, smaller than the dog mean speed, 2 ms−1. Sheep remain highly cohesive during the drive, C ≈ 1.2 m, which corresponds the typical body length of sheep (Fig. 2b); they remain well aligned, with P(t) > 0.6 all the time (Fig. 2c), which is substantially above the expected polarization value of N non-interacting individuals, \({P}_{0}\approx 1/\sqrt{N}=0.27\)52. Flock adopt an oblong shape perpendicular to the direction of motion, with E(t) smaller than 1 most of the time (Fig. 2b).

Fig. 2: Time series and probability density functions of the observables characterizing collective behavior of sheep and their reaction to the dog.
figure 2

a Speed of the barycenter of the flock vB(t) (light blue), dog vD(t) (magenta), and individual sheep (gray lines). b Cohesion C(t) (brown) and elongation E(t) (purple). c Polarization P(t) (dark blue). d Relative distance \({\bar{y}}_{{{{\rm{RD}}}}}(t)\) from the dog to rear sheep in the direction of motion of the flock, given by velocity vector of the barycenter (green), and distance dBD(t) from barycenter to the dog (dark-green). e Lateral movement of the dog with respect to the direction of motion of the flock \({\bar{x}}_{{{{\rm{D}}}}}\) (orange), and orientation of the barycenter ϕB(t). Vertical gray dashed lines in a-e show the instants of time shown in Fig. 1b. fj Probability density function (PDF) corresponding to the observables shown in the left column. Mean  ± SD values: 〈C〉 = 1.21 ± 0.34 m (~body length); 〈P〉 = 0.85 ± 0.17; 〈vB〉 = 1.3 ± 0.002 ms−1; 〈vD〉 = 1.5 ± 0.01 ms−1; Mode of E = 0.8. While the time series a-e are based on trajectories shown in Fig. 1b, the PDFs fj are constructed using data from all the drives.

The dog always remains behind the flock barycenter and almost always behind every sheep with respect to the direction of motion of the flock, i.e. \({\bar{y}}_{{{{\rm{RD}}}}}(t) \, > \, 0\) most of the time (Fig. 2d), and at a distance to the barycenter (dDB(t)) that varies  ≈ 3–5 m (Fig. 2d). The dog performs wide zigzags in the field (Fig. 1b), which are lateral movements with respect to the direction of motion of the flock, with \({\bar{x}}_{{{{\rm{D}}}}}\) displaying wide oscillations between negative (when the dog is at the left side of flock direction of motion) and positive (when the dog is at the right side) values, with an amplitude often larger than 2 m (Fig. 2e). These oscillations are also visible in the trajectory of the flock, as shown by the changes of variation of its direction of motion given by the barycenter heading ϕB (Fig. 2e).

To know the extent to which these behavioral features can be generalized, we have measured the probability density functions (PDF) of the observables, defined above, over all herding events (Fig. 2f–j). Indeed, the two PDFs of sheep speed and dog speed are quite similar, although the dog often reaches speed values that are quite larger than those of the sheep (see the bump at 2 ms−1 in the red curve in Fig. 2f). However, dog speed is more often lower than sheep speed, with a peak of vD located at 0.8 ms−1, below the location of the peak of vB at 0.9 ms−1. In turn, the dog often reaches a speed higher than 2 ms−1, yielding a mean speed of 1.5 ms−1, slightly higher than the mean speed of sheep, 1.3 ms−1 (Fig. 2f).

The flock remains cohesive, with a mean radius 〈C〉 = 1.21 m (~body length), SD = 0.34 m, with a peak in elongation at E = 0.8 (Fig. 2g), and highly polarized, 〈P〉 = 0.85, SD = 0.17 (Fig. 2h). The distance between the flock’s barycenter and the dog varies over a wide range, from dBD ≈ 3 to 7 m (Fig. 2i). The dog is well behind the flock in the direction of motion of the flock, typically at a distance between \({\bar{y}}_{{{{\rm{RD}}}}}\approx 1\) and 4 m from the rear sheep (Fig. 2i), and only in a small number of cases the dog surpasses the rear sheep (\({\bar{y}}_{{{{\rm{RD}}}}} < 0\)). The wide lateral oscillations of the dog have a typical amplitude similar to the one observed in the illustrative sequence shown in Fig. 1b, from  − 4 to 2 m, and can be even more pronounced, with \({\bar{x}}_{{{{\rm{D}}}}}\) ranging from  −6 to 6 m (Fig. 2j). Note that the negative/positive asymmetry is simply due to the limited number of experiments, as no left/right asymmetry is expected in sheep or dog behavior.

Figure 3 shows the impact of these wide lateral oscillations in the PDF of the angles with which the barycenter of the flock and the dog perceive each other. The PDF of the angle between the direction of the barycenter and the dog is wide, with values of ψBD greater than 120 being quite frequent, implying that the dog is behind the flock; conversely, the flock is ahead of the dog most of the times, although the distribution is relatively wide (Fig. 3a). Similarly, the PDF of the alignment between the barycenter of the flock and the dog headings is relatively wide, having practically the same shape than ψDB, showing frequent misalignments larger than ϕBD = 45 (Fig. 3b).

Fig. 3: Relative angular positions and headings of the barycenter of the flock and the dog.
figure 3

Probability density functions (PDF) of (a) the respective viewing angles ψBD and ψDB with which the barycenter (blue) and the dog (red) perceive each other, and (b) their heading angle difference ϕBD = ϕD − ϕB (blue).

We also calculate the turning rate, δϕi = ϕi(t + Δt) − ϕ(t), of the barycenter of the flock and that of the dog over 3 s as a function of ψDB and ψBD respectively. The turning rate of barycenter of the flock (δϕB) is close to 0 when the dog is behind the sheep (\(\left\vert {\psi }_{{{{\rm{BD}}}}}\right\vert \approx 18{0}^{\circ }\)), but turns in the opposite direction of dog as ψBD decreases, ie. when the dog moves towards the flanks of the flock (Fig. 4a).

Fig. 4: Turning rates of the barycenter of the flock and the dog.
figure 4

Turning angle over 3 s of the barycenter of the flock (a) and the dog (b) with respect to their corresponding viewing angles ψBD and ψDB, respectively. In all plots, purple and orange dots represent the observed turning rates for a given viewing angle, white dots correspond to the median, and the thick vertical line corresponds to the limits of the first and third quartiles, respectively.

Moreover, during herding events the dog turns towards the barycenter of the flock, and its turning rate (ΔϕD) is proportional to dog’s viewing angle (ψDB); in response to orders given by the shepherd, the dog performs enveloping movements to the right or left, until sometimes its direction of movement is perpendicular to that of the flock (Fig. 4b). There is also a notable correlation between the speeds of the dog and the barycenter, and the flock becomes less cohesive as sheep move at higher speeds (Supplementary Fig. 2). We find that both dog speed and barycenter speed increase or decrease simultaneously, suggesting a mutual influence between the dog and the sheep (Supplementary Fig. 3). In the next section, we delve further into revealing the influence between the dog and the sheep at fine time scales.

Directional correlations and hierarchical dynamics

In our experiments, the dog actively steers the flock between two designated points in the field. During these events, we aim to explore both the influence of dog behavior on the direction of sheep movement and how the behavior of an individual sheep affects the direction of movement of its neighbors. We infer that an individual j follows i if j consistently copies i’s direction with some time delay, denoted by τij. To identify this leader-follower relationship, we follow the methods described in53,54,55 and calculate the cross-correlation function between orientations of i and j, henceforth referred to as directional correlation (Fig. 5a, b; see also Supplementary Section 1 and Supplementary Fig. 4).

Fig. 5: Hierarchical leader-follower relationships.
figure 5

a Graphical representation of directional correlation analysis. dij is the projected relative distance (\({\overrightarrow{r}}_{i}-{\overrightarrow{r}}_{j}\)) between individuals i and j onto the direction of motion of the sheep flock (\({\overrightarrow{v}}_{B}\)) at time, t. b Representative directional correlation function Cij(τ) between 2 sheep during one of the herding events. τij = τ3 is the time delay at which Cij is maximum. c Leader-follower network of one of the drives. Nodes labeled from 1-14 are sheep; labels remain the same throughout the experiment. Nodes are plotted on a reference frame in which the barycenter (orange dot) is at origin facing north. Edges between nodes are drawn from followers to leaders, with the size of each node being proportional to the number of its followers. Relationship between the average relative spatial position and indegree in the data (d) and the model (e). Indegree serves as a proxy for hierarchy, where individuals with a high indegree are higher in the hierarchy.

We then construct a directed leader-follower network for each herding event based on the pairwise τij values computed for that herding event. In such a network, each node represents the dog or an individual sheep, and a directed edge is drawn from the follower to the leader. We infer the ‘leadership hierarchy’ of an individual by computing the indegree (defined as the number of incoming edges into a node) for the node representing the individual on the network. The higher the indegrees (or, in other words, the number of followers), the higher the position in the leadership hierarchy.

Here, we note that, for a given pair, a leader-follower relationship may not always exist. Unless one individual in the pair consistently copies the direction of the other, the strength of directional correlation will be negligible. However, in our data, we do observe consistent leader-follower pairs within each herding event. Figure 5c shows the leader-follower network observed during one of the herding events and Supplementary Fig. 5. shows the networks observed during other herding events. To understand the leader-follower relationship further, we overlay the network on a reference frame whose origin is the barycenter of the sheep flock. Furthermore, in Fig. 5c, the node’s size is proportional to its indegree and thus reflects its position in the leadership hierarchy.

We observe that sheep in the front of the flock are characterized by a higher indegree (bigger node size) compared to the sheep located in the back, lastly followed by the dog. In other words, the sheep at the front is the highest in the directional leadership hierarchy. Furthermore, although the dog drives the flock, it is the lowest in the leadership hierarchy. This suggests that the dog continuously adjusts its direction based on sheep motion. Consequently, we expect that the sheep in the front influences the group’s direction and, in turn, the dog’s direction.

To quantify the influence of individuals located at the front of the flock on the direction of its movements, we calculated the average distance of sheep from its neighbors projected onto the group velocity, \({d}_{ij}={ < ({\overrightarrow{x}}_{j}-{\overrightarrow{x}}_{i})\cdot {\overrightarrow{v}}_{{{{\rm{flock}}}}} > }_{t}\), and \({d}_{i}=\frac{1}{N}{\sum }_{j}{d}_{ij}\), where N is the number of sheep (Fig. 5a). For all sheep that are in the front of the group, di > 0, and consequently, di < 0 for sheep at the rear. As noted earlier, we use the indegree of a node as a proxy for its directional influence. So, we calculate di for all individuals with a given indegree. This informs us about the average spatial position of all sheep with the same indegree. In simple terms, it indicates where the sheep is located (front or back of the group center) for a given indegree. We find a strong correlation between \( < {d}_{i} > \) and the indegree of a node, confirming that sheep located in the front of the flock influence the direction of motion of the group and, in turn, on dog movement (Fig. 5d, Pearson’s correlation for \( < {d}_{i} > \) versus indegree, r = 0.85, n = 14, p < 0.0001. See Supplementary Fig. 6 for distribution of di for a given indegree). In Supplementary Section 2, we also present an alternative method to find a correlation between an individual’s relative spatial position and its position in the leadership hierarchy56. Here, we calculate the proportion of time di > 0 for a given indegree. We find that the proportion of times di > 0 is higher for individuals with high indegree, consistent with result shown in Fig. 5d (Supplementary Fig. 7) Furthermore, Supplementary Fig. 8 shows that some individuals are consistently found at the front of the group during the different herding events.

Modeling the collective response of the flock to the herding dog

To better understand how information propagates within the flock as a result of social interactions among sheep and their interactions with the dog, we use a modified version of a herding model developed by Strömbom et al57. The model is described in detail in Methods, and the values of the parameters used in the model are listed in Supplementary Table 1. Fig. 6 shows the results of extensive numerical simulations of the model (see also Supplementary videos 3 and 4). We find that group properties such as cohesion (Fig. 6a), elongation (Fig. 6b), polarization (Fig. 6c) and relative distance between dog to rear sheep (Fig. 6d) are all in qualitative agreement with experimental data. The lateral movement of the dog (\({\bar{x}}_{D}\)) shows a (weak) bimodal distribution in simulations (Fig. 6e), while the real data shows a broad unimodal distribution (Fig. 2j); we speculate that this minor difference could be due to higher noise in the real data. Additionally, we find that the PDFs of the viewing angle of the barycenter and the dog, and the difference in heading angles between barycenter and the dog, all qualitatively agree with experiments (Fig. 6f).

Fig. 6: Simulation results of the shepherding model.
figure 6

Probability density functions (a-f): a Cohesion. b Elongation. c Polarization. d Relative distance from the dog to rear sheep in the direction of motion of the flock \({\bar{y}}_{{{{\rm{RD}}}}}\). e Lateral movement of the dog with respect to the direction of motion of the flock, \({\bar{x}}_{{{{\rm{D}}}}}\). e Viewing angles ψBD and ψDB with which the barycenter and the dog perceive each other, and their heading angle difference ϕBD = ϕD − ϕB.

Importantly, we construct the interaction network for the simulation data using the same protocol as described in Section II B. Here too, we find that individuals in the front of the flock are more often influential in directional decisions, with the dog consistently adjusting its direction in agreement with experimental observations (Fig. 5e, also see Supplementary Section 3 and Supplementary Fig. 9 for the robustness of the results to model assumptions).

Furthermore, we aim to understand if the observed pattern of information propagation from front to back results from a constant perturbation induced by the dog or if it merely emerges as a consequence of social interaction between sheep. We first construct a null model of collective movement wherein we exclude the dog from the herding model. In the null model, sheep follow the same behavioral rules as in the herding model. However, in the null model, sheep do not graze but always move at a constant speed (see Supplementary Section 4 for details). Here, when we construct the interaction network based on directional correlations, we do not find any leader-follower pairs. Even when they exist, there are only 2-3 pairs of leader-followers. The leader-follower network is not as highly connected as the one observed in the real data or the herding model (see Supplementary Fig. 10).

In the herding model too, we note that there is no built hierarchy between the individuals in the model; further, as individuals do not occupy a fixed spatial position within the flock, we would expect that there would be no consistent leader-follower pairs. In contrast to these expectations but consistent with real sheep data, in the presence of a constant perturbation, such as a herding dog, we observe a hierarchical transfer of directional information of group motion (Fig. 5e). This is likely because once a perturbation event starts, individuals’ relative locations do not change, resulting in individuals located at the front of the flock having more influence on its direction of motion but only when they are consistently herded by the dog. Lastly, it is important to note that the last position occupied by the dog in the hierarchy with respect to sheep is not explicitly coded in the model but emerges as a result of the interactions between the dog and sheep.

Discussion

We investigated the collective responses of a flock of merino sheep interacting with a herding dog. Specifically, we study (1) the influence of the dog on the direction of sheep movement and (2) the impact of individual sheep both on their neighbors and the dog. Through the analysis of high-resolution spatiotemporal tracking data of both the dog (acting as a threat or stressor) and the sheep, we characterize the collective response of the flock and offer insights on the hierarchical nature of directional information flow.

In our experiments, we observe a highly polarized and cohesive sheep flock throughout the herding events. Additionally, we observe alignment between the flock and the dog. We emphasize that the groups are not only highly cohesive but also exhibit high polarization. Moreover, as the dog increases its speed, the group increases its speed while being highly polarized but less cohesive. The increase in group cohesion observed in our experiments when sheep interact with the dog is consistent with the mechanisms that reduce predation risks, such as the selfish herd effect46 or group defense21. However, recent studies indicate that an increase in group cohesion alone may not adequately explain the anti-predatory benefits of group living, especially when groups exhibit synchronous collective motion as observed in our sheep flock experiments9,19,44. Furthermore, computational models suggest that when the speeds of predators and prey are comparable, individuals aligning with neighbors rather than moving toward the group center are less likely to be captured58.

Through the analysis of time delays of directional correlations, we identify a clear hierarchy among sheep in terms of their directional influence on the flock. We find that the average spatial position of a sheep along the front-back axis of group velocity strongly correlates with its influence on group movement. In other words, although the flock is continuously chased by the dog, we find that the dog aligns its movement direction, on short time scales ( ~ seconds), with that of the flock, with the directional information flowing from front of the flock to the rear and then to the dog. While this appears counter-intuitive, in a previous study, Early et al.59 speculated that the dog’s adjustment was based on the flock’s movement in a yard. This unexpected directional hierarchy likely results from the proximity between the dog and the flock in confined sheep’s yards, which allows the flock to move in its intended direction while the dog adapts to the herd on a short time scale.

We also observe that some sheep find themselves typically in the front of the group while others are typically in the rear. We suggest that this spatial heterogeneity in sheep positions within the flock may arise from differences in individual reactivity to dogs60, with the individuals that are most sensitive to the presence of the dog being those who are at the front of the flock, thus initiating the directional changes. As an interesting contrast, in a recent study on sheep flocks in the absence of any threat61, all sheep had an equal probability of being at the front of the group.

While it is clear that individuals located in front had a greater directional influence on the herd, we did not observe a significant correlation between the spatial position of an individual and its influence on the speed changes of neighboring sheep (Supplementary Section 5 and Supplementary Fig. 11). This could be explained by the fact that as the flock maintains its cohesion during the herding events, it imperative that individuals move at a similar speed. Therefore, there may be no preferred position within the flock to influence the group’s speed or that of any other flock member. However, as shown in refs. 38,62, the directional changes in escape events do appear to depend on the spatial location of individuals since those on the periphery have more degrees of freedom to alter the direction of motion.

Our findings are consistent with observations in mobbing flocks interacting with a fixed ground-based predator model, in which individuals influencing the group’s direction of motion were located at the front63. Similar front-to-back directional information flows have also been reported in homing pigeons, merino sheep and meerkats exhibiting directed collective motion, although individuals were not subjected to an external threat54,56,61. On the other hand, in jackdaw flocks exhibiting synchronized motion but without any perturbation, the birds influencing the group’s direction were not only found at the front or edges but also at the rear63. In meerkat groups in motion, the individuals in front do not influence the speed of the group56. All this suggests that it is essential to consider the ecological context when inferring the social or hierarchical influence of individuals on each other in animal groups.

We strengthen our inferences using a computational model to show that sheep following simple interaction rules (i. e., repulsion from the dog and a tendency to move towards nearby neighbors and align with them), can reproduce collective response patterns similar to those observed in our experiments. Specifically, we observed a correlation between the average spatial position of sheep within the group and their hierarchy in directional influence. While certain individuals are often observed at the front of the group in experiments, the model suggests that individuals don’t need to be at a fixed spatial position within the flock to obtain the experimentally observed pattern of correlation between the spatial position of sheep and its hierarchical influence on the movement direction. In addition, using a null model, we also show the presence of a constant external perturbation that drives away the flock, such as a herding dog, is a must to produce the hierarchical directional influence from front to back. These observations suggest simple interaction rules of collecting and driving can reproduce the empirically observed patterns. Furthermore, the observed hierarchy in sheep is likely to be found more generally, beyond the specific shepherd system we studied, at least in small herds.

Our observations also reveal that the flock is often elongated perpendicular to the group velocity. This finding contrasts with expectations from fish schools, where oblong formations (ie. the group is elongated along its direction of motion) are considered to provide protection against predation64. The analysis of the herding model shows that group elongation is determined by the relative strengths of attraction (wAtt) and orientation (wAli). The model predicts that if the orientation strength is lower than the attraction strength, the mode of elongation occurs at values less than 1 (Supplementary Fig. 12); indicating that in sheep flocks, the strength of attraction is relatively higher than that of alignment. However, we emphasize that the alignment strength remains large enough to maintain a high degree of polarization observed in data, suggesting that both cohesion and highly directed motion are likely crucial for predator avoidance. Similar importance of the combination of both alignment and attraction when avoiding predators is also observed in pigeon flocks9.

In our study, we used only one sheep flock and the same dog across all trials. However, different groups display variations in collective properties such as cohesion, polarization, group speed, and information transfer65,66. Additionally, predators vary in attack rate and time spent near the prey, demonstrating that predators differ in their response to prey67. Therefore, these factors can affect the generalizability of our results. While we partially address this issue by developing a computational model to complement our findings, we note that to strengthen the generality of the conclusions, future studies could consider using various sheep flocks and dogs of the same breed, as well as different breeds.

In all our analyses, we only focused on the flock dynamics when the sheep were actively chased by the sheepdog. Thus, we did not study the dynamic interactions between sheep during grazing and threat detection. Recent studies on fish schools in the laboratory and blackbuck herds in the wild show a consistent pattern that the initial propagation of threat information across the group is often mediated by changes in speed13,68. Future studies could incorporate a grazing phase followed by introducing a threat to better understand the role of speed changes during collective escape in sheep flocks. Additionally, in our computational model, we assumed alignment interactions between sheep; however, some empirical studies didn’t find evidence for velocity matching28,29. Computational models have also demonstrated that empirically observed group properties can be reproduced without requiring explicit alignment interactions69,70,71. Therefore, a logical continuation would be to reconstruct the interaction rules between sheep, and between sheep and the dog directly from the UWB data. Interaction rules between individuals have been directly characterized in various species of schooling fish32,72.

Using a similar method and considering that Ubisense tags are both user-friendly and cost-effective, one can characterize and quantify interaction rules within this system as well. Such insights will enable the development of enhanced herding models with applications spanning various fields, including the creation of robots designed for environmental cleaning, crowd management, guiding groups of exploratory robots, and bio-herding73,74.

Methods

Herding experiments

Ethics

We have complied with all relevant ethical regulations for animal use. All procedures have been approved by the local Ethics Committee for Animal Science and Health of the experimental domain of Langlade (INRA, UMR 1388 GenPhySE), Pompertuzat, France, under permit APAFiS SSA 2017 005 in agreement with the French legislation. The dog handler has provided consent for their data to be included in this study and to be published. All ethical regulations relevant to human research participants were followed.

Study species

14 female merino sheep (Ovis aries) aged 4 years and with a mean body weight of 75 kg and mean body length of 1.2 m were used in the experiments. We also used an 8-year-old border collie specially trained to herd sheep and whose behavior during the experiments was managed by a professional handler (Fig. 1a).

Tracking system

We used a real-time location system developed by Ubisense based on Ultra-Wide Band (UWB) signals triangulation75 to track the movement trajectories of each sheep, the dog and the shepherd. Each sheep was equipped with two tags attached by a clip to the fleece along the axis of the vertebral column, which made it possible to get both the position and the orientation of the animal. The dog and his handler were also equipped with four and two tags respectively (Supplementary Fig. 13). Ubisense tags are miniaturized circuits powered with batteries that operate in a 6–8 GHz frequency band for localization and emit UWB wave trains that are then received and processed by a set of sensors. In our experiments, the tracking system included 8 sensors uniformly distributed around the experimental pasture and fixed 3 m from the ground. The sensors are UWB signal receivers connected through low-latency Ethernet cables to a server that processes sensor data into tags position. Each tag is localized at 2Hz with a typical error of less than 30cm.

Herding events

Experiments were performed on a flat rectangular pasture of 80 m length and 50 m width. The task consisted for the shepherd and his dog to drive the flock between two locations A and B, 60 m apart. We performed a total of 26 round trips during which the flock was driven from place A to place B and then brought back to place A, located in the middle of the enclosure, to minimize any potential boundary effects (see Supplementary Fig. 14). Each round trip lasted 2 minutes on average. The controlled movement phases of the flock were interspersed with five rest periods of 30 to 60 minutes each to allow the dog to recover and maintain sufficient motivation to carry out the task. During the experiments, sheep were not continuously exposed to the dog and spent most of the time at rest in a more or less random spatial configuration. In turn, the sheep move and align with each other in the dog’s presence. Supplementary Fig. 15 shows the two phases that can be identified in the whole set of data captured during the experiments: an active phase, where both speed and alignment are high, and a passive phase, where both speed and alignment are small. Supplementary Fig. 16 also shows that speed and alignment are positively correlated. We, therefore, focus our analysis on the active phase during which the dog was driving the sheep and staying behind the flock relative to its direction of movement.

While staying in this position, it may happen that the dog regularly alternates its direction of movement from left to right and vice versa, following the shepherd’s orders. Finally, most of the time, the shepherd remained motionless on one side of the field and gave his orders to the dog.

Quantification of collective behavior

We denote by \({\overrightarrow{r}}_{\! i}({x}_{i},{y}_{i})\) and \({\overrightarrow{v}\!}_{i}({v}_{x}^{i},{v}_{y}^{i})\) the position and velocity vectors of individuals, respectively, with i = 1, …, N for the sheep, i = D for the dog and i = B for the barycenter (or, group centroid) of the sheep flock given by \({\overrightarrow{r}}_{{{{\rm{B}}}}}(t)=(1/N){\sum }_{i = 1}^{N}{\overrightarrow{r}}_{i}(t)\). We consider that the heading of an individual is given by its direction of motion, i.e., by the angle of its velocity vector \({\phi }_{i}={\mathtt{ATAN2}}({v}_{y}^{i},{v}_{x}^{i})\) (Fig. 1c, d).

Then, we define the group cohesion C and the group polarization P as follows:

$$C(t)=\frac{1}{N}{\sum }_{i=1}^{N}{d}_{{{{\rm{B}}}}i},\quad P(t)=\frac{1}{N}\left\Vert \mathop{\sum}_{i=1}^{N}\frac{{\overrightarrow{v}}_{i}(t)}{{{{{\rm{v}}}}}_{i}(t)}\right\Vert ,$$

where \({{{{\rm{v}}}}}_{i}(t)=\parallel {\overrightarrow{v}}_{i}(t)\parallel\) is the speed of individual i and \({d}_{{{{\rm{B}}}}i}=\parallel {\overrightarrow{r}}_{i}(t)-{\overrightarrow{r}}_{B}(t)\parallel\) is the distance between the barycenter and i.

The viewing angle of i defined as the angle with which i perceives j, quantifies how much the velocity vector \({\overrightarrow{v}}_{i}\) has to turn to point towards j, ψij = θij − ϕi, where θij = ATAN2(yj − yixj − xi) is the angle that the vector going from i to j forms with the horizontal x-axis. The alignment of two individuals is measured by the difference of their headings, ϕij = ϕj − ϕi. Positive angles are measured counterclockwise, and negative angles are measured clockwise.

The average behavior of the flock is described by the velocity vector of the barycenter \({\overrightarrow{v}}_{B}\) (Fig. 1b, dark blue arrow). This vector defines the ordinate axis of an oriented system of reference centered on B (Fig. 1d). Denoting the variables in this system of reference with a bar, we have, for i = 1, …, N, D:

$${\bar{x}}_{i}=-{d}_{{{{\rm{B}}}}i}\sin {\psi }_{{{{\rm{B}}}}i},\quad {\bar{y}}_{i}={d}_{{{{\rm{B}}}}i}\cos {\psi }_{{{{\rm{B}}}}i}.$$

The length and the width of the group in its direction of motion can then be easily expressed using these variables so that the elongation can be defined as

$$E(t)=\frac{{\max }_{i=1,\ldots ,N}\{{\bar{y}}_{i}(t)\}-{\min }_{i=1,\ldots ,N}\{{\bar{y}}_{i}(t)\}}{\mathop{\max }_{i=1,\ldots ,N}\{{\bar{x}}_{i}(t)\}-\mathop{\min }_{i=1,\ldots ,N}\{{\bar{x}}_{i}(t)\}}.$$

The sign of \({\bar{x}}_{i}\) reveals the side where individual i is located with respect to the direction of motion of the sheep flock, and \({\bar{x}}_{i}\) shows how far the individual is from this direction. In particular, \({\bar{x}}_{{{{\rm{D}}}}}(t)\) reflects the lateral oscillations of the dog with respect to the direction of motion of the flock. Along this direction, the distance of the dog to the barycenter of the flock is given by \(-{\bar{y}}_{{{{\rm{D}}}}}\), and the distance of the dog to the rear sheep of the flock by \({\bar{y}}_{{{{\rm{RD}}}}}={\bar{y}}_{{{{\rm{R}}}}}-{\bar{y}}_{{{{\rm{D}}}}}\), where R refers to the rear sheep in this direction, that is, \({\bar{y}}_{{{{\rm{R}}}}}\le {\bar{y}}_{i}\) for all i. Negative values of \(-{\bar{y}}_{{{{\rm{D}}}}}\) and \({\bar{y}}_{{{{\rm{RD}}}}}\) mean respectively that the dog is in front of the barycenter or in front of the rear sheep.

Agent-based herding model

We use a discrete-time model, adapted from57, where the positions of individuals change at equispaced time instants tn = nΔt, Δt = 1 s.

Sheep

At a given time tn, each individual sheep i is located at \({\overrightarrow{r}}_{i}^{\,n}\) and moves to the point \({\overrightarrow{r}}_{i}^{\,n+1}\) given by

$${\overrightarrow{r}}_{i}^{\,n+1}={\overrightarrow{r}}_{i}^{\,n}+l\,\overrightarrow{e}({\phi }_{i}^{n+1}),$$
(1)

where \(\overrightarrow{e}({\phi }_{i}^{n+1})\) is the unit vector in the direction of \({\phi }_{i}^{n+1}\) and l ( = vSΔt) is the length traveled during this period. The angle \({\phi }_{i}^{n+1}\) is the sheep heading’s angle during this n+1-th time step and is given by the direction of the weighted additive combination of the vector director of the previous time step \(\overrightarrow{e}({\phi }_{i}^{n})\), an additive noise (\({\overrightarrow{{{{\mathcal{N}}}}}}_{i}^{\,n}\)), and the vectors corresponding to the external interactions to which the sheep is subject,

$${\overrightarrow{U}}_{i}^{n+1}=\alpha \,\overrightarrow{e}({\phi }_{i}^{n})+{\overrightarrow{S}}_{{{{\rm{social}}}}}^{\,i,n}+{\overrightarrow{R}}_{{{{\rm{Dog}}}}}^{\,i,n}+\epsilon \,{\overrightarrow{{{{\mathcal{N}}}}}}_{i}^{\,n},$$
(2)

where \({\overrightarrow{S}}_{{{{\rm{social}}}}}^{\,i,n}\) are the social interactions between sheep and \({\overrightarrow{R}}_{{{{\rm{dog}}}}}^{\,i,n}\) the repulsion from the dog. We assume that interactions between individuals can be expressed by linear functions that do not depend on the distance separating individuals.

Usually, in self-propelled particle models, agents align and attract with all the nearest, topological or metric neighbors76. However, recent studies have shown that in a moving animal group, each individual does not interact with all its neighbors but only with a small number of them. For instance, it has been shown that fish selectively interact with their most or two most influential neighbors52,77,78 or just one randomly chosen neighbor79,80. Sheep are also shown to select which neighbors they interact with81. Inspired by these empirical observations, we introduce a key modification in the model: sheep perceives a limited number of its nearest neighbors (k), among which only a few of them have an impact on its behavior82.

Thus, a number nAtt of these neighbors, chosen randomly, are considered to attract the sheep, and to contribute equally to the strength of the attraction (\({S}_{{{{\rm{Att}}}}}^{i}\)), and a number nAlinAtt, and sampled randomly from the nAtt attracting ones, are considered to act on the alignment of the sheep (\({S}_{{{{\rm{Ali}}}}}^{i}\)), all of them with the same intensity. Finally, the sheep is repulsed by every sheep closer than a short distance dRep, and this, with the same intensity. Thus, social interactions between sheep are described as follows:

$${\overrightarrow{S}}_{{{{\rm{Att}}}}}^{i}=\frac{{w}_{{{{\rm{Att}}}}}}{{n}_{{{{\rm{Att}}}}}}\mathop{\sum }_{j=1}^{{n}_{{{{\rm{Att}}}}}}\frac{{\overrightarrow{r}\!\!}_{j}-{\overrightarrow{r}\!\!}_{i}}{\parallel {\overrightarrow{r}\!\!}_{j}-{\overrightarrow{r}\!\!}_{i}\parallel },$$
(3)
$${\overrightarrow{S}}_{{{{\rm{Ali}}}}}^{i}=\frac{{w}_{{{{\rm{Ali}}}}}}{{n}_{{{{\rm{Ali}}}}}}\mathop{\sum}_{j=1}^{{n}_{{{{\rm{Ali}}}}}}{\overrightarrow{e}}_{j},$$
(4)
$${\overrightarrow{S}}_{{{{\rm{Rep}}}}}^{i}=-\frac{{w}_{{{{\rm{Rep}}}}}}{{n}_{{{{\rm{Rep}}}}}}\mathop{\sum }_{j = 1}^{{n}_{{{{\rm{Rep}}}}}}\frac{{\overrightarrow{r}\!\!}_{j}-{\overrightarrow{r}\!\!}_{i}}{\parallel {\overrightarrow{r}\!\!}_{j}-{\overrightarrow{r}\!\!}_{i}\parallel },$$
(5)

where each interaction has a positive weight w.

When the dog is closer than a distance RD, the sheep is repulsed in the opposite direction according to

$${\overrightarrow{R}}_{{{{\rm{Dog}}}}}^{i}=-{w}_{{{{\rm{Dog}}}}}\frac{{\overrightarrow{r}}_{{{{\rm{Dog}}}}}-{\overrightarrow{r}\!\!}_{i}}{\parallel {\overrightarrow{r}}_{{{{\rm{Dog}}}}}-{\overrightarrow{r}\!\!}_{i}\parallel },$$
(6)

where wdog is a positive weight.

As in57, we also assume that all sheep maintain a minimum distance of dRep from each other at all times to avoid collisions. Sheep move at speed vS via social interactions (align with and are attracted to their neighbors) only when the dog is within a distance RD. Otherwise, the sheep remain in a ‘grazing’ phase and do not move.

Dog

Sheepdogs are typically controlled by a shepherd, who wishes to drive the flock from one point to another by using the dog as a repulsive stimulus that makes the individual sheep move away from it. We are interested in situations where the sheep are grouped in a flock, and the sheepdog is positioned at one side of the flock. Then, the shepherd adjusts the position of the dog to make the flock travel toward a target point T. For simplicity, we assume that the dog moves straight with constant speed vD = 1.5 ms−1, unless a sheep is closer than a short distance la, in whose case the dog slows down to vD = 0.05 ms−1.

At each time step, the dog’s position is updated as a function of the position of the barycenter of the flock with respect to the target point, so that the repulsion that the dog exerts on the sheep points towards the target. Thus, the dog moves towards a point Pdrive such that the barycenter of flock B lies between Pdrive and the target T, ensuring that the three points are aligned and that a distance ldrive separates Pdrive from B (Fig. 7). If an individual sheep Si separates from the flock more than a distance lsep, the dog has to make it to return to the group. Then, Pdrive is defined in the same way but considering that the barycenter of the flock is the target and Si is the sheep to be driven. Once the sheep is back in the group, the dog returns to drive the flock towards the target.

Fig. 7: Schematic representation of the interaction rules in the computational model for (a) dog and (b) sheep.
figure 7

At each time step, the dog’s position is updated based on whether: (a1) the flock is cohesive (ie. the distance of the farthest sheep from the barycenter (B) is less than lsep), or (a2) non-cohesive (ie. the distance of the farthest sheep from the barycenter is greater than lsep). The dog moves in a straight line at a constant speed, vD, if it is farther than ła distance from all agents. Otherwise, it moves at 0.05vD. (b1) Sheep move away (along \({\overrightarrow{R}}_{{{{\rm{Dog}}}}}^{i}\)) from the dog if it is within distance RD. Sheep repel from their neighbors that are within a distance of dRep along \({\overrightarrow{S}}_{{{{\rm{Rep}}}}}^{i}\). Sheep align and attract towards a set of randomly chosen neighbors among those they can perceive. For example in (b2), the focal sheep can perceive five nearest neighbors (k = 5, marked 1-5). The focal sheep is attracted towards the average direction, \({\overrightarrow{S}}_{{{{\rm{Att}}}}}^{i}\), of four randomly chosen neighbors (nAtt = 4, sheep marked 1-4 in this case) and aligns (\({\overrightarrow{S}}_{{{{\rm{Ali}}}}}^{i}\)) with one of those chosen neighbor (nAli = 1, sheep marked 4 in this case). We set k = 10, nAtt = 5, and nAli = 1 in our simulations (see Methods). The resulting heading vector of sheep i is a linear weighted combination of repulsion from the dog, collision avoidance, attraction towards neighbors, and orientation towards neighbors, each with their corresponding weights given by wDog, wRep, wAtt, and wAli respectively. We set Rd = 12, Ra = 2, wDog = 1, wRep = 2, wAtt = 1.5, wAli = 1.3, α = 0.5, e = 0.5, vS = 1 ms−1, and vDog = 1.5 ms−1 in our simulations.

The point Pdrive is then given by

$${\overrightarrow{r}}_{{P}_{{{{\rm{drive}}}}}}=\left\{\begin{array}{ll}{\overrightarrow{r}\!\!\!}_{B}-{l}_{{{{\rm{drive}}}}}\frac{{\overrightarrow{r}\!\!\!\!}_{T}-{\overrightarrow{r}\!\!\!\!}_{B}}{\parallel {\overrightarrow{r}\!\!\!\!}_{T}-{\overrightarrow{r}\!\!\!\!}_{B}\parallel }\quad &\,{\mbox{if}}\,\,R\le {l}_{{{{\rm{sep}}}}},\\ {\overrightarrow{r}\!\!\!}_{{i}^{* }}-{l}_{{{{\rm{drive}}}}}\frac{{\overrightarrow{r}\!\!\!\!}_{B}-{\overrightarrow{r}\!\!\!\!}_{{i}^{* }}}{\parallel {\overrightarrow{r}\!\!\!\!}_{B}-{\overrightarrow{r}\!\!\!\!}_{{i}^{* }}\parallel }\quad &\,{\mbox{if}}\,\,\parallel {\overrightarrow{r}\!\!}_{{i}^{* }}-{\overrightarrow{r}\!\!}_{B}\parallel > \, {l}_{{{{\rm{sep}}}}},\end{array}\right.$$
(7)

where i* is the most distant sheep from the barycenter, i.e., \(\parallel {\overrightarrow{r}\!\!}_{{i}^{* }}-{\overrightarrow{r}\!\!}_{B}\parallel \ge \parallel {\overrightarrow{r}\!\!}_{i}-{\overrightarrow{r}\!\!}_{B}\parallel\) for all i = 1, …, N.

A modified version of the model

To test the robustness of the model results, we also consider a modified version of the model in which RD does not cover the entire flock. Under this condition, to ensure that the flock remains cohesive and polarized, we assume that sheep social interactions (attraction and alignment) are always present among sheep, regardless of the dog’s position. Further, we assume that the sheep also copy their neighbor’s speed. Further details of the model and results are presented in Supplementary Section 2.

Statistics and reproducibility

We used the same 14 female marino sheep and a border collie in all our experiments. From these experiments, we analyzed data from 26 drives, which are events in which the dog is behind the moving sheep flock and is chasing the sheep flock. Statistical tests are reported using Pearson’s correlation. p < 0.05 was considered to be statistically significant. The data analysis and visualization were done with MATLAB Version: 23.2.0.2485118 (R2023b), Natick, Massachusetts: The MathWorks Inc.