Skip to contents

The function mag calculates the mean absolute glucose or MAG.

Usage

mag(data, n = 60, dt0 = NULL, inter_gap = 45, tz = "")

Arguments

data

DataFrame object with column names "id", "time", and "gl".

n

Integer giving the desired interval in minutes over which to calculate the change in glucose. Default is 60 to have hourly (60 minutes) intervals.

dt0

The time frequency for interpolation in minutes, the default will match the CGM meter's frequency (e.g. 5 min for Dexcom).

inter_gap

The maximum allowable gap (in minutes) for interpolation. The values will not be interpolated between the glucose measurements that are more than inter_gap minutes apart. The default value is 45 min.

tz

A character string specifying the time zone to be used. System-specific (see as.POSIXct), but " " is the current time zone, and "GMT" is UTC (Universal Time, Coordinated). Invalid values are most commonly treated as UTC, on some platforms with a warning.

Value

A tibble object with two columns: subject id and MAG value

Details

A tibble object with a column for subject id and a column for MAG values is returned.

The glucose values are linearly interpolated over a time grid starting at the beginning of the first day of data and ending on the last day of data. Then, MAG is calculated as \(\frac{|\Delta G|}{\Delta t}\) where \(|\Delta G|\) is the sum of the absolute change in glucose calculated for each interval as specified by n, default n = 60 for hourly change in glucose. The sum is then divided by \(\Delta t\) which is the total time in hours.

References

Hermanides et al. (2010) Glucose Variability is Associated with Intensive Care Unit Mortaility, Critical Care Medicine 38(3) 838-842, doi:10.1097/CCM.0b013e3181cc4be9

Author

Elizabeth Chun

Examples


data(example_data_1_subject)
mag(example_data_1_subject)
#> # A tibble: 1 × 2
#>   id          MAG
#>   <fct>     <dbl>
#> 1 Subject 1  17.0

data(example_data_5_subject)
mag(example_data_5_subject)
#> # A tibble: 5 × 2
#>   id          MAG
#>   <fct>     <dbl>
#> 1 Subject 1  17.0
#> 2 Subject 2  18.9
#> 3 Subject 3  27.1
#> 4 Subject 4  16.7
#> 5 Subject 5  35.3