apply_non_wear_algo: Classify an accelerometer axis vector of epochs as wear time...

View source: R/apply-non-wear-algo.R

apply_non_wear_algoR Documentation

Classify an accelerometer axis vector of epochs as wear time or non-wear time based on a set of bout rules.

Description

This function uses a general algorithm to classify an accelerometer axis vector of epochs as wear time or non-wear time based on a set of bout rules

Usage

apply_non_wear_algo(
  x,
  axis1 = "axis1",
  min_bout_length = 90,
  target_values,
  max_exceptions = 2,
  return = "everything"
)

Arguments

x

Required: a data frame of accelerometer data.

axis1

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

min_bout_length

Required: a length-one numeric vector representing the minimum number of epochs in a bout (default: 10).

target_values

Required: a numeric vector representing the epoch value(s) that belong to a bout.

max_exceptions

Required: a length-one numeric vector representing the maximum number of epochs permitted within a bout that outside the range of the values in the target_values argument (default: 2).

return

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

Value

Returns the data frame in the x argument along with all vectors that were derived while applying the bout 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 Barreira sleep algorithm
dt <- apply_barreira_algo(
  x = agd_data$data$clean |>
    dplyr::filter(
      epoch_length == 60,
      filter == "LowFrequencyExtension"
    ),
  age = agd_data$args$age
)

# Apply general non-wear algorithm
dt <- apply_non_wear_algo(
  x = dt,
  min_bout_length = 60,
  target_values = 0,
  max_exceptions = 2,
  return = c("is_wearing", "is_sleeping", "ymd_hm")
)

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