Predictive "blood glucose" algorithm?
Asked Answered
R

4

9

I'm writing an app that lets a diabetic user enter his/her "blood glucose" readings, and then charts them on a graph over time from left to right. Since the blood readings will be done only several times a day, an algorithm would be handy to:

a) fill in the gaps on the graph between readings (curves would be more realistic than jerky lines) and allow a more accurate "blood glucose level" daily average

b) roughly predict what will happen in the future (if the user eats nothing that will affect his blood levels)

I suck at calculus. I'm hoping someone here knows a library for this stuff? I'm hoping someone knows of an algorithm that has been tailored for this specific problem already (e.g.: where someone has compared it to real data from diabetics)

Disclaimer: I am very aware that any such algorithm would vary wildly depending on the user. I'm just looking to improve on straight angular lines. Regardless of the diabetic, there is a limit to the rate that blood sugars can rise and fall.

I'm using Javascript, but as it's just math, I could port it from C, Java or whatever.

Rectangle answered 12/1, 2009 at 4:27 Comment(0)
E
43

Blood sugar behavior is very complicated. It is affected by

  • Current blood sugar (complicated by the possible presence of ketones if the patient is hyperglycemic)
  • recent food out to several hours depending on the type and how much
  • recent fast acting insulin (with variety and patient dependent reaction profiles between 45 minutes and two hours long. Oh, and delivery mechanism)
  • long-acting insulin out past 12 hours (again patient and variety dependent)
  • activity levels
  • stress levels
  • illness
  • basal insulin rate if the patient wears a pump
  • ad nauseum

Very hard problem. Any heuristic---any heuristic---you chose would be highly misleading. So short answer:

Don't do it.


This comes, in part, from having compared a diabetic's 24-hour continous glucose log with the ~10 finger pricks taken during the same time. I.e. my suggestion is data driven.


Edit: Evidently I didn't make myself clear.

You can't even get close.

Nothing you can do with finger prick data can be remotely reliable.

Connecting the dots with any lines (even straight segments) is just plain wrong. It doesn't reflect reality. Not even a little bit.

I'm an experimental particle physicist. Complicated data sets are what I do. There is a diabetic in my life (did you guess?). This matters to me.

But I've seen the high frequency data logs, side-by-side with a log of the days finger-pricks, exercise, food, and insulin.

If you could get every-fifteen-minutes data, I'd say go ahead and use a spline. It won't be dangerously misleading. But, if you have 6-10 measurements across the day, you know nothing.


Good news: continuous monitoring is coming down in price. It's out of the lab and available with some pumps even now.


For those who aren't familiar with this: compliant diabetic patients do (results of extremely unscientific polling) 4-6+ glucose tests a day as a matter of course, and several additional ones in the 1-2 hours following any unexpected excursion (they get physical symptoms that allow them to detect severe excursions).

This serves to give the patient a rough idea of how they are doing at controlling their glucose levels, but they also go to a lab to get a Hemoglobin A1C drawn every quarter (or so). The A1C result is dependent mostly on their average blood glucose.

I've talked to people who clocked in a 80-110 (quite favorable numbers) four times a day for months, and got back an A1C suggesting an average above 150 (not desirable at all). Presumable they were going high in the night. And I've heard similar stories from people who we probably going low---very low---in their sleep.

The lesson is:

Finger prick readings have their place, but don't try to extrapolate them to times not well sampled.

Envy answered 12/1, 2009 at 4:40 Comment(13)
I knew someone would say that ;-) I'm not expecting anything like 100% accuracy here. Any improvement over angular lines would be welcome.Rectangle
Fwiw, I "get" that you're saying there is no easy way to improve over angular lines. What I'm saying is any improvement is better than no improvement, and perhaps someone else out there has already done the work.Rectangle
No it's not. Put the points on the graph, and don't connect them. That is the only correct way to display the data.Envy
Agreed. My first startup was a PalmPilot blood glucose management system, and I can tell you, personally, as 15+ year Type 1 diabetic, don't do it. It doesn't work, it'll put you in legal limbo if someone gets hurt. That said, you might consider a logarithmic trendline and call it a day.Superscribe
Bad estimates are WORSE than no estimates.Bangor
@username: if you're only sampling 6 - 10 times a day your accuracy is less than %1 a day and that gives you trend lines that are pure fantasy. as Scott and dmckee suggest - don't do it!Joslin
I really, truly understand your point (and fwiw will be marking your answer correct as it's the most informed) - I just think of weather forecasting, which can also be a matter of life-and-death (e.g.: for sailors) is similarly complex.Rectangle
Exactly. Forget about diabetes for a second and imagine if your blood sugar readings were altitude that you were only sampling 5-10 times a day during flight. You can't connect those dots otherwise you're surely lying.Superscribe
@Kloucks "sampling 6 - 10 times a day" is not the exactly the case as a diabetic can choose the times at which they sample (depending on their tolerance for pain and availability of test strips). So you might be looking at 5 times within an hour (depending on the context).Rectangle
And fwiw, if it were no possible to forcast blood sugar levels to some degree, all Type 1 diabetics would be long dead!Rectangle
@username: you correctly and accurately describe the inherent error of your proposal i.e. suppose they do test 5 time 1 hr and not again 3 hrs then 4 times within an hr then then not again for 9 hrs does that give you an accurate trendline for predictive purposes - NO!Joslin
@Joslin Honest thanks for the thoughtful response. It's appreciated. We're talking at cross-purposes on some level.Rectangle
@username: I think what you're missing is that the "improvement" you're talking about is very misleading to a diabetic. If you're suggesting to a diabetic that their sugar levels are under control, when in fact they may be swinging wildly between 30 and 300, you're doing them a (potentially GRAVE) disservice.Byelostok
R
2

If you want to do just a straight fit of the data to make things easier to view then something like what Charlie Martin recommended would likely work well. However, as noted by dmckee this data really wouldn't mean anything.

What you are trying to do is actually more in line with pharmacokenetics which is an entire scientific study in and of itself. In this case I'm not even sure it would entirely apply except in the case of Type I Diabetes as most of what I know about pharamcokenetics only applies drug studies, but if something is being produced by the body then you are likely looking at entirely different types of analysis. If you are interested in the subject then there are quite a few book previews on Google Books if you do a search for "pharmacokienetics" but due to the nature of the subject they are very math heavy and assume that you have an understanding of chemistry and biology as well.

Ribald answered 12/1, 2009 at 14:9 Comment(0)
A
1

okay, you're going to be looking for some fitted curve. The thing with that is that for n points there are fit polynomials up to order... n-1 I think. It's been a while. Yep. by golly, I'm right. The common thing when you have lots of points and don't wants a complicated function (which you don't) is to use a least-squares approximation.

probably the best thing is to look for a canned routine you can use; these exist in most stats packages. Give us a little more detail on the environment you want and we might be able to point you more closely to something suitable.

Acclamation answered 12/1, 2009 at 4:33 Comment(0)
S
1

This is most likely not going to work but Artificial Neural Networks may, and i repeat may be able to get something out of a good data set. By good, i mean like weeks or months of continuous recording, and even then i wouldn't trust the data set unless i had very good reason to. I also don't think you'll get predictive data out of it, but it may depend on how you implement it. Overall if you were to do this it would seem to be more of a hobby thing to see if it even even come close, like "oh neat i got a neural network to within X amount of accuracy". Again, i must stress, don't use this in any sort of production situations or anywhere where it could possibly hurt or kill someone!

Solemn answered 28/10, 2009 at 4:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.