apply_oakley: Apply the Oakley algorithm

View source: R/apply_oakley.R

apply_oakleyR Documentation

Apply the Oakley algorithm

Description

The Oakley sleep scoring algorithm classifies each epoch as asleep or awake from wrist activity counts. It was developed for the Actiwatch activity monitoring system.

Usage

apply_oakley(agdb, threshold = 40)

Arguments

agdb

A tibble of activity data. Its epoch length must be 15, 30, 60, or 120 seconds.

threshold

Numeric wake threshold, or "automatic". An epoch is scored as awake when its weighted activity score is greater than the threshold. The default is 40.

Details

Oakley's weighted activity score is the sum of activity counts in a window centred on the epoch, multiplied by epoch-length-specific weights. For 60-second data, the score at epoch t is

0.04 * count[t - 2] + 0.20 * count[t - 1] + count[t] +
  0.20 * count[t + 1] + 0.04 * count[t + 2]

The method uses the axis1 count directly. The weights for 15-, 30-, and 120-second epochs are those specified in the Actiwatch software manual. Counts outside the observed series are treated as zero when scoring the first and last epochs.

With threshold = "automatic", the wake threshold is calculated separately for each group as 0.88888 * sum(count) / mobile_time_minutes. An epoch is mobile when its count is at least the number of 15-second intervals in that epoch. mobile_time_minutes is the number of mobile epochs multiplied by the epoch length in minutes.

Value

A tibble of activity data. A new column sleep indicates whether each epoch is scored as asleep ("S") or awake ("W").

References

Oakley NR. Validation with Polysomnography of the Sleepwatch Sleep/Wake Scoring Algorithm Used by the Actiwatch Activity Monitoring System. Technical Report. Mini-Mitter; 1997.

Actiwatch Communication and Sleep Analysis Software instruction manual. Respironics, Inc. Available at https://fccid.io/JIAAWR1/Users-Manual/USERS-MANUAL-1-920937.

The implementation and weights were cross-checked against the pyActigraphy Oakley documentation. Its source implementation was also consulted.

See Also

apply_sadeh(), apply_cole_kripke()

Examples

library("dplyr")
data("gtxplus1day")

gtxplus1day %>%
  collapse_epochs(60) %>%
  apply_oakley()

actigraph.sleepr documentation built on Sept. 12, 2026, 5:08 p.m.