Skip to contents

Checks how often a number sequence changes from decreasing monotonically to increasing monotonically (or vice versa).

Usage

direction_changes(numeric_vector)

Arguments

numeric_vector

Numbers, ordered by their time of appearance.

Value

Single number indicating how often numeric_vector changes direction (0 to +Inf).

Details

The supplied vectors are assumed to be ordered by time. Values do not have to be strictly monotonically in-/decreasing. I.e., c(0, 1, 1, 2) would return 0, as \(x_n >= x_n-1\) is satisfied for \(2 <= n <= length(c(0, 1, 1, 2))\).

References

Pfister, R., Tonn, S., Schaaf, M., Wirth, R. (2024). mousetRajectory: Mouse tracking analyses for behavioral scientists. The Quantitative Methods for Psychology, 20(3), 217-229. doi:10.20982/tqmp.20.3.p217

Examples

direction_changes(c(0, 1, 1, 2))
#> [1] 0
direction_changes(c(0, 1, 1, 0))
#> [1] 1
direction_changes(c(0, 1, 0, 1))
#> [1] 2