Close

Second approach of a diabetes type 2 risk calculator

A project log for Medical tricorder

Using artificial intelligence to identify a disease by its symptoms

m-bindhammerM. Bindhammer 04/22/2015 at 12:300 Comments

Based on this reference I started to develop a second diabetes type 2 risk calculator:

Term

Classification

Value

Sex
Female-0.879

Male0
Rx HTN
(High blood pressure medication)
Yes1.222
No0
Rx Steroids
(Steroids medication)
Yes2.191
No0
Age
/[years]
BMI
(Body mass index in kg/m²)

< 250
25 - 27.490.699
27.5 - 29.991.97
≥ 302.518
FMH
(Family medical history)
No 1st degree family members with diabetes0
Parent OR siblings with diabetes mellitus0.728
Parent AND siblings with diabetes mellitus0.753
SmokerNon smoker0
Used to smoke-0.218
Smoker0.855

The risk to suffer from diabetes type 2 is then given by

\color{White} \large Terms=6.322-Sex-RxHTN-RxSteroids-0.063 \times Age-BMI-FMH-Smoker \color{White} \large Risk= \frac{100}{1+e^{Terms}}

That's a logistic function of the form

\color{White} \large \color{White} \large f(x)= \frac{L}{1+e^{-k\times \big(x-x_{0}\big)}}   with L = 100, midpoint x-value x0 = 0 and steepness k = -1. The plot of the risk function looks as follows:

Example code:

String commandbuffer;

void setup() {
  Serial.begin(9600);
}

void loop() {
  char* a_c[] = {"a) ", "b) ", "c) "};
  char* questionary[8][4] = 
  {
    {"1. GENDER", "Female", "Male"},
    {"2. HIGH BLOOD PRESSURE MEDICATION", "Yes", "No"},
    {"3. STEROIDS MEDICATION", "Yes", "No"},
    {"4. AGE [years]"},
    {"5. BODY MASS [kg]"},
    {"6. BODY HEIGHT [m]"},
    {"7. FAMILY MEDICAL HISTORY", "No 1st degree family members with diabetes", 
     "Parent OR siblings with diabetes mellitus", 
     "Parent AND siblings with diabetes mellitus"},
    {"8. SMOKER", "Non smoker", "Used to smoke", "Smoker"}
  };
  int column_index[] = {2, 2, 2, 0, 0, 0, 3, 3};
  float score[6][4] = 
  {
    {-0.879, 0.0},
    {1.222, 0.0},
    {2.191, 0.0},
    {0.0, 0.699, 1.97, 2.518},
    {0.0, 0.728, 0.753},
    {0.0, -0.218, 0.855}
  };
  float terms[7];
  float mass, height, BMI;
  for(int i = 0; i < 8; i++) {
    for(int j = 0; j < column_index[i] + 1; j++) {
      if(j > 0) Serial.print(a_c[j-1]);
      Serial.println(questionary[i][j]);
    }
    while(1) {
      user_input();
      if(i < 3 && (commandbuffer == "a" || commandbuffer == "b")) {
        if(commandbuffer == "a") {
          input_reset();
          terms[i] = score[i][0];
          break;
        } 
        if(commandbuffer == "b") {
          input_reset();
          terms[i] = score[i][1];
          break;
        } 
      } 
      if(i == 3 && commandbuffer.toInt() > 0 && commandbuffer.toInt() < 121) {
        Serial.print("Age: ");
        Serial.print(commandbuffer.toInt());
        Serial.println(" year(s)");
        terms[i] = float(commandbuffer.toInt());
        input_reset();
        break;
      } 
      if(i == 4 && commandbuffer.toFloat() > 5.0 && commandbuffer.toFloat() < 250.0) {
        Serial.print("Body mass: ");
        Serial.print(commandbuffer.toFloat());
        Serial.println(" kg");
        mass = commandbuffer.toFloat();
        input_reset();
        break;
      } 
      if(i == 5 && commandbuffer.toFloat() > 0.4 && commandbuffer.toFloat() < 2.5) {
        Serial.print("Body height: ");
        Serial.print(commandbuffer.toFloat());
        Serial.println(" m");
        height = commandbuffer.toFloat();
        BMI = mass / pow(height, 2.0);
        Serial.print("BMI: ");
        Serial.print(BMI);
        Serial.println(" kg/m^2");
        if(BMI < 25.0) terms[i-1] = score[i-2][0];
        if(BMI >= 25.0 && BMI < 27.5) terms[i-1] = score[i - 2][1];
        if(BMI >= 27.5 && BMI < 30) terms[i-1] = score[i - 2][2];
        if(BMI >= 30.0) terms[i-1] = score[i-2][3];
        input_reset();
        break;
      } 
      if(i > 5 && (commandbuffer == "a" || commandbuffer == "b" || commandbuffer == "c")) {
        if(commandbuffer == "a") {
          input_reset();
          terms[i-1] = score[i-2][0];
          break;
        } 
        if(commandbuffer == "b") {
          input_reset();
          terms[i-1] = score[i-2][1];
          break;
        } 
        if(commandbuffer == "c") {
          input_reset();
          terms[i-1] = score[i-2][2];
          break;
        }
      } 
      else input_reset();
    }
    Serial.println("");
  }
  float exponent = 6.322-terms[0]-terms[1]-terms[2]-0.063*terms[3]-terms[4]-terms[5]-terms[6];
  float risk = 100.0/(1+exp(exponent));
  Serial.print("RISK TO SUFFER FROM TYPE 2 DIABETES: ");
  Serial.print(risk, 3);
  Serial.println(" %");
  Serial.println(""); 
}

void user_input() {
  if(Serial.available()){
    delay(100);
    while(Serial.available()) {
      commandbuffer += (char)Serial.read();
    }
  }
}

void input_reset() {
  commandbuffer = "";
}

Discussions