Title: | Sleep Duration Estimate Algorithm |
---|---|
Description: | Provides sleep duration estimates using a Pruned Dynamic Programming (PDP) algorithm that efficiently identifies change-points. PDP applied to physical activity data can identify transitions from wakefulness to sleep and vice versa. Baek, Jonggyu, Banker, Margaret, Jansen, Erica C., She, Xichen, Peterson, Karen E., Pitchford, E. Andrew, Song, Peter X. K. (2021) An Efficient Segmentation Algorithm to Estimate Sleep Duration from Actigraphy Data <doi:10.1007/s12561-021-09309-3>. |
Authors: | Jonggyu Baek [aut], Margaret Banker [aut], Nathan Szeto [aut, cre], Alice Cleynen [aut], Guillem Rigaill [aut], Michel Koskas [aut] |
Maintainer: | Nathan Szeto <[email protected]> |
License: | GPL-3 |
Version: | 0.2.2 |
Built: | 2025-03-03 05:34:28 UTC |
Source: | https://github.com/cran/ActiSleep |
A dataset containing accelerometry data for a single subject in 1-minute epochs, includes vector magnitude and other measurements.
date: Time and date of a single measurement.
axis1: X-axis movement.
axis2: Y-axis movement.
axis3: Z-axis movement.
steps: Steps taken by the subject.
lux: Amount of light present, measured in lux.
inclineOff: Incline off.
inclineStanding: Incline standing.
inclineSitting: Incline sitting.
inclineLying: Incline lying.
VM: Vector magnitude, calculated from x-, y-, and z-axis measurements.
data("AccelData")
data("AccelData")
A data frame with 1351 rows and 11 variables.
Obtain table from raw accelerometer table in 1-min intervals
aggregate_dat(datain, cutnum = 1, unit = c("min", "sec"), tz = "GMT")
aggregate_dat(datain, cutnum = 1, unit = c("min", "sec"), tz = "GMT")
datain |
raw ActiGraph GT3X data |
cutnum |
quantity of unit to serve as interval, default is 1 |
unit |
time unit to use |
tz |
timezone, default is GMT |
data frame of accelerometer data aggregated by intervals
Calculate the mean index of a segment
cal_mean_idx(i, datain, idx_start, idx_end)
cal_mean_idx(i, datain, idx_start, idx_end)
i |
segment index |
datain |
activity data, must be a data frame |
idx_start |
array of segment start indices |
idx_end |
array of segment end indices |
mean value of segment indices
Reformat the time variable to match analysis-ready format
ChangeTimeVar(datain, col_idx, format = "%Y-%m-%d %H:%M:%S")
ChangeTimeVar(datain, col_idx, format = "%Y-%m-%d %H:%M:%S")
datain |
input dataset, must be a data frame |
col_idx |
index of column to convert to date object |
format |
format of input date data, default is YYYY-MM-DD HH:MM:SS |
dataframe with formatted time values
data("SleepDiary1Week") ChangeTimeVar( SleepDiary1Week, col_idx = c(5:18), format = "%Y-%m-%d %H:%M:%S")
data("SleepDiary1Week") ChangeTimeVar( SleepDiary1Week, col_idx = c(5:18), format = "%Y-%m-%d %H:%M:%S")
Obtain table of in-bed and out-bed times from sleep diary data
GetDiary_subj(datain, subj_idx, idx_bed, idx_wake, tz = "GMT")
GetDiary_subj(datain, subj_idx, idx_bed, idx_wake, tz = "GMT")
datain |
input dataset, must be a data frame |
subj_idx |
index indicating subject |
idx_bed |
array specifying indices for in-bed time data |
idx_wake |
array specifying indices for out-bed time data |
tz |
timezone, default is GMT |
dataframe with in-bed and out-bed times
data("SleepDiary1Week") SleepDiary1Week <- ChangeTimeVar(SleepDiary1Week, c(5:18), format = "%m/%d/%Y %H:%M") colIdx_diary_bed <- c(1:7) * 2 - 2 + 5 colIdx_diary_wake <- c(1:7) * 2 - 1 + 5 GetDiary_subj( SleepDiary1Week, 1, colIdx_diary_bed, colIdx_diary_wake, tz = "GMT")
data("SleepDiary1Week") SleepDiary1Week <- ChangeTimeVar(SleepDiary1Week, c(5:18), format = "%m/%d/%Y %H:%M") colIdx_diary_bed <- c(1:7) * 2 - 2 + 5 colIdx_diary_wake <- c(1:7) * 2 - 1 + 5 GetDiary_subj( SleepDiary1Week, 1, colIdx_diary_bed, colIdx_diary_wake, tz = "GMT")
Obtain in-bed and out-bed times from diary data
GetEstSleepInterval_subj( datain, bed = "22:00:00", wake = "8:00:00", tz = "GMT" )
GetEstSleepInterval_subj( datain, bed = "22:00:00", wake = "8:00:00", tz = "GMT" )
datain |
diary data |
bed |
default in-bed time |
wake |
default out-bed time |
tz |
timezone, default is GMT |
data frame containing in-bed and out-bed times based on sleep diary
Obtain a list of AGD filenames and data
read_agd(file, tz = "GMT", sec = 10)
read_agd(file, tz = "GMT", sec = 10)
file |
AGD data file |
tz |
timezone, default is GMT |
sec |
time interval used to set date |
list of AGD filenames and data
Obtain specific sleep segment based on day, indices, etc.
SearchSleepSeg( date, Y, idx_start, idx_end, NoPA_cut = 0.7, sleep_mins = 30, SI_i, tz = "GMT" )
SearchSleepSeg( date, Y, idx_start, idx_end, NoPA_cut = 0.7, sleep_mins = 30, SI_i, tz = "GMT" )
date |
date of interest |
Y |
vector containing validated sleep counts |
idx_start |
start index of sleep segment |
idx_end |
end index of sleep segment |
NoPA_cut |
percent of 0 counts to define NoPA segments |
sleep_mins |
threshold number of minutes to define sleep segment |
SI_i |
estimated sleep intervals based on sleep diary data |
tz |
timezone, default is GMT |
list of validated sleep segments
This code was written by Alice Cleynen, Guillem Rigaill, and Michel Koskas as part of the Segmentor3IsBack package, which is no longer in CRAN. It has been imported into the ActiSleep package to ensure this package's longevity.
A small dataset containing sleep diary data for a single day and single subject
bed. time at which the subject reported going to sleep on day 1
wake. time at which the subject reported waking up on day 1
data("SleepDiary1Day")
data("SleepDiary1Day")
a data frame with 1 row and 2 variables
A small dataset containing sleep diary data for a single week and single subject
FOLIOCC. unique subject id
etapa.
stage.
start_day. first day of measurement
time_bed1. time at which the subject reported going to sleep on day 1
time_wake1. time at which the subject reported waking up on day 1
time_bed2. time at which the subject reported going to sleep on day 2
time_wake2. time at which the subject reported waking up on day 2
time_bed3. time at which the subject reported going to sleep on day 3
time_wake3. time at which the subject reported waking up on day 3
time_bed4. time at which the subject reported going to sleep on day 4
time_wake4. time at which the subject reported waking up on day 4
time_bed5. time at which the subject reported going to sleep on day 5
time_wake5. time at which the subject reported waking up on day 5
time_bed6. time at which the subject reported going to sleep on day 6
time_wake6. time at which the subject reported waking up on day 6
time_bed7. time at which the subject reported going to sleep on day 7
time_wake7. time at which the subject reported waking up on day 7
data("SleepDiary1Week")
data("SleepDiary1Week")
a data frame with 1 row and 18 variables
Obtain sleep data from accelerometer data
SleepEstEachDay( datain, f = 1, id = NA, Y_name = "max_count", T = 0.4, nonwear_detect = FALSE, wear_mins = 120, S = 3, NoPA_cut = 0.7, sleep_mins = 20, wake_mins = 180, nap_mins = 20, UseDiary = FALSE, diary_data = c(), CommonBedTime = "22:00:00", CommonWakeTime = "8:00:00", tz = "GMT" )
SleepEstEachDay( datain, f = 1, id = NA, Y_name = "max_count", T = 0.4, nonwear_detect = FALSE, wear_mins = 120, S = 3, NoPA_cut = 0.7, sleep_mins = 20, wake_mins = 180, nap_mins = 20, UseDiary = FALSE, diary_data = c(), CommonBedTime = "22:00:00", CommonWakeTime = "8:00:00", tz = "GMT" )
datain |
input accelerometry dataset, must be tibble, data frame, etc. |
f |
cost function indicator |
id |
subject id |
Y_name |
column name of the activity count data to be used in analysis, for example max count of x, y, z axes or vector magnitude |
T |
threshold percentile of activity level |
nonwear_detect |
flag indicating use of nonwear detection algorithm, default is FALSE |
wear_mins |
threshold number of minutes to define wear segment |
S |
number of segments per hour |
NoPA_cut |
percent of 0 counts to define NoPA segments |
sleep_mins |
threshold number of minutes to define sleep segment |
wake_mins |
threshold number of minutes to define wake segment |
nap_mins |
threshold number of minutes to define nap segment |
UseDiary |
flag indicating if diary data to be used, default is FALSE |
diary_data |
diary data, must be a data frame |
CommonBedTime |
in-bed time if no diary data, default is "22:00:00" |
CommonWakeTime |
out-bed time if no diary data, default is "8:00:00" |
tz |
timezone, default is GMT |
list containing a data frame of summary sleep data
data("AccelData") AccelData <- ChangeTimeVar(AccelData, col_idx = 1, format = "%m/%d/%Y %H:%M") SleepEstEachDay(AccelData, Y_name = "VM") data("AccelData") AccelData <- ChangeTimeVar(AccelData, col_idx = 1, format = "%m/%d/%Y %H:%M") SleepEstEachDay(AccelData, Y_name = "VM", nonwear_detect = TRUE) data("AccelData") data("SleepDiary1Day") SleepDiary1Day <- ChangeTimeVar( SleepDiary1Day, col_idx = c(1,2), format = "%m/%d/%Y %H:%M") AccelData <- ChangeTimeVar(AccelData, col_idx = 1, format = "%m/%d/%Y %H:%M") SleepEstEachDay( AccelData, f = 2, Y_name = "VM", T = 0, nonwear_detect = TRUE, S = 2, NoPA_cut = 0.45, sleep_mins = 5, UseDiary = TRUE, diary_data = SleepDiary1Day )
data("AccelData") AccelData <- ChangeTimeVar(AccelData, col_idx = 1, format = "%m/%d/%Y %H:%M") SleepEstEachDay(AccelData, Y_name = "VM") data("AccelData") AccelData <- ChangeTimeVar(AccelData, col_idx = 1, format = "%m/%d/%Y %H:%M") SleepEstEachDay(AccelData, Y_name = "VM", nonwear_detect = TRUE) data("AccelData") data("SleepDiary1Day") SleepDiary1Day <- ChangeTimeVar( SleepDiary1Day, col_idx = c(1,2), format = "%m/%d/%Y %H:%M") AccelData <- ChangeTimeVar(AccelData, col_idx = 1, format = "%m/%d/%Y %H:%M") SleepEstEachDay( AccelData, f = 2, Y_name = "VM", T = 0, nonwear_detect = TRUE, S = 2, NoPA_cut = 0.45, sleep_mins = 5, UseDiary = TRUE, diary_data = SleepDiary1Day )