regularity_index: Calculate regularity indices for analyzing time-of-day...

View source: R/regularity__generic.R

regularity_indexR Documentation

Calculate regularity indices for analyzing time-of-day consistency of recurring behaviors

Description

Calculate regularity indices for analyzing time-of-day consistency of recurring behaviors

Usage

regularity_index(values, timestamps, ...)

## S3 method for class 'factor'
regularity_index(values, timestamps, target, min_days = 3, numeric = TRUE, ...)

## S3 method for class 'numeric'
regularity_index(
  values,
  timestamps,
  n_bands,
  band_size,
  min_days = 3,
  numeric = TRUE,
  ...
)

Arguments

values

a vector of values to analyze

timestamps

a vector of POSIX-formatted timestamps. Must have the same length as values, and it must have element-wise, one-to-one correspondence with the elements of values

...

further arguments passed to methods

target

character scalar. When values is a factor, which level should be emphasized? All other levels will be collapsed into a single 'other' category.

min_days

the minimum number of days that are required to ensure proper analysis for each time of day. A warning will issue for any daytimes (i.e., epochs) that fall below this threshold.

numeric

logical. Return the score as a numeric object (default)? If FALSE, a regularity object will be returned instead.

n_bands

the number of difference bands that will be examined for a continuous input

band_size

the size of each difference band that will be examined for a continuous input

Details

When setting numeric = TRUE, only the numeric value is returned. Otherwise, a regularity object is returned, whose value equals the numeric value, and whose attributes include additional information from the analysis (potentially useful for debugging).

Value

A regularity index whose value lies between -100 and +100.

Examples

set.seed(1919)
values <- factor(
  sample(c("Awake", "Asleep"), 6, TRUE)
)
timestamp_offsets <- 43200 * 0:5
regularity_index(values, as.POSIXlt(Sys.Date()) + timestamp_offsets, min_days = 2)
regularity_index(values, as.POSIXlt(Sys.Date()) + timestamp_offsets, min_days = 2, numeric = FALSE)

paulhibbing/PBpatterns documentation built on Feb. 17, 2024, 5:34 a.m.