find_min_before_hours: Find Minimum Glucose Before Specified Hours

View source: R/function_overrides.R View source: R/RcppExports.R

find_min_before_hoursR Documentation

Find Minimum Glucose Before Specified Hours

Description

Identifies the minimum glucose value occurring within a specified time window before a given start point. This function is useful for analyzing glucose patterns preceding specific events or time points.

Usage

find_min_before_hours(df, start_point_df, hours)

Arguments

df

A dataframe containing continuous glucose monitoring (CGM) data. Must include columns:

  • id: Subject identifier (string or factor)

  • time: Time of measurement (POSIXct)

  • gl: Glucose value (integer or numeric, mg/dL)

start_point_df

A dataframe with column start_indices (R-based indices into df)

hours

Number of hours to look back from the start point

Value

A list containing:

  • min_indices: Tibble with R-based (1-indexed) row numbers of minimum glucose (min_indices). The corresponding occurrence time is df$time[min_indices] and glucose is df$gl[min_indices].

  • episode_counts: Tibble with episode counts per subject (id, episode_counts)

  • episode_start: Tibble with all episode starts with columns:

    • id: Subject identifier

    • time: Timestamp at which the minimum occurs; equivalent to df$time[indices]

    • gl: Glucose value at the minimum; equivalent to df$gl[indices]

    • indices: R-based (1-indexed) row number(s) in df denoting where the minimum occurs

See Also

mod_grid, find_local_maxima

Other GRID pipeline: detect_between_maxima(), find_local_maxima(), find_max_after_hours(), find_max_before_hours(), find_min_after_hours(), find_new_maxima(), grid(), maxima_grid(), mod_grid(), start_finder(), transform_df()

Examples

# Load sample data
library(iglu)
data(example_data_5_subject)
data(example_data_hall)

# Create start points for demonstration (using row indices)
start_indices <- seq(1, nrow(example_data_5_subject), by = 100)
start_points <- data.frame(start_indices = start_indices)

# Find minimum glucose in previous 2 hours
min_before <- find_min_before_hours(example_data_5_subject, start_points, hours = 2)
print(paste("Found", length(min_before$min_indices), "minimum points"))

# Find minimum glucose in previous 1 hour
min_before_1h <- find_min_before_hours(example_data_5_subject, start_points, hours = 1)

# Analysis on larger dataset
large_start_indices <- seq(1, nrow(example_data_hall), by = 200)
large_start_points <- data.frame(start_indices = large_start_indices)
large_min_before <- find_min_before_hours(example_data_hall, large_start_points, hours = 2)
print(paste("Found", length(large_min_before$min_indices), "minimum points in larger dataset"))

cgmguru documentation built on Nov. 6, 2025, 1:07 a.m.