apply_general_bout_algo: Classify an accelerometer axis vector of epochs based on a...

View source: R/apply-general-bout-algo.R

apply_general_bout_algoR Documentation

Classify an accelerometer axis vector of epochs based on a set of bout rules.

Description

This function uses a general algorithm to classify an accelerometer axis vector of of epochs based on a set of bout rules.

Usage

apply_general_bout_algo(
  x,
  axis1 = "axis1",
  is_wearing = "is_wearing",
  min_bout_length = 10,
  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").

is_wearing

Required: a character vector of "Yes" and "No" values representing wear time and non-wear time respectively (default: "is_wearing"). See apply_non_wear_algo() for more details.

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 is 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, clean and classify data
agd_data$load()$clean()$classify()

# Look for 10+ minute bouts of moderate-intensity physical activity
dt <- apply_general_bout_algo(
  x = agd_data$data$classify,
  min_bout_length = 10 * (60 / agd_data$args$movement_epoch_length),
  target_values = 574:1002,
  max_exceptions = 2 * (60 / agd_data$args$movement_epoch_length),
  return = c("dataTimestamp", "axis1", "in_bout")
)

# Get bout lengths
rle(dt$in_bout)

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