glucopy.Gframe.mag#

Gframe.mag(per_day: bool = False, 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:
  • per_day (bool, default False) – If True, returns the a pandas.Series with the MAG for each day. If False, returns the MAG for the entire dataset.

  • 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

Examples

Calculating the MAG for the entire dataset and minutes as the time unit (default):

In [1]: import glucopy as gp

In [2]: gf = gp.data('prueba_1')

In [3]: gf.mag()
Out[3]: 0.7260142569639062

Calculating the MAG for the entire dataset and hours as the time unit:

In [4]: gf.mag(time_unit='h')
Out[4]: 43.560855417834375

Calculating the MAG for each day and minutes as the time unit:

In [5]: gf.mag(per_day=True)
Out[5]: 
Day
2020-11-27    0.693333
2020-11-28    0.795789
2020-11-29    0.775281
2020-11-30    0.669242
2020-12-01    0.654494
                ...   
2021-03-14    0.632756
2021-03-15    0.853411
2021-03-16    0.656360
2021-03-17    0.573018
2021-03-18    0.514408
Name: MAG, Length: 112, dtype: float64