glucopy.metrics.mag#

glucopy.metrics.mag(df: DataFrame, time_unit: str = 'm')[source]#

Calculates the Mean Absolute Glucose Change per unit of time (MAG).

\[MAG = \sum_{i=1}^{N} \frac{|\Delta X_i|}{\Delta T_i}\]
  • \(N\) is the number of glucose readings.

  • \(\Delta X_i\) is the difference between glucose values at time i and i-1.

  • \(\Delta T_i\) is the difference between times at time i and i-1.

Parameters:
  • df (pandas.DataFrame) – DataFrame containing the CGM values. The dataframe must contain ‘CGM’ and ‘Timestamp’ columns present in glucopy.Gframe.data.

  • time_unit (str, default 'm' (minutes)) – The time time_unit for the x-axis. Can be ‘s (seconds)’, ‘m (minutes)’, or ‘h (hours)’.

Returns:

mag – Mean Absolute Glucose Change per unit of time.

Return type:

float

Notes

This function is meant to be used by glucopy.Gframe.mag()