Description
Hi,
I think there might be an error in risk_index.
In lines 12 and 13
rl = 10 * fBG[fBG < 0]**2 rh = 10 * fBG[fBG > 0]**2
If we pass a list of BG, those lines are removing the elements with fBG(BG)<0 or fBG>0, and afterwards the mean is computed.
But if we look at the paper "Clarke, W., & Kovatchev, B. (2009). Statistical tools to analyze continuous glucose monitor data. Diabetes Technology and Therapeutics, 11(SUPPL.1). https://doi.org/10.1089/dia.2008.0138" the definition LBGI and HBGI for a series of n BG reading is the average of the rl and rh for each BG reading, so we use all n readings.
With the above implementation the rl=0.0 or rh=0.0 samples are removed from the average.
Consider the following example, where we pass 10 samples to risk_index with an horizon of 10
BG | rl | rh
122 | 0.0000 | 0.2277
155 | 0.0000 | 3.5834
144 | 0.0000 | 2.1229
120 | 0.0000 | 0.1441
200 | 0.0000 | 11.6047
350 | 0.0000 | 45.5737
456 | 0.0000 | 69.5785
131 | 0.0000 | 0.8055
70 | 7.7552 | 0.0000
555 | 0.0000 | 90.7512
We get LBGI=7.7552, HBGI=24.93
But, if we take all the 10 samples and compute the average, then we should get LBGI=0.77552, that is, it should divide by 10 not 1 to take all the 10 samples.
What do you think?