Determines peak offset using a hierarchical set of rules, evaluated in order until one succeeds:
First valley after the peak returning to baseline + tolerance.
First crossing below onset + tolerance.
Fallback: two hours after onset.
Arguments
- glucose
Numeric vector, smoothed glucose trace.
- timestamps
POSIXct vector, same length as
glucose.- peak_index
Integer, index of the selected peak within
glucose.- onset
A list as returned by
find_onset().- baseline
Numeric scalar, corrected baseline.
- tol
Numeric scalar, tolerance (mg/dL) used in the return-to-baseline and onset-crossing checks.