Skip to contents

Rotate a numeric vector (for rotation_test, this will be a set of event times). "Rotating" the vector entails advancing all values by a random increment, then subtracting the maximum expected value from all rotated entries that exceed that maximum. This is a utility function used by rotation_test, but advanced users may wish to use it directly to carry out non-standard rotation tests.

Usage

rotate_data(event_times, full_period)

Arguments

event_times

A vector of the times of events. Times can be given in any format. If event_times should not be sorted prior to analysis (for example, if times are given in hours of the day and the times in the dataset span several days), be sure to specify skip_sort=TRUE.

full_period

A length two vector giving the start and end times of the full period during which events in event_times might have occurred. If missing, default is range(event_times).

Value

A vector of numeric values the same length as event_times generated by rotating the event times by a random amount

Details

The rotation test was applied in Miller et al. 2004 and detailed in DeRuiter and Solow 2008. This test is a variation on standard randomization or permutation tests that is appropriate for time-series of non-independent events (for example, time series of behavioral events that tend to occur in clusters). This implementation of the rotation test compares a test statistic (some summary of an "experimental" time-period) to its expected value during non-experimental periods. Instead of resampling random subsets of observations from the original dataset, the rotation test samples many contiguous blocks from the original data, each the same duration as the experimental period. The summary statistic, computed for these "rotated" samples, provides a distribution to which the test statistic from the data can be compared.

Examples

my_events <- 1500 * stats::runif(10) # 10 events at "times" between 0 and 1500
my_events
#>  [1]  121.12521 1251.49956  901.14133  235.81266   11.09916  699.59025
#>  [7]  746.66608  434.65087 1099.32298 1158.78227
rotated_events <- rotate_data(my_events, full_period = c(0, 1500))
rotated_events
#>  [1]   47.71365  246.55186  511.49124  558.56707  713.04232  911.22397
#>  [7]  970.68326 1063.40055 1323.00015 1433.02620