Learn R Programming

iglu (version 3.0.0)

mage: Calculate Mean Amplitude of Glycemic Excursions

Description

The function calculates MAGE values and can optionally return a plot of the glucose trace.

Usage

mage(data, version = c("ma", "naive"), ...)

Arguments

data

Data Frame object with column names "id", "time", and "gl" OR numeric vector of glucose values (plot won't work with vector).

version

Either 'ma' or 'naive'. Chooses which version of the MAGE algorithm to use. 'ma' algorithm is more accurate, and is the default. Earlier versions of iglu package (<=2.0.0) used 'naive'.

...

Optional arguments to pass to the MAGE Functions (see mage_ma_single)

  • dateformat: POSIXct format for time of glucose reading. Default: YYYY-mm-dd HH:MM:SS. Highly recommended to set if glucose times are of a different format.

  • short_ma: Integer for period length of the short moving average. Must be positive and less than "long_MA". Default: 5. (Recommended <15).

  • long_ma: Integer for period length for the long moving average. Default: 23. (Recommended >20)

  • plot: Boolean. Returns ggplot if TRUE. Default: FALSE.

  • interval: Integer for time interval in minutes between glucose readings. Algorithm will auto-magically determine the interval if not specified. Default: NA (Only used to calculate the gaps shown on the ggplot)

  • title: Title for the ggplot. Default: "Glucose Trace - Subject [ID]"

  • xlab: Label for x-axis of ggplot. Defaults to "Time"

  • ylab: Label for y-axis of ggplot. Defaults to "Glucose Level"

  • show_ma: Whether to show the moving average lines on the plot or not. Default: FALSE

  • sd_multiplier: A numeric value that can change the sd value used to determine size of glycemic excursions used in the calculation. This parameter is only used when version = "naive", ans is ignored otherwise.

Value

A tibble object with two columns: the subject id and corresponding MAGE value. If a vector of glucose values is passed, then a tibble object with just the MAGE value is returned. In version 2, if plot = TRUE, a "master" ggplot will be returned with glucose traces for all subjects.

Details

The function computationally emulates the manual method for calculating the mean amplitude of glycemic excursions (MAGE) first suggested in Mean Amplitude of Glycemic Excursions, a Measure of Diabetic Instability, (Service, 1970).

'ma' is a more accurate algorithm that uses the crosses of a short and long moving average to identify intervals where a peak/nadir might exist. Then, the height from one peak/nadir to the next nadir/peak is calculated from the *original* glucose values.

'naive' algorithm calculates MAGE by taking the mean of absolute glucose differences (between each value and the mean) that are greater than the standard deviation. A multiplier can be added to the standard deviation using the sd_multiplier argument.

References

Service et al. (1970) Mean amplitude of glycemic excursions, a measure of diabetic instability Diabetes 19 .644-655, 10.2337/diab.19.9.644.

Examples

Run this code
# NOT RUN {
data(example_data_5_subject)
mage(example_data_5_subject, version = 'ma')
# }

Run the code above in your browser using DataLab