Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Predictive "blood glucose" algorithm?

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.

like image 308
username Avatar asked Jan 12 '09 04:01

username


3 Answers

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.

like image 68
dmckee --- ex-moderator kitten Avatar answered Oct 05 '22 17:10

dmckee --- ex-moderator kitten


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.

like image 35
rjzii Avatar answered Oct 05 '22 16:10

rjzii


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.

like image 34
Charlie Martin Avatar answered Oct 05 '22 17:10

Charlie Martin