Computes episode-based daily sleep summary measures.
Source:R/scores_nt_fitbit.R
compute_fitbit_sleep_table_ext.RdThis function extends the standard sleep pipeline by grouping 30-second sleep epochs into continuous sleep blocks based on a configurable gap threshold, and redefining main sleep periods based on block duration. Heart rate exclusion logic is applied both prior to and after block construction to ensure consistency across raw and reconstructed sleep structures.
Usage
compute_fitbit_sleep_table_ext(
data_activity,
data_sleep_combined,
data_daily,
hr_low = 50,
hr_high = NULL,
hr_rep_day = 10,
hr_rep_sleep = 30,
bin_minutes = NULL,
offset = "12:00",
min_slp_minutes,
main_duration = 180,
gap = 90
)Arguments
- data_activity
tbl. Epoch-level activity data used to derive heart rate exclusion flags.
- data_sleep_combined
tbl. 30-second sleep epoch data containing sleep stage and timestamp information.
- data_daily
tbl. Daily Fitbit summary data including resting heart rate.
- hr_low
numeric. Lower threshold for valid heart rate values.
- hr_high
numeric or NULL. Optional upper threshold for valid heart rate values.
- hr_rep_day
numeric. Threshold (number of epochs) for repeated heart rate detection in daytime activity.
- hr_rep_sleep
numeric. Threshold (number of epochs) for repeated heart rate detection in sleep.
- bin_minutes
numeric. Number of minutes used to bin data.
- offset
character. Time-of-day cutoff used to define sleep-day boundaries.
- min_slp_minutes
numeric. Minimum number of sleep minutes required for a day to pass quality control. Used to create a
qc_Xminflag column in the output.- main_duration
numeric. Minumum duration in minutes for a sleep episode to be qualify as a main sleep episode.
- gap
numeric. Maximum allowed gap (in minutes) between consecutive sleep epochs before a new sleep episode is defined.
Value
tbl. A daily-level extended sleep summary table containing:
Identifiers and time variables:
participant_id,session_idwk: Study week indexday: Study day indexdt: Sleep-aligned datedt_day: Day of weekdt_wknd: Weekend indicator
Sleep timing and block structure:
dtt_start_bed,dtt_end_beddtt_start_slp,dtt_end_slp
Sleep duration metrics:
min_total_slp,min_asleep_slp,min_restless_slp,min_light_slp,min_deep_slp,min_rem_slp,min_nap_slpmin_waso,min_wake,n_waso
Heart rate summaries by sleep stage:
hrate_awake_slp,hrate_restless_slp,hrate_asleep_slphrate_light_slp,hrate_deep_slp,hrate_rem_slphrate_nap_slp,hrate_rest_fitb
Heart rate exclusion metrics:
excl_min_total_slp,excl_min_lowhrate_slpexcl_min_nohrate_slp,excl_min_highhrate_slpexcl_min_repeathrate_slp,min_extra_nohrate_slp
Quality control flags:
qc_300min: Indicator for >= 300 minutes of sleepflg_slp: Flag for implausible sleep structureflg_any: Indicator for any valid sleep data