This is a quickstart guide to
model and visualize animal movements from radio-telemetry data using the
movetrack
package.
library(movetrack)
library(ggplot2)
theme_set(theme_bw(base_size = 15))
# Load example data
data(motusData)
The first step involves estimating animal locations based on antenna
bearings and signal strength at two-minute intervals using the
locate
function.
## Removed 10 detections containing missing values.
Next, we model the animal’s flight paths using Markov Chain Monte
Carlo (MCMC) with four parallel chains utilising the track
function and return a summary of the results.
## Running MCMC with 4 parallel chains...
##
## Chain 1 Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 2 Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 3 Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 4 Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 1 Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 1 Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 4 Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 4 Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 2 Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 2 Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 1 Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 1 finished in 120.4 seconds.
## Chain 2 Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 2 finished in 122.1 seconds.
## Chain 3 Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 3 Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 4 Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 4 finished in 129.4 seconds.
## Chain 3 Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 3 finished in 156.9 seconds.
##
## All 4 chains finished successfully.
## Mean chain execution time: 132.2 seconds.
## Total execution time: 157.1 seconds.
## ID time lon lat distance speed
## 1 49237 2023-08-20 20:16:00 8.80 54.8 NA NA
## 2 49237 2023-08-20 20:18:00 8.80 54.8 1134 9.45
## 3 49237 2023-08-20 20:20:00 8.79 54.8 1380 11.50
## 4 49237 2023-08-20 20:22:00 8.79 54.8 1506 12.55
## 5 49237 2023-08-20 20:24:00 8.78 54.8 1549 12.91
## 6 49237 2023-08-20 20:26:00 8.77 54.8 1678 13.99
## 7 49237 2023-08-20 20:28:00 8.76 54.8 1881 15.67
## 8 49237 2023-08-20 20:30:00 8.75 54.8 2035 16.96
## 9 49237 2023-08-20 20:32:00 8.74 54.7 1965 16.38
## 10 49237 2023-08-20 20:34:00 8.74 54.7 1799 14.99
## 11 49237 2023-08-20 20:36:00 8.74 54.7 1749 14.57
## 12 49237 2023-08-20 20:38:00 8.75 54.7 1706 14.21
## 13 49237 2023-08-20 20:40:00 8.76 54.7 1576 13.14
## 14 49237 2023-08-20 20:42:00 8.77 54.7 1431 11.92
## 15 49237 2023-08-20 20:44:00 8.78 54.7 1371 11.42
## 16 49237 2023-08-20 20:46:00 8.78 54.7 1421 11.84
## 17 49237 2023-08-20 20:48:00 8.79 54.7 1553 12.94
## 18 49237 2023-08-20 20:50:00 8.80 54.6 1890 15.75
## 19 49237 2023-08-20 20:52:00 8.80 54.6 2235 18.63
## 20 49237 2023-08-20 20:54:00 8.81 54.6 2342 19.52
## 21 49237 2023-08-20 20:56:00 8.82 54.6 2301 19.18
## 22 49237 2023-08-20 20:58:00 8.82 54.6 2445 20.37
## 23 49237 2023-08-20 21:00:00 8.83 54.5 2774 23.11
## 24 49237 2023-08-20 21:08:00 8.83 54.5 2966 6.18
## 25 49237 2023-08-20 21:10:00 8.82 54.5 2716 22.64
## 26 49237 2023-08-20 21:12:00 8.82 54.5 2239 18.66
## 27 49237 2023-08-20 21:14:00 8.81 54.5 1908 15.90
## 28 49237 2023-08-20 21:16:00 8.79 54.4 1808 15.07
## 29 49237 2023-08-20 21:18:00 8.78 54.4 1717 14.31
## 30 49237 2023-08-20 21:20:00 8.77 54.4 1697 14.14
## 31 49237 2023-08-20 21:22:00 8.76 54.4 1854 15.45
## 32 49237 2023-08-20 21:24:00 8.75 54.4 2012 16.77
## 33 49237 2023-08-20 21:26:00 8.75 54.4 1893 15.78
## 34 49237 2023-08-20 21:28:00 8.75 54.4 1729 14.41
## 35 49237 2023-08-20 21:30:00 8.76 54.4 1620 13.50
## 36 49237 2023-08-20 21:32:00 8.76 54.3 1692 14.10
## 37 49237 2023-08-20 21:34:00 8.76 54.3 1770 14.75
## 38 49237 2023-08-20 21:36:00 8.77 54.3 1597 13.31
## 39 49237 2023-08-20 21:38:00 8.77 54.3 1466 12.21
## 40 49237 2023-08-20 21:40:00 8.77 54.3 1410 11.75
## 41 49237 2023-08-20 21:42:00 8.77 54.3 1520 12.67
## 42 49237 2023-08-20 21:44:00 8.77 54.3 1812 15.10
## 43 49237 2023-08-20 21:46:00 8.77 54.3 2133 17.78
## 44 49237 2023-08-20 21:48:00 8.77 54.2 2264 18.87
## 45 49237 2023-08-20 21:50:00 8.77 54.2 2511 20.93
## 46 49237 2023-08-20 21:52:00 8.76 54.2 2836 23.63
## 47 49237 2023-08-20 22:10:00 8.76 54.2 2789 2.58
## 48 49237 2023-08-20 22:12:00 8.75 54.1 2454 20.45
## 49 49237 2023-08-20 22:14:00 8.74 54.1 2060 17.17
## 50 49237 2023-08-20 22:16:00 8.73 54.1 2031 16.93
## 51 49237 2023-08-20 22:24:00 8.72 54.1 2299 4.79
## 52 49237 2023-08-20 22:26:00 8.71 54.1 2708 22.57
## 53 49237 2023-08-20 22:28:00 8.70 54.0 3354 27.95
## 54 49237 2023-08-20 22:30:00 8.69 54.0 4280 35.66
## 55 49237 2023-08-20 22:34:00 8.68 54.0 5308 22.12
## 56 49237 2023-08-20 23:00:00 8.65 53.9 5997 3.84
## 57 49237 2023-08-20 23:02:00 8.63 53.9 6725 56.04
## 58 49237 2023-08-20 23:04:00 8.59 53.8 7587 63.23
## 59 49237 2023-08-21 00:16:00 8.55 53.7 8207 1.90
## 60 49237 2023-08-21 00:18:00 8.50 53.7 8335 69.45
## 61 49237 2023-08-21 00:20:00 8.45 53.6 8062 67.19
## 62 49237 2023-08-21 00:22:00 8.40 53.5 7784 64.87
## 63 49237 2023-08-21 00:24:00 8.34 53.5 7720 64.33
## 64 49237 2023-08-21 00:26:00 8.28 53.4 7966 66.38
## 65 49237 2023-08-21 01:44:00 8.23 53.3 7959 1.70
## 66 49237 2023-08-21 01:46:00 8.18 53.3 7468 62.23
## 67 49237 2023-08-21 01:48:00 8.14 53.2 6486 54.05
## 68 49237 2023-08-21 01:50:00 8.11 53.2 5430 45.25
## 69 49237 2023-08-21 01:52:00 8.08 53.1 4545 37.88
## 70 49237 2023-08-21 01:54:00 8.06 53.1 4031 33.59
## 71 49237 2023-08-21 01:56:00 8.04 53.1 3797 31.64
## 72 50893 2023-10-26 18:38:00 8.78 54.3 NA NA
## 73 50893 2023-10-26 18:40:00 8.78 54.3 4520 37.67
## 74 50893 2023-10-26 18:42:00 8.78 54.2 6174 51.45
## 75 50893 2023-10-26 18:44:00 8.79 54.2 7731 64.42
## 76 50893 2023-10-26 18:46:00 8.80 54.2 4138 34.49
## 77 50893 2023-10-26 18:48:00 8.81 54.2 3595 29.96
## 78 50893 2023-10-26 18:50:00 8.82 54.2 3561 29.68
## 79 50893 2023-10-26 18:52:00 8.84 54.2 3562 29.69
## 80 50893 2023-10-26 18:54:00 8.86 54.2 3747 31.23
## 81 50893 2023-10-26 18:56:00 8.87 54.1 4037 33.64
## 82 50893 2023-10-26 18:58:00 8.88 54.1 4687 39.06
## 83 50893 2023-10-26 19:00:00 8.88 54.1 4800 40.00
## 84 50893 2023-10-26 19:02:00 8.88 54.0 4606 38.38
## 85 50893 2023-10-26 19:04:00 8.86 54.0 4406 36.72
## 86 50893 2023-10-26 19:06:00 8.83 54.0 3958 32.98
## 87 50893 2023-10-26 19:08:00 8.77 54.0 4899 40.83
## 88 50893 2023-10-26 19:10:00 8.67 54.0 7420 61.83
## 89 50893 2023-10-26 19:12:00 8.53 53.9 12498 104.15
## 90 50893 2023-10-26 19:50:00 8.37 53.8 15450 6.78
## 91 50893 2023-10-26 19:52:00 8.24 53.7 13860 115.50
## 92 50893 2023-10-26 19:54:00 8.19 53.7 7947 66.22
## 93 50893 2023-10-26 19:56:00 8.15 53.6 5106 42.55
## 94 50893 2023-10-26 19:58:00 8.10 53.6 4401 36.68
## 95 50893 2023-10-26 20:00:00 8.07 53.6 3619 30.16
## 96 50893 2023-10-26 20:02:00 8.05 53.6 3410 28.41
## 97 50893 2023-10-26 20:04:00 8.05 53.6 3233 26.94
## 98 50893 2023-10-26 20:06:00 8.06 53.6 3287 27.39
## 99 50893 2023-10-26 20:08:00 8.08 53.6 3501 29.18
## 100 50893 2023-10-26 20:10:00 8.07 53.6 3339 27.83
## 101 50893 2023-10-26 20:12:00 8.00 53.7 6200 51.67
## 102 50893 2023-10-26 20:14:00 7.81 53.7 13765 114.71
## 103 50893 2023-10-26 20:16:00 7.75 53.7 5652 47.10
## 104 50893 2023-10-26 20:18:00 7.73 53.7 3612 30.10
## 105 50893 2023-10-26 20:20:00 7.64 53.7 6893 57.44
## 106 50893 2023-10-26 20:34:00 7.44 53.7 14093 16.78
## 107 50893 2023-10-26 20:36:00 7.26 53.7 12380 103.16
## 108 50893 2023-10-26 20:38:00 7.22 53.7 4132 34.43
## 109 50893 2023-10-26 20:40:00 7.22 53.7 3057 25.47
## 110 50893 2023-10-26 20:42:00 7.23 53.7 3056 25.47
## 111 50893 2023-10-26 20:44:00 7.23 53.7 3036 25.30
## 112 50893 2023-10-26 20:46:00 7.22 53.7 3051 25.43
## 113 50893 2023-10-26 20:48:00 7.20 53.6 3287 27.39
## 114 50893 2023-10-26 20:50:00 7.19 53.6 3333 27.78
## 115 50893 2023-10-26 20:52:00 7.16 53.6 3848 32.07
## 116 50893 2023-10-26 20:54:00 7.14 53.6 4022 33.52
## 117 50893 2023-10-26 20:56:00 7.13 53.6 4487 37.39
## 118 50893 2023-10-26 21:04:00 7.09 53.6 5545 11.55
## 119 50893 2023-10-26 21:06:00 7.08 53.5 4469 37.25
## 120 50893 2023-10-26 21:08:00 7.08 53.5 3512 29.27
## 121 50893 2023-10-26 21:10:00 7.08 53.5 3219 26.83
## 122 50893 2023-10-26 21:12:00 7.08 53.5 3075 25.62
## 123 50893 2023-10-26 21:14:00 7.08 53.5 3095 25.79
## 124 50893 2023-10-26 21:20:00 7.08 53.5 3734 10.37
## 125 50893 2023-10-26 21:22:00 7.09 53.5 3443 28.69
## 126 50893 2023-10-26 21:24:00 7.09 53.5 3504 29.20
## 127 50893 2023-10-26 21:26:00 7.08 53.5 5118 42.65
## 128 50893 2023-10-26 21:28:00 6.93 53.4 13146 109.55
## 129 50893 2023-10-26 21:30:00 6.51 53.3 30851 257.09
## 130 50893 2023-10-26 23:26:00 5.92 53.2 41745 6.00
## 131 50893 2023-10-26 23:28:00 5.35 53.1 40354 336.28
## 132 50893 2023-10-26 23:30:00 5.00 53.0 26137 217.81
## 133 50893 2023-10-26 23:38:00 4.84 52.9 12099 25.21
## 134 50893 2023-10-26 23:40:00 4.82 52.9 4526 37.72
## 135 50893 2023-10-26 23:42:00 4.82 52.9 3691 30.76
## 136 50893 2023-10-26 23:44:00 4.82 52.9 3422 28.51
## 137 50893 2023-10-26 23:46:00 4.81 52.9 3541 29.51
## 138 50893 2023-10-26 23:48:00 4.78 52.9 3821 31.84
## 139 50893 2023-10-26 23:50:00 4.76 52.9 3715 30.96
## 140 50893 2023-10-26 23:52:00 4.75 52.9 3600 30.00
## 141 50893 2023-10-26 23:54:00 4.74 52.9 3674 30.62
## 142 50893 2023-10-26 23:56:00 4.71 52.9 3758 31.31
## 143 50893 2023-10-26 23:58:00 4.69 52.8 3779 31.49
## 144 50893 2023-10-27 00:00:00 4.67 52.8 3556 29.63
## 145 50893 2023-10-27 00:02:00 4.67 52.8 3501 29.18
## 146 50893 2023-10-27 00:04:00 4.67 52.8 3563 29.69
## 147 50893 2023-10-27 00:06:00 4.65 52.8 4033 33.61
## 148 50893 2023-10-27 00:08:00 4.62 52.8 4119 34.32
## 149 50893 2023-10-27 00:10:00 4.60 52.8 3757 31.31
## 150 50893 2023-10-27 00:12:00 4.59 52.8 3612 30.10
## 151 50893 2023-10-27 00:14:00 4.59 52.8 3664 30.53
## 152 50893 2023-10-27 00:16:00 4.57 52.7 4988 41.57
## 153 50893 2023-10-27 00:18:00 4.55 52.7 8526 71.05
## 154 50893 2023-10-27 00:46:00 4.53 52.6 7484 4.45
## 155 50893 2023-10-27 00:48:00 4.52 52.6 5596 46.64
## 156 50893 2023-10-27 00:50:00 4.52 52.6 3921 32.67
## 157 50893 2023-10-27 00:52:00 4.52 52.6 3567 29.72
## 158 50893 2023-10-27 00:54:00 4.52 52.6 3528 29.40
## 159 50893 2023-10-27 00:56:00 4.53 52.6 3555 29.62
## 160 50893 2023-10-27 00:58:00 4.53 52.6 3620 30.17
## 161 50893 2023-10-27 01:00:00 4.53 52.6 4399 36.66
We can plot the results per individual and output variable using the
plot
function:
We can visualise the results on a map using the mapTrack
function:
Modelled movement trajectories per individual. Posterior means are shown together with 50 posterior draws, circles on the map indicate receiver locations with detections of the animals.
We could also create a Leaflet map using the following code:
library(sfheaders)
library(leaflet)
# Extract draws
draws <- getDraws(fit) |>
sf_linestring("lon", "lat", linestring_id = "tID")
# Leaflet map
fit |>
as.data.frame() |>
sf_linestring("lon", "lat", linestring_id = "ID") |>
leaflet() |>
addTiles() |>
addPolylines(data = draws, color = "grey", weight = 1, opacity = 0.2) |>
addPolylines(color = ~ c("orange", "blue"))