Predicting BG vs Predicting Sensitivity

This last December, simPancreas went through many changes putting me closer to my so wanted “set and forget” Artificial Pancreas.

This last December 2015, simPancreas went through more changes, putting me closer to my so wanted “set and forget” Artificial Pancreas.

The most important change I went through was introducing variable insulin sensitivity throughout the system simulation cycles intended to determine an adequate amount of insulin for treatment.

Before this change, simPancreas calculated directly without any variable insulin sensitivity, considering only changing sensitivities throughout the day as taught/recommended with regular pump-therapy.

Up to this point, simPancreas calculations went something like:

1. It calculated a future BG prediction.

2. It then determined the amount of insulin needed from that prediction ( in case of it being higher than the BG objective ) in order to return to the objective.

3. It simulated BG reductions throughout the next 3 hours ( insulin life ) according to changing sensitivities as hours passed by.

Although the system results have been very promising, I was still getting some variations from the BG objective in the order of 10-15 points ( mg / dl ) above or below objective.

I started looking for ways to understand why those variations were happening.

Analyzing the Data

Up to this point, I have accumulated more than 70,000 data points, all including:
— Blood glucose
— Time of day
— Remaining Active Insulin ( IOB )
— Active Carbohydrates ( COB )
— Insulin Sensitivity
— BG Velocity
— BG Acceleration

I decided to start analysing the data and experimenting with different hypothesis that could account for the variations from the objective I was getting.

Hypothesis 1: The Time of Day + Active Carbohydrates

The greatest difference in sensitivity detected was when I started looking at the data for sensitivities with Carbohydrates on Board vs No Carbohydrates on Board.

This is a bit obvious if you think about it:

— If at a certain time, bg is rising and you haven’t eaten, you’ll need, some insulin.

— If at that same time, bg is rising by the same amount and you have eaten, you’ll need much more insulin.

The more insulin used, the less sensitivity to it you have, theoretically.

This was implemented into the algorithm and it worked fine behaving just as we manually do when pre-bolusing as soon as you know how much you are going to eat.

But still, there were variations…

Hypothesis 2: Its all in the BG

At one point of my analysis I was trying to link BG Sensitivity with IOB + COB + Velocity but couldn’t find any correlation.

I decided to stop, and do this step by step, so I organised the data.

My combined sensitivity graph throughout the day with ALL data points, looks something like this:

Screen Shot 2016-01-15 at 8.17.02 AM
Click graph to zoom. Sensitivity in the Y-axis and Hour of the day in the X-axis.

I started to dissect that graph and decided to “select” and “filter” the data:

a) By hour of the day

b) Using only data points with a BG of 100

This is what I got:

Screen Shot 2016-01-14 at 6.27.13 PM
Click graph to zoom. Sensitivity in the Y-axis and Hour of the day in the X-axis.

I didn’t notice anything special or different from the data, so I decided to add the same data but with BG at 80, and this is what I got:

Screen Shot 2016-01-14 at 6.31.19 PM
Click graph to zoom.

Hmmm… that looked really weird… lets try to add some BG around 120 just for curiosity…

Screen Shot 2016-01-14 at 6.32.59 PM
Click graph to zoom.

So this looks pretty messy and jumpy… but there is a pattern between each set of data!

The higher the BG, the lower the AVG Sensitivity during the day!

I decided to group BG throughout the day in buckets of 10 points each and averaged each bucket and this is what I got:

Screen Shot 2016-01-14 at 5.54.39 PM
Click graph to zoom. Sensitivity in the Y-axis and BG Bucket on the X-Axis.

The Red Line is the Average Sensitivity, and as we can clearly see, the lower the BG, the higher the Average Sensitivity.

I added a dashed line to show the data trend and was impressed by how as you have lower BGs sensitivity increases!

Could this in part explain why sometimes we feel insulin gets pooled in our bodies?

Implications for The Loop

This has major implications for the loop.

This means we need to calculate a bolus based on the moving Sensitivity as BG is decreasing / increasing.

If my BG objective is 100 mg/dl and my current BG is 120 mg/dl


My sensitivity at 120 mg/dl is 20mg/dl/U


The logical thing to do is to give a 1U bolus. Since sensitivity is at 20mg/dl/U, one unit should bring us down to 100 mg/dl


Let’s say that by bad luck you end up 1.5 hrs later at 110 mg/dl with 0.5U of active insulin and at 110 mg/dl your sensitivity increases to 30mg/dl/U, that means you will end up at 95 mg/dl


Let’s say that by bad luck you end up .5 hrs later at 100 mg/dl with 0.25U of active insulin and at 100 mg/dl your sensitivity increases to 35mg/dl/U, that means you will end up at 91 mg/dl

Now imagine the calculations if your BG first is increasing with carbs, but then it will start decreasing with the insulin dose you are calculating at a point in time.

It gets complicated, but it is solvable 🙂

There is still much work to do…

The tricky part…

As if the last part wasn’t tricky enough…

One hard thing about all this is calculating Sensitivity correctly and being aware that it is constantly changing.

The calculation part is done as below:

1. Find a set of data points.

2. Determine insulin consumption by measuring the differences in IOB.

3. Determine BG decrement by measuring differences in BG.

4. Calculate Sensitivity by dividing BG decrement / Insulin consumption.

So if my insulin decreases 30 points with 1U of insulin, sensitivity is 30 right?

How the hell do you calculate sensitivity when there is no BG decrement or when there is no Insulin consumption??????

Here’s the really really really tricky part:
I haven’t found the perfect way to do it yet.

But I have found an iterative way to approximate to a safe Sensitivity measurement.

1. I find an average sensitivity for that time of day, lets say 20 mg/dl/U

2. If BG is above the objective, I decrement the average sensitivity by a percentage to account for the increment.

3. If BG is below the objective, I increment the average sensitivity by a percentage to account for the decrement.

I could also try determining how much BG is incrementing theoretically with carbs and how much it is decrementing theoretically with IOB.

There is much more data where I can get a real measurement with BG decrement and Insulin consumption, so this temporary formula fills in for the remaining data for now.


1. I would be very interested to know if anyone else has found out a similar / different way to do so. In the mean time I will keep testing and experimenting.

2. In any way this post represents any professional research or analysis. This is just me, with my data, doing experiments and communicating my personal insights. Please be careful & don’t hurt yourself.

3. I am open to discuss and test with my own data & simPancreas 🙂