glucopy.Gframe.auc#
- Gframe.auc(per_day: bool = False, time_unit='m', threshold: int | float = 0, above: bool = True)[source]#
Calculates the Area Under the Curve (AUC) using the trapezoidal rule.
\[AUC = \frac{1}{2} \sum_{i=1}^{N-1} (X_i + X_{i+1}) * (t_{i+1} - t_i)\]\(X_i\) is the \(i\)-th measurement of the glucose concentration at time \(t_i\).
\(X_{i+1}\) is the \((i+1)\)-th measurement of the glucose concentration at time \(t_{i+1}\).
\(t_i\) is the \(i\)-th time associated with the \(X_i\) measurement.
\(t_{i+1}\) is the \((i+1)\)-th time associated with the \(X_{i+1}\) measurement.
\(N\) is the number of glucose readings.
- Parameters:
per_day (bool, default False) – If True, returns a
pandas.Series
with the AUC for each day. If False, returns the AUC for the entire dataset.time_unit (str, default 'm' (minutes)) – The time unit for the x-axis. Can be ‘s (seconds)’, ‘m (minutes)’, or ‘h (hours)’.
threshold (int | float, default 0) – The threshold value above which the AUC will be calculated.
above (bool, default True) – If True, the AUC will be calculated above the threshold. If False, the AUC will be calculated below the threshold.
- Returns:
auc – Area Under the Curve (AUC).
- Return type:
float | pandas.Series
Examples
Calculating the AUC 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.auc() Out[3]: 23075053.5
Calculating the AUC for each day and minutes as the time unit (default):
In [4]: gf.auc(per_day=True) Out[4]: Day 2020-11-27 42030.0 2020-11-28 196732.0 2020-11-29 208903.5 2020-11-30 170577.5 2020-12-01 198432.0 ... 2021-03-14 203134.5 2021-03-15 175091.0 2021-03-16 230388.0 2021-03-17 163342.0 2021-03-18 158780.5 Name: AUC, Length: 112, dtype: float64
Calculating the AUC for the entire dataset, hours as the time unit, and below the threshold (100):
In [5]: gf.auc(time_unit='h', threshold=100, above=False) Out[5]: 19509.93333333331