---
title: "detect_between_maxima function"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{detect_between_maxima function}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", warning = FALSE, message = FALSE)
library(cgmguru)
library(iglu)
```

# detect_between_maxima

## Overview
Identifies and analyzes events occurring between detected maxima points to characterize glucose dynamics between peaks. Often used downstream of `grid()`, `mod_grid()`, `find_max_after_hours()`, and `find_new_maxima()`.

## Inputs
- **df**: CGM dataframe with `id`, `time` (POSIXct), `gl` (mg/dL)
- **transform_df**: Output from `transform_df()` mapping GRID starts to maxima

## Returns
- **results**: Tibble with `id`, `grid_time`, `grid_gl`, `maxima_time`, `maxima_glucose`, `time_to_peak`
- **episode_counts**: Counts per `id`

## Run documented examples
```{r}
example(detect_between_maxima, package = "cgmguru", run.dontrun = FALSE)
```


