Flags multi-frame tracking errors as NA using the criterion from
Todd, Kain & de Bivort (2017): a frame-to-frame jump of more than
outlier_sd standard deviations starts an excursion, which is then
rejected if (and only if) the trajectory eventually returns either
close to the pre-excursion position or close to the overall median
position.
Arguments
- data
A data frame of numeric coordinate columns — typically supplied by
dplyr::pick()insidedplyr::mutate(). To filter a whole aniframe, usefilter_na_across().- outlier_sd
Threshold (in standard deviations) for flagging frame-to-frame jumps and for the "return to pre-excursion position" acceptance check. Todd's default is
5.- return_sd
Threshold (in standard deviations) for the "return to overall median position" acceptance check. Todd's default is
1.- by_axis
Logical. If
TRUE(the default), Todd's literal per-axis behaviour is used: each spatial column has its own σ, median, and excursion state machine, and a row is blanked if any axis flags it. IfFALSE, a single state machine runs on the joint Euclidean displacement (consistent withfilter_na_speed()).
Details
For each coordinate column, the algorithm:
Computes the standard deviation
σof the coordinate over the full series and the overall medianm.Walks the series. When a frame-to-frame change exceeds
outlier_sd * σ, an excursion starts: that frame is flagged and subsequent frames are flagged until the position is either withinoutlier_sd * σof its pre-excursion value, or withinreturn_sd * σof the overall median. The first such frame is accepted (not flagged), and the state machine resets.
This distinguishes transient excursions (a tracking glitch where the position eventually comes back) from sustained shifts (the animal genuinely moved to a new region) — the latter never satisfy the return condition unless the new region happens to be near the median, in which case it is accepted via the second criterion.
Every coordinate column is set to NA at a flagged row. confidence is
not a coordinate and so is never modified here; filter_na_across()
blanks it too.
References
Todd, J. G., Kain, J. S., & de Bivort, B. L. (2017). Systematic exploration of unsupervised methods for mapping behavior. Physical Biology, 14(1), 015002. doi:10.1088/1478-3975/14/1/015002 .
See also
filter_na_speed() for single-frame outliers.