apply_sadeh_algo: Classify an accelerometer axis vector of 60-second epochs as...

View source: R/apply-sadeh-algo.R

apply_sadeh_algoR Documentation

Classify an accelerometer axis vector of 60-second epochs as sleep time or awake time.

Description

This function uses the Sadeh algorithm (https://pubmed.ncbi.nlm.nih.gov/7939118) to classify an accelerometer axis vector of 60-second epochs as sleep time or awake time.

Usage

apply_sadeh_algo(
  x,
  axis1 = "axis1",
  censor_counts = FALSE,
  return = "everything"
)

Arguments

x

Required: a data frame of accelerometer data.

axis1

Required default ("axis1"): a length-one character vector representing the name of the vertical axis.

censor_counts

Optional (default: FALSE): a length-one logical vector representing whether to censor accelerometer counts to a maximum of 300 before applying the Sadeh algorithm.

return

Required (default: "everything"): a character vector representing which vectors to return. If set to "everything", the data frame in x will be returned along with all vectors that were derived while applying the Sadeh algorithm.

Value

Returns x along with all vectors that were derived while applying the Sadeh algorithm. Note: values in the sadeh_sleep_score vector that are greater than -4 are interpreted as sleep time (see https://actigraphcorp.my.site.com/support/s/article/Where-can-I-find-documentation-for-the-Sadeh-and-Cole-Kripke-algorithms). # nolint: line_length_linter.

Examples

# Initialize agd_worker R6 class
agd_data <- agd_worker$new(
  id = "jane-canuck",
  age = 10,
  agd_lfe = system.file("extdata", "jane-canuck-lfe.agd", package = "chms"),
  agd_nml = system.file("extdata", "jane-canuck-nml.agd", package = "chms"),
  epoch_length = 15,
  day_max = 3,
  sleep_algo = "barreira",
  non_wear_algo = "barreira"
)

# Load and clean data
agd_data$load()$clean()

# Apply Sadeh sleep algorithm
dt <- apply_sadeh_algo(
  x = agd_data$data$clean |>
    dplyr::filter(
      epoch_length == 60,
      filter == "LowFrequencyExtension"
    )
)

chms documentation built on Oct. 17, 2026, 5:07 p.m.