% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/scores_nt_fitbit.R
\name{compute_sleep_ranges_waso}
\alias{compute_sleep_ranges_waso}
\title{Compute sleep timing and WASO Metrics from Epoch-Level Data}
\usage{
compute_sleep_ranges_waso(sleep_offset, bin_minutes)
}
\arguments{
\item{sleep_offset}{tbl. Sleep epoch-level dataset containing at minimum:
\code{participant_id}, \code{session_id}, \code{sleep_date}, \code{dtt}, \code{stage},
\code{hrate_excluded}, and \code{main_slp}.}

\item{bin_minutes}{numeric. Number of minutes to bin data by.}
}
\value{
tbl. A participant-night level summary containing:
\itemize{
\item \code{dtt_start_slp}: First detected sleep epoch (light/deep/rem/asleep).
\item \code{dtt_end_slp}: End of sleep period (last awake onset or end of bed).
\item \code{dtt_start_bed}: Start of recording interval for the sleep period.
\item \code{dtt_end_bed}: End of recording interval for the sleep period.
\item \code{n_waso}: Number of wake-after-sleep-onset (WASO) episodes.
\item \code{min_waso}: Total WASO duration (in minutes, 30-sec epoch units).
}
}
\description{
Computes sleep onset, sleep offset, and WASO (wake after sleep onset) metrics
from 30-second sleep epoch data.

This function summarizes nightly sleep timing and wake fragmentation by
identifying transitions in sleep stages and calculating
wake-after-sleep-onset characteristics.
}
\details{
Sleep stages labeled as \code{"awake"} or \code{"wake"} are treated as wake periods.
Missing stages are also recoded as \code{"awake"} to ensure consistency in
wake detection. Wake episodes at the beginning and end of the sleep window
are excluded from WASO calculations.
}
\note{
input data should be output of \code{join_sleep30_and_exclusion()}. Input
data must be in 30-second epochs. \code{min_wake} includes minutes with stage of
"wake", "awake", "unknown", or NA  (for activity minutes that become sleep
under extended framework).
\itemize{
\item data input: sleep epoch-level data with sleep stage and exclusion flags
}
}
\keyword{internal}
