View source: R/variability_metrics.R
| mage_rcpp | R Documentation |
Calculates Mean Amplitude of Glycemic Excursions (MAGE) with an Rcpp backend.
mage_rcpp(
data,
version = c("ma", "naive"),
sd_multiplier = 1,
short_ma = 5,
long_ma = 32,
return_type = c("num", "df"),
direction = c("avg", "service", "max", "plus", "minus"),
tz = "",
inter_gap = 45,
max_gap = 180
)
data |
A dataframe containing CGM data with columns |
version |
Either |
sd_multiplier |
Multiplier for the standard deviation threshold in
|
short_ma |
Short moving-average window length. Defaults to 5. |
long_ma |
Long moving-average window length. Defaults to 32. |
return_type |
Either |
direction |
One of |
tz |
Time zone used for day-grid alignment when supplied. |
inter_gap |
Maximum gap, in minutes, over which linear interpolation is allowed. Defaults to 45. |
max_gap |
Gap length, in minutes, above which MAGE is calculated on separate trace segments. Defaults to 180. |
The implementation follows the MAGE calculation approaches used by
iglu::mage. The default version = "ma"
follows iglu's moving-average approach: CGM is interpolated to 5-minute
intervals, short and long moving-average crossings identify candidate
peak/nadir intervals, and countable excursions are those whose peak-to-nadir
or nadir-to-peak amplitude is at least one glucose standard deviation.
The version = "naive" option matches iglu's older standard-deviation
based calculation. This function is calculation-only and does not implement
iglu's plotting options.
A tibble with columns id and MAGE. With return_type =
"df", MAGE is a list-column of tibbles with start,
end, mage, plus_or_minus, and
first_excursion.
Service, F. John, et al. (1970). Mean amplitude of glycemic excursions, a measure of diabetic instability. Diabetes, 19(9), 644-655. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.2337/diab.19.9.644")}
Fernandes, Nathaniel J., et al. (2022). Open-source algorithm to calculate mean amplitude of glycemic excursions using short and long moving averages. Journal of Diabetes Science and Technology, 16(2), 576-577. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1177/19322968211061165")}
iglu::mage, conga_rcpp
library(iglu)
data(example_data_5_subject)
mage_rcpp(example_data_5_subject)
mage_rcpp(example_data_5_subject, version = "naive")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.