combine_epochs_periods: Combine epochs with sleep/nonwear periods

Description Usage Arguments Value Examples

View source: R/combine_epochs_periods.R

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

1
combine_epochs_periods(epochs, periods, start_var, end_var)

Arguments

epochs

A tibble (tbl) of activity data with (at least) 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
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)

oslerinhealth/actigraph.sleepr documentation built on May 25, 2021, 1:06 p.m.