Skip to contents

Determines peak offset using a hierarchical set of rules, evaluated in order until one succeeds:

  1. First valley after the peak returning to baseline + tolerance.

  2. First crossing below onset + tolerance.

  3. Fallback: two hours after onset.

Usage

find_offset(glucose, timestamps, peak_index, onset, baseline, tol)

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.

Value

A list with index, time, and value for the offset point, and method indicating which rule was used.