Continuous glucose monitoring analysis for chronobiology research.
⚠️ Early development. sugaR is a fresh scaffold — the pipeline below describes the intended functionality, but no functions are implemented yet. See
NEWS.mdfor current status.
📖 What is sugaR?
sugaR processes continuous glucose monitoring (CGM) data for circadian and chronobiology research. It smooths raw interstitial glucose traces, computes an adaptive pre-wake baseline, detects the first post-wake glucose peak, and derives cycle-level regularity metrics — most notably fGPTstd, the day-to-day standard deviation of first post-wake glucose peak timing.
sugaR is a peer package to zeitR (actigraphy) and slumbR (sleep diaries) within the Circadia Lab ecosystem, intended to feed into syncR::sync() alongside those packages once published.
✨ Features
- 📉 Savitzky-Golay smoothing of CGM traces
- ⚖️ Adaptive baseline computation with diabetic/non-diabetic tolerances
- 📈 First post-wake glucose peak detection with dynamic prominence/distance
- 🔀 Hierarchical onset/offset determination
- 🌙 Sleep-wake-anchored glucose cycle construction and QC
- 📊 First post-wake glucose peak timing variability (fGPTstd)
- 🖼️ Actogram-style plotting for visual QC of automated peak detection
🗂️ Project Structure
sugaR/
├── R/
│ ├── smoothing.R # Savitzky-Golay smoothing
│ ├── baseline.R # Pre-wake baseline computation & correction
│ ├── peak-detection.R # Candidate peak detection & grouping
│ ├── onset-offset.R # Peak onset/offset rules
│ ├── cycle.R # Sleep-anchored cycle construction & QC
│ ├── fgptstd.R # fGPTstd metric
│ ├── plot-actogram.R # Visual QC plotting
│ ├── constructors.R # sugaR_trace / sugaR_cycle S3 objects
│ └── sugaR-package.R # Package-level documentation
├── tests/testthat/ # Unit tests (currently stubs)
├── dev/ # Real-data smoke tests (never committed with data)
└── man/ # Generated documentation
🚀 Getting Started
Installation
# Not yet published to r-universe. Once functional:
remotes::install_github("circadia-bio/sugaR")Basic usage (planned)
library(sugaR)
trace <- glucose_trace(time = cgm$time, glucose = cgm$glucose, diabetic = FALSE)
cycle <- build_glucose_cycle(cgm = cgm, sleep_episode = sleep_episode)
cycle <- validate_cycle(cycle)
fgptstd <- compute_fgptstd(cycles = participant_cycles)📦 Dependencies
| Package | Purpose |
|---|---|
signal |
Savitzky-Golay filtering |
stats |
Base statistical functions |
ggplot2 (Suggests) |
Actogram plotting |
testthat (Suggests) |
Unit testing |
🤝 Related Tools
- 🌙 zeitR — wrist actigraphy analysis
- 📔 slumbR — sleep diary processing
- 🔄 syncR — ecosystem integrator, pulling sugaR/zeitR/slumbR/tallieR into a unified participant database
- 🔬 circadia-bio — the Circadia Lab GitHub organisation