version <- as.vector(read.dcf("DESCRIPTION")[, "Version"]) version <- gsub("-", ".", version) dep <- as.vector(read.dcf("DESCRIPTION")[, "Depends"]) m <- regexpr("R *\\(>= \\d+.\\d+.\\d+\\)", dep) rm <- regmatches(dep, m) rvers <- gsub(".*(\\d+.\\d+.\\d+).*", "\\1", rm)
actigraph.sleepr
: Sleep and non-wear detection from ActiGraph dataknitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
The actigraph.sleepr
package implements three sleep scoring/detection algorithms: Sadeh [@Sadeh:1994aa], Cole-Kripke [@Cole:1992aa] and Tudor-Locke [@Tudor-Locke:2014aa] as well as two non-wear detection algorithms: Troiano [@Troiano:2008aa] and Choi [@Choi:2011aa].
# install.packages("remotes") remotes::install_github("dipetkov/actigraph.sleepr")
An AGD file is an SQLite database file exported by an ActiGraph device. See the ActiLife 6 User manual. For illustration let's use one day of sample data recorded by a GT3X+ monitor.
library("actigraph.sleepr") file_10s <- system.file("extdata", "GT3XPlus-RawData-Day01.agd", package = "actigraph.sleepr" ) agdb_10s <- read_agd(file_10s)
The read_agd
function loads the raw activity measurements into a convenient format: a tibble (data frame) of timestamped activity counts, whose attributes are the device settings. However, further manipulations of the tibble using the dplyr
verbs (e.g., mutate
, inner_join
) might drop these non-standard attributes, i.e., the attributes are not always inherited.
attributes(agdb_10s)[10:12]
Since the data is stored in a tibble, we can use the dplyr verbs (mutate, select, filter, summarise, group_by, arrange) to manipulate the data. For example, let's compute the vector magnitude of the three-axis counts (axis1 - vertical, axis2 - horizontal, axis3 - lateral).
suppressMessages(library("dplyr")) agdb_10s <- agdb_10s %>% select(timestamp, starts_with("axis")) agdb_10s %>% mutate(magnitude = sqrt(axis1^2 + axis2^2 + axis3^2))
The Sadeh and Cole-Kripke algorithms for converting activity measurements into asleep/awake indicators were developed for 60s epochs. If the data is in smaller epochs, we need to collapse or aggregate the epochs. The example data is in 10s epochs. So we aggregate the epochs from 10s to 60s by adding the counts for the six consecutive 10s epochs that fall into the same 60s epoch.
# Collapse epochs from 10 sec to 60 sec by summing agdb_60s <- agdb_10s %>% collapse_epochs(60) agdb_60s
The Sadeh algorithm is primarily used for younger adolescents as the supporting research was performed on children and young adults. It takes 60s epochs and uses an 11-minute window that includes the five previous and five future epochs. The apply_sadeh
function implements the algorithm as described in the ActiGraph user manual.
agdb_60s %>% apply_sadeh()
The Cole-Kripke algorithm is primarily used for adult populations as the supporting research was performed on subjects ranging from 35 to 65 years of age. Like the Sadeh algorithm, it takes 60s epochs and uses a 7-minute window that includes the four previous and two future epochs. The apply_cole
function implements the algorithm as described in the ActiGraph user manual.
agdb_60s %>% apply_cole_kripke()
Once each one-minute epoch is labeled as asleep (S) or awake (W), we can use the Tudor-Locke algorithm to detect periods of time in bed and, for each period, to compute sleep quality metrics such as total minutes in bed, total sleep time, number and average length of awakenings, movement and fragmentation index.
agdb_60s %>% apply_sadeh() %>% apply_tudor_locke()
Long stretches that consist almost entirely of zero counts (zero epochs) suggest that the device wasn't worn at all and therefore should be excluded from downstream analysis. The Troiano algorithm for detecting periods of non-wear formalizes a technique used to analyze the 2003-2004 NHANES data, which allows a non-wear period to contain a few nonzero epochs of artifactual movement (spikes). The Choi algorithm extends the Troiano algorithm by requiring that short spikes of artifactual movement during a non-wear period are preceded and followed by a fixed number of consecutive zero epochs.
agdb_60s %>% apply_troiano() agdb_60s %>% apply_choi()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.