Derives standard sleep architecture summary statistics from a staged
hypnogram. All metrics are resolution-agnostic: the function computes
every metric that is possible given the available staging levels and
returns NA for metrics that require stages not present at the detected
resolution (e.g. REM/SWS latency and AASM stage percentages require a
full AASM hypnogram).
Arguments
- hypnogram
A
hypnor_hypnogramobject as returned bynew_hypnogram()orread_hypnogram(), or any data frame with at minimumepochandstagecolumns – it will be passed throughnew_hypnogram()automatically if not already ahypnor_hypnogram. Epoch duration and staging resolution are read from the object'sepoch_secandresolutionattributes.- lights_off, lights_on
Optional
POSIXcttimestamps for lights-off and lights-on. When both are supplied,hypnogramis first restricted to this window viawindow_hypnogram()– every metric (TST,SOL,WASO, stage percentages, everything) is computed relative to the window, not justTIB/SE. OtherwiseTIBdefaults to the full span ofhypnogramas passed in (first to last epoch).
Value
A one-row tibble with columns:
- tst_min
Total sleep time (minutes).
- tib_min
Time in bed (minutes).
- se_pct
Sleep efficiency (percent) = TST / TIB * 100.
- sol_min
Sleep onset latency (minutes).
NAif no sleep epoch is present.- waso_min
Wake after sleep onset (minutes): wake epochs between the first and last sleep epoch.
NAif no sleep epoch is present.- rem_lat_min
REM latency from sleep onset (minutes).
NAfor coarse hypnograms or if no REM epoch is present.- sws_lat_min
SWS (N3) latency from sleep onset (minutes).
NAfor coarse hypnograms or if no N3 epoch is present.- pct_n1,pct_n2,pct_n3,pct_rem
Stage percentages of TST.
NAfor coarse hypnograms.- pct_sleep,pct_quiet_sleep
Stage percentages of TST for coarse hypnograms.
NAfor full AASM hypnograms.- staging_resolution
"aasm"or"coarse".
Details
Sleep onset is defined as the first epoch with any non-"W" stage –
this applies uniformly to full AASM hypnograms (where N1 counts as
sleep onset) and coarse hypnograms (where "Sleep" or "Quiet sleep"
both count).
Examples
if (FALSE) { # \dontrun{
hyp <- read_hypnogram("night_001.csv")
compute_sleep_architecture(hyp)
} # }