glucopy.metrics.auc#
- glucopy.metrics.auc(df: DataFrame, 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:
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 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
Notes
This function is meant to be used by
glucopy.Gframe.auc()