Package 'ActiSleep'

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

Help Index


Accelerometry Data

Description

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.

Usage

data("AccelData")

Format

A data frame with 1351 rows and 11 variables.


Aggregate Accelerometer Data

Description

Obtain table from raw accelerometer table in 1-min intervals

Usage

aggregate_dat(datain, cutnum = 1, unit = c("min", "sec"), tz = "GMT")

Arguments

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

Value

data frame of accelerometer data aggregated by intervals


Calculate Mean Index

Description

Calculate the mean index of a segment

Usage

cal_mean_idx(i, datain, idx_start, idx_end)

Arguments

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

Value

mean value of segment indices


Reformat Time Variable

Description

Reformat the time variable to match analysis-ready format

Usage

ChangeTimeVar(datain, col_idx, format = "%Y-%m-%d %H:%M:%S")

Arguments

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

Value

dataframe with formatted time values

Examples

data("SleepDiary1Week")

ChangeTimeVar(
SleepDiary1Week,
col_idx = c(5:18),
format = "%Y-%m-%d %H:%M:%S")

Diary In/Out-bed Times

Description

Obtain table of in-bed and out-bed times from sleep diary data

Usage

GetDiary_subj(datain, subj_idx, idx_bed, idx_wake, tz = "GMT")

Arguments

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

Value

dataframe with in-bed and out-bed times

Examples

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")

Estimated sleep interval

Description

Obtain in-bed and out-bed times from diary data

Usage

GetEstSleepInterval_subj(
  datain,
  bed = "22:00:00",
  wake = "8:00:00",
  tz = "GMT"
)

Arguments

datain

diary data

bed

default in-bed time

wake

default out-bed time

tz

timezone, default is GMT

Value

data frame containing in-bed and out-bed times based on sleep diary


Read in AGD filedata

Description

Obtain a list of AGD filenames and data

Usage

read_agd(file, tz = "GMT", sec = 10)

Arguments

file

AGD data file

tz

timezone, default is GMT

sec

time interval used to set date

Value

list of AGD filenames and data


Find specific sleep segment

Description

Obtain specific sleep segment based on day, indices, etc.

Usage

SearchSleepSeg(
  date,
  Y,
  idx_start,
  idx_end,
  NoPA_cut = 0.7,
  sleep_mins = 30,
  SI_i,
  tz = "GMT"
)

Arguments

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

Value

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.

Description

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.


Sleep Diary 1-Day Data

Description

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

Usage

data("SleepDiary1Day")

Format

a data frame with 1 row and 2 variables


Sleep Diary 1-Week Data

Description

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

Usage

data("SleepDiary1Week")

Format

a data frame with 1 row and 18 variables


Daily sleep estimate

Description

Obtain sleep data from accelerometer data

Usage

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"
)

Arguments

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

Value

list containing a data frame of summary sleep data

Examples

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
)