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

View source: R/apply-tudor-locke-algo.R

apply_tudor_locke_algoR Documentation

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

Description

This function uses the Tudor-Locke algorithm (https://pubmed.ncbi.nlm.nih.gov/24383507) to classify an accelerometer axis vector of 60-second epochs as sleep time or awake time. This function was validated indirectly against output from the official SAS version of the Barreira algorithm (www.pbrc.edu/pdf/PBRCSleepEpisodeTimeMacroCode.pdf).

Usage

apply_tudor_locke_algo(
  x,
  time_stamp = "dataTimestamp",
  axis1 = "axis1",
  incline_off = "inclineOff",
  incline_standing = "inclineStanding",
  incline_sitting = "inclineSitting",
  incline_lying = "inclineLying",
  return = "everything"
)

Arguments

x

Required: a data frame of accelerometer data in 60-second epochs.

time_stamp

Required (default: "dataTimestamp"): a length-one character vector representing the name of the time stamp vector.

axis1

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

incline_off

Required (default: "inclineOff"): a length-one character vector representing the name of the corresponding vector in an ActiGraph .agd file.

incline_standing

Required (default: "inclineStanding"): a length-one character vector representing the name of the corresponding vector in an ActiGraph .agd file.

incline_sitting

Required (default: "inclineSitting"): a length-one character vector representing the name of the corresponding vector in an ActiGraph .agd file.

incline_lying

Required (default: "inclineLying"): a length-one character vector representing the name of the corresponding vector in an ActiGraph .agd file.

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 Tudor-Locke algorithm.

Value

Returns x along with all vectors that were derived while applying the Tudor-Locke algorithm.

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 Tudor-Locke sleep algorithm
dt <- apply_tudor_locke_algo(
  x = agd_data$data$clean |>
    dplyr::filter(
      epoch_length == 60,
      filter == "LowFrequencyExtension"
    )
)

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