find_max_after_hours: Find Maximum Glucose After Specified Hours

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

find_max_after_hoursR Documentation

Find Maximum Glucose After Specified Hours

Description

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

Usage

find_max_after_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 ahead from the start point

Value

A list containing:

  • max_indices: Tibble with R-based (1-indexed) row numbers of maximum glucose (max_indices). The corresponding occurrence time is df$time[max_indices] and glucose is df$gl[max_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 maximum occurs; equivalent to df$time[indices]

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

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

Notes

- start_indices must be valid row numbers in df (1-indexed). - The search window is (0, hours] hours after each start index.

See Also

mod_grid, find_local_maxima, find_new_maxima, transform_df

Other GRID pipeline: detect_between_maxima(), find_local_maxima(), find_max_before_hours(), find_min_after_hours(), find_min_before_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 maximum glucose in next 2 hours
max_after <- find_max_after_hours(example_data_5_subject, start_points, hours = 2)
print(paste("Found", length(max_after$max_indices), "maximum points"))

# Find maximum glucose in next 1 hour
max_after_1h <- find_max_after_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_max_after <- find_max_after_hours(example_data_hall, large_start_points, hours = 2)
print(paste("Found", length(large_max_after$max_indices), "maximum points in larger dataset"))

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