@@ -19,50 +19,75 @@ A significant focus of this project has been ensuring compatibility with the ori
1919This approach ensures that the Python implementation produces results consistent with the original R package.
2020
2121## Unit Test Status
22- Unless noted, iglu-r test is considered successful if it achieves precision of 0.001
23-
24- | Function | IGLU-R test compatibility | array/list/Series | TZ | Comments |
25- | ----------| ---------------------------| -------------------| ----| ----------|
26- | above_percent | ✅ | |||
27- | active_percent | ✅ |
28- | adrr | ✅ |
29- | auc| 🟡 (0.01 precision) | || see [ auc_evaluation.ipynb] ( https://github.com/staskh/iglu_python/blob/main/notebooks/auc_evaluation.ipynb ) |
30- | below_percent| ✅ |
31- | cogi | ✅ |
32- | conga | ✅ |
33- | cv_glu | ✅ |
34- | cv_measures | ✅ |
35- | ea1c | ✅ |
36- | episode_calculation | ✅| || |
37- | gmi | ✅ |
38- | grade_eugly | ✅ |
39- | grade_hyper | ✅ |
40- | grade_hypo | ✅ |
41- | grade | ✅ |
42- | gri | ✅ |
43- | gvp | ✅ |
44- | hbgi | ✅ |
45- | hyper_index | ✅ |
46- | hypo_index | ✅ |
47- | igc | ✅ |
48- | j_index | ✅ |
49- | lbgi | ✅ |
50- | mad_glu | ✅ |
51- | mag | ✅ | || IMHO, Original R implementation has an error |
52- | mage | ✅ | || See algorithm at [ MAGE] ( https://irinagain.github.io/iglu/articles/MAGE.html ) |
53- | mean_glu | ✅ |
54- | median_glu | ✅ |
55- | modd | ✅ |
56- | pgs | ✅ | || |
57- | quantile_glu | ✅ |
58- | range_glu | ✅ |
59- | roc | ✅ |
60- | sd_glu | ✅ |
61- | sd_measures | ✅ |
62- | sd_roc | ✅ | |||
63- | process_data | ✅ |
64- | summary_glu | ✅ |
65- | CGMS2DayByDay | ✅ |
22+ The current version of IGLU-PYTHON is test-compatible with IGLU-R v4.2.2
23+
24+ Unless noted, IGLU-R test compatability is considered successful if it achieves precision of 0.001
25+
26+ | Function | Description | IGLU-R test compatibility | list /ndarray /Series input | TZ | Comments |
27+ | ----------| -------------| -------------| -------------------| ----| ----------|
28+ | above_percent | percentage of values above target thresholds| ✅ | ✅ returns Dict[ str,float] |||
29+ | active_percent | percentage of time CGM was active | ✅ | ✅ only Series(DatetimeIndex) returns Dict[ str,float] |
30+ | adrr | average daily risk range | ✅ | ✅ only Series(DatetimeIndex) returns float |
31+ | auc| Area Under Curve | 🟡 (0.01 precision) | ✅ only Series(DatetimeIndex) returns float || see [ auc_evaluation.ipynb] ( https://github.com/staskh/iglu_python/blob/main/notebooks/auc_evaluation.ipynb ) |
32+ | below_percent| percentage of values below target thresholds| ✅ | ✅ returns Dict[ str,float] |
33+ | cogi |Coefficient of Glucose Irregularity | ✅ | ✅ returns float
34+ | conga | Continuous Overall Net Glycemic Action |✅ | ✅ only Series(DatetimeIndex) returns float
35+ | cv_glu | Coefficient of Variation | ✅| ✅ returns float |
36+ | cv_measures | Coefficient of Variation subtypes (CVmean and CVsd) | ✅ | ✅ only Series(DatetimeIndex) returns Dict[ str,float] | |
37+ | ea1c | estimated A1C (eA1C) values| ✅ | ✅ returns float |
38+ | episode_calculation | Hypo/Hyperglycemic episodes with summary statistics| ✅| 🟡 always returns DataFrame(s)|| |
39+ | gmi | Glucose Management Indicator | ✅ | ✅ returns float |
40+ | grade_eugly |percentage of GRADE score attributable to target range| ✅ | ✅ returns float
41+ | grade_hyper |percentage of GRADE score attributable to hyperglycemia| ✅ |✅ returns float
42+ | grade_hypo |percentage of GRADE score attributable to hypoglycemia| ✅ |✅ returns float
43+ | grade | mean GRADE score| ✅ | ✅ returns float |
44+ | gri | Glycemia Risk Index | ✅ | ✅ returns float |
45+ | gvp |Glucose Variability Percentage| ✅ | ✅ only Series(DatetimeIndex) returns float
46+ | hbgi | High Blood Glucose Index| ✅ | ✅ returns float |
47+ | hyper_index | Hyperglycemia Index| ✅ | ✅ returns float |
48+ | hypo_index | Hypoglycemia Index| ✅ | ✅ returns float |
49+ | igc | Index of Glycemic Control| ✅ | ✅ returns float |
50+ | in_range_percent | percentage of values within target ranges| ✅ | ✅ returns Dict[ str,float] |
51+ | iqr_glu | glucose level interquartile range| ✅ | ✅ returns float |
52+ | j_index | J-Index score for glucose measurements| ✅ | ✅ returns float |
53+ | lbgi | Low Blood Glucose Index| ✅ | ✅ returns float |
54+ | m_value | M-value of Schlichtkrull et al | ✅ | ✅ returns float |
55+ | mad_glu | Median Absolute Deviation | ✅ | ✅ returns float |
56+ | mag | Mean Absolute Glucose| ✅ | ✅ only Series(DatetimeIndex) returns float ||| IMHO, Original R implementation has an error |
57+ | mage | Mean Amplitude of Glycemic Excursions| ✅ | ✅ only Series(DatetimeIndex) returns float || See algorithm at [ MAGE] ( https://irinagain.github.io/iglu/articles/MAGE.html ) |
58+ | mean_glu | Mean glucose value | ✅ | ✅ returns float|
59+ | median_glu | Median glucose value| ✅ | ✅ returns float |
60+ | modd | Mean of Daily Differences| ✅ | ✅ only Series(DatetimeIndex) returns float|
61+ | pgs | Personal Glycemic State | ✅ | ✅ only Series(DatetimeIndex) returns float| ||
62+ | quantile_glu | glucose level quantiles| ✅ | ✅ returns List[ float] |
63+ | range_glu | glucose level range| ✅ | ✅ returns float|
64+ | roc | Rate of Change| ✅ | 🟡 always returns DataFrame|
65+ | sd_glu | standard deviation of glucose values| ✅ | ✅ returns float
66+ | sd_measures | various standard deviation subtypes| ✅ | ✅ only Series(DatetimeIndex) returns Dict[ str,float] |
67+ | sd_roc | standard deviation of the rate of change| ✅ | ✅ only Series(DatetimeIndex) returns float ||
68+ | summary_glu | summary glucose level| ✅ |
69+ | process_data | Data Pre-Processor | ✅ |
70+ | CGMS2DayByDay | Interpolate glucose input| ✅ |
71+
72+ ### Input & Output
73+ The implementation maintains compatibility with the R version while following Python best practices. The metrics can be used as:
74+
75+ ``` Python
76+ import iglu_python ias iglu
77+
78+ # With DataFrame input
79+ result_df = iglu.cv_glu(data) # data should have 'id', 'time', and 'gl' columns
80+ # Return DataFrame with "id' and column(s) with value(s)
81+
82+ # With Series input (some metrics require Series with DateTimeIndex)
83+ result_float = iglu.cv_glu(glucose_series) # just glucose values
84+ # returns a single float value
85+
86+ # Same with function that support list or ndarray
87+ result_float = iglu.cv_glu(glucose_list) # list of glucose values
88+ # returns a single float value
89+
90+ ```
6691
6792# Installation
6893
@@ -92,36 +117,32 @@ import iglu_python as iglu
92117# Optional: datetime index or 'time' column
93118data = pd.DataFrame({
94119 ' id' : [' Subject1' ] * 100 ,
95- ' time' : pd.date_range(start = ' 2023-01-01' , periods = 100 , freq = ' 5min' )
96- ' gl' : [120 , 135 , 140 , 125 , 110 , ... ], # glucose values in mg/dL
120+ ' time' : pd.date_range(start = ' 2023-01-01' , periods = 100 , freq = ' 5min' ),
121+ ' gl' : [120 , 135 , 140 , 125 , 110 ] * 20 # glucose values in mg/dL
97122})
98123
99124# Calculate glucose metrics
100125mean_glucose = iglu.mean_glu(data)
101126cv = iglu.cv_glu(data)
102- time_in_range = iglu.active_percent(data, lltr = 70 , ultr = 180 )
127+ active = iglu.active_percent(data)
103128
104- print (f " Mean glucose: { mean_glucose} " )
105- print (f " CV: { cv} " )
106- print (f " Time in range (70-180 mg/dL) : { time_in_range } % " )
129+ print (f " Mean glucose: { mean_glucose[ ' mean ' ][ 0 ] } " )
130+ print (f " CV: { cv[ ' CV ' ][ 0 ] } " )
131+ print (f " CGM active percent : { active[ ' active_percent ' ][ 0 ] } % " )
107132```
108133
109134### Using with Time Series Data
110135
111136``` python
112137import pandas as pd
138+ import numpy as np
113139import iglu_python as iglu
114- from datetime import datetime, timedelta
115140
116141# Create time series data
117142timestamps = pd.date_range(start = ' 2023-01-01' , periods = 288 , freq = ' 5min' )
118143glucose_values = [120 + 20 * np.sin(i/ 48 ) + np.random.normal(0 , 5 ) for i in range (288 )]
119144
120- data = pd.DataFrame({
121- ' id' : [' Subject1' ] * 288 ,
122- ' time' : timestamps,
123- ' gl' : glucose_values
124- })
145+ data = pd.Series(glucose_values, index = timestamps)
125146
126147# Calculate advanced metrics
127148mage = iglu.mage(data)
0 commit comments