csd: Cumulative sleep debt.

Description Usage Arguments Details Value Examples

View source: R/csd.r

Description

Cumulative sleep debt.

Usage

1
csd(x, baseline_sleep, reset = 2, plot = TRUE, ylabel, ...)

Arguments

x

a report period. See report_period().

baseline_sleep

a data frame containing the normal sleep duration or baseline by participant.

reset

consecutive number of sleep periods that will set as zero the cumulative sleep debt when the total sleep in 24h is greater than the baseline_sleep. It does not depend on the exceeding duration or credit.

plot

a logical variable. By default is TRUE.

ylabel

label of the y-axis

...

optional parameters

Details

if no reset is desired just set a large value e.g. 1E3. Three cumsum values are computed: cumsum, cumsum_reset and cumsum_actual. The last one allows the deficiency to be in credit (positive values).

Value

a data frame and optionally a graph. def is the daily sleep deficiency.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Example 1
library(lubridate)
data(act)
act$datime_start <- ymd_hms(act$datime_start)
act$datime_end <- ymd_hms(act$datime_end)

par <- data.frame(subject_ID = 1,
summary_duration_h = 24,
summary_type = "sequential",
summary_start_datime = ymd_hms("2017-12-05 00:00:00 UTC"),
summary_end_datime = ymd_hms("2017-12-15 00:00:00 UTC"))

rep <- report_period(period = par , acti_data = act)

start_date <- act[act$subject_ID==1 & act$interval_type == "FLIGHT" &
act$comments == "SIN-AMS",]$datime_end
sel <- act[act$datime_start >= start_date & act$datime_end <=
start_date + days(10),]

par_afterflight <- data.frame(subject_ID = 1,
summary_duration_h = 24,
summary_type = "sequential",
summary_start_datime = round.POSIXt(start_date, "day"),
summary_end_datime = round.POSIXt(start_date, "day") + days(10))
rep_afterflight <- report_period(period = par_afterflight , acti_data = sel)
baseline <- data.frame(subject_ID = 1, baseline_sleep = mean(rep$total_sleep))
reset <- 2
z <- csd(x = rep_afterflight, baseline_sleep = baseline, reset = 2)
z[[2]]
plot(z[[1]])
# Example 2 with no reset by adding large reset value
csd(x = rep_afterflight, baseline_sleep = baseline, reset = 1E5)

ActisoftR documentation built on Oct. 16, 2018, 5:04 p.m.