combine_epochs_periods: Combine epochs with sleep/nonwear periods

View source: R/combine_epochs_periods.R

combine_epochs_periodsR Documentation

Combine epochs with sleep/nonwear periods

Description

Suppose we have used apply_tudor_locke() to detect sleep periods or apply_troiano()/apply_choi() to detect non-wear periods. It might be useful to combine the epochs data with the periods data, so that each epoch is labeled according to which period it falls into, if any. Then we can easily slice the epochs data by sleep/non-sleep or wear/non-wear.

Usage

combine_epochs_periods(epochs, periods, start_var, end_var)

Arguments

epochs

A tibble of activity data with a timestamp column.

periods

A summary tibble of the (sleep or non-wear) periods.

start_var

The periods column which specifies when the periods start.

end_var

The periods column which specifies when the periods end.

Value

A tibble of activity data with one additional column, period_id, which indicates the period each epoch falls into.

Examples

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

agdb <- gtxplus1day %>%
  collapse_epochs(60) %>%
  apply_sadeh()
periods <- agdb %>%
  apply_tudor_locke(min_sleep_period = 60)

agdb_with_periods <- combine_epochs_periods(
  agdb, periods,
  in_bed_time, out_bed_time
)

# How many sleep periods were detected and what is their duration,
# in minutes?
periods %>% select(in_bed_time, out_bed_time, duration)
# What is the assignment of epochs to periods?
agdb_with_periods %>% count(period_id)

dipetkov/actigraph.sleepr documentation built on March 25, 2022, 2:33 a.m.