Based on this reference I started to develop a second diabetes type 2 risk calculator:
Term | Classification | Value |
Sex | Female | -0.879 |
Male | 0 | |
Rx HTN (High blood pressure medication) | Yes | 1.222 |
No | 0 | |
Rx Steroids (Steroids medication) | Yes | 2.191 |
No | 0 | |
Age | / | [years] |
BMI (Body mass index in kg/m²) | < 25 | 0 |
25 - 27.49 | 0.699 | |
27.5 - 29.99 | 1.97 | |
≥ 30 | 2.518 | |
FMH (Family medical history) | No 1st degree family members with diabetes | 0 |
Parent OR siblings with diabetes mellitus | 0.728 | |
Parent AND siblings with diabetes mellitus | 0.753 | |
Smoker | Non smoker | 0 |
Used to smoke | -0.218 | |
Smoker | 0.855 |
The risk to suffer from diabetes type 2 is then given by
That's a logistic function of the form
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
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.