1. LDL Cholesterol calculation
- Posted by jmduro 1 month ago
- 1190 views
Here is code to calulate LDL Cholesterol by the Martin-Hopkins formula which works even with high levels of triglycerides or total cholesterol.
It has been checked with EU 4.2.0 development.
include std/console.e include std/io.e constant factor_table= { { 3.5, 3.4, 3.3, 3.3, 3.2, 3.1}, { 4 , 3.9, 3.7, 3.6, 3.6, 3.4}, { 4.3, 4.1, 4 , 3.9, 3.8, 3.6}, { 4.5, 4.3, 4.1, 4 , 3.9, 3.9}, { 4.7, 4.4, 4.3, 4.2, 4.1, 3.9}, { 4.8, 4.6, 4.4, 4.2, 4.2, 4.1}, { 4.9, 4.6, 4.5, 4.3, 4.3, 4.2}, { 5 , 4.8, 4.6, 4.4, 4.3, 4.2}, { 5.1, 4.8, 4.6, 4.5, 4.4, 4.3}, { 5.2, 4.9, 4.7, 4.6, 4.4, 4.3}, { 5.3, 5 , 4.8, 4.7, 4.5, 4.4}, { 5.4, 5.1, 4.8, 4.7, 4.5, 4.3}, { 5.5, 5.2, 5 , 4.7, 4.6, 4.5}, { 5.6, 5.3, 5 , 4.8, 4.6, 4.5}, { 5.7, 5.4, 5.1, 4.9, 4.7, 4.5}, { 5.8, 5.5, 5.2, 5 , 4.8, 4.6}, { 6 , 5.5, 5.3, 5 , 4.8, 4.6}, { 6.1, 5.7, 5.3, 5.1, 4.9, 4.7}, { 6.2, 5.8, 5.4, 5.2, 5 , 4.7}, { 6.3, 5.9, 5.6, 5.3, 5 , 4.8}, { 6.5, 6 , 5.7, 5.4, 5.1, 4.8}, { 6.7, 6.2, 5.8, 5.4, 5.2, 4.9}, { 6.8, 6.3, 5.9, 5.5, 5.3, 5 }, { 7 , 6.5, 6 , 5.7, 5.4, 5.1}, { 7.3, 6.7, 6.2, 5.8, 5.5, 5.2}, { 7.6, 6.9, 6.4, 6 , 5.6, 5.3}, { 8 , 7.2, 6.6, 6.2, 5.9, 5.4}, { 8.5, 7.6, 7 , 6.5, 6.1, 5.6}, { 9.5, 8.3, 7.5, 7 , 6.5, 5.9}, {11.9, 10 , 8.8, 8.1, 7.5, 6.7} } -- CT, TG, HDL en g/L function martin_hopkins(atom CT, atom TG, atom HDL) integer lig=0, col=0, tg=TG*100 -- tg, nonhdl en mg/dL atom factor=5.0, nonhdl=(CT-HDL)*100 if (tg<50) then lig=1 elsif (tg>=50) and (tg<57) then lig=2 elsif (tg>=57) and (tg<62) then lig=3 elsif (tg>=62) and (tg<67) then lig=4 elsif (tg>=67) and (tg<72) then lig=5 elsif (tg>=72) and (tg<76) then lig=6 elsif (tg>=76) and (tg<80) then lig=7 elsif (tg>=80) and (tg<84) then lig=8 elsif (tg>=84) and (tg<88) then lig=9 elsif (tg>=88) and (tg<93) then lig=10 elsif (tg>=93) and (tg<97) then lig=11 elsif (tg>=97) and (tg<101) then lig=12 elsif (tg>=101) and (tg<106) then lig=13 elsif (tg>=106) and (tg<111) then lig=14 elsif (tg>=111) and (tg<116) then lig=15 elsif (tg>=116) and (tg<121) then lig=16 elsif (tg>=121) and (tg<127) then lig=17 elsif (tg>=127) and (tg<133) then lig=18 elsif (tg>=133) and (tg<139) then lig=19 elsif (tg>=139) and (tg<147) then lig=20 elsif (tg>=147) and (tg<155) then lig=21 elsif (tg>=155) and (tg<164) then lig=22 elsif (tg>=164) and (tg<174) then lig=23 elsif (tg>=174) and (tg<186) then lig=24 elsif (tg>=186) and (tg<202) then lig=25 elsif (tg>=202) and (tg<221) then lig=26 elsif (tg>=221) and (tg<248) then lig=27 elsif (tg>=248) and (tg<293) then lig=28 elsif (tg>=293) and (tg<400) then lig=29 elsif (tg>=400) then lig=30 end if if (nonhdl<100) then col=1 elsif (nonhdl>=100) and (nonhdl<130) then col=2 elsif (nonhdl>=130) and (nonhdl<160) then col=3 elsif (nonhdl>=160) and (nonhdl<190) then col=4 elsif (nonhdl>=190) and (nonhdl<220) then col=5 elsif (nonhdl>=220) then col=6 end if factor = factor_table[lig][col] return CT - HDL - (TG/factor) end function atom CT = prompt_number("Total Cholesterol (g/L):\n", {}) atom TG = prompt_number("Triglycerides (g/L):\n", {}) atom HDL = prompt_number("HDL Cholesterol (g/L):\n", {}) printf(STDOUT, "LDL Cholesterol (g/L): %.3f\n", martin_hopkins(CT, TG, HDL)) maybe_any_key()
Jean-Marc
2. Re: LDL Cholesterol calculation
- Posted by axtens_bruce 1 month ago
- 1152 views
So I thought I'd fiddle with this code and change the big if into a decision table-ish thing.
constant lig_dec_tab = { {MININT, 57, 1}, {50, 57, 2 }, {57, 62, 3 }, {62, 67, 4 }, {67, 72, 5 }, {72, 76, 6 }, {76, 80, 7 }, {80, 84, 8 }, {84, 88, 9 }, {88, 93, 10 }, {93, 97, 11 }, {97, 101, 12 }, {101, 106, 13 }, {106, 111, 14 }, {111, 116, 15 }, {116, 121, 16 }, {121, 127, 17 }, {127, 133, 18 }, {133, 139, 19 }, {139, 147, 20 }, {147, 155, 21 }, {155, 164, 22 }, {164, 174, 23 }, {174, 186, 24 }, {186, 202, 25 }, {202, 221, 26 }, {221, 248, 27 }, {248, 293, 28 }, {293, 400, 29 }, {400, MAXINT, 30 } }
and then later
for i = 1 to length(lig_dec_tab) do if tg > lig_dec_tab[1] and tg < lig_dec_tab[2] then lig = lig_dec_tab[3] exit end if end for
But when I run it I get
C:\TEMP\ldl.ex:67 <0074>:: Errors resolving the following references: 'MININT' (ldl.ex:38) has not been declared. 'MAXINT' (ldl.ex:67) has not been declared.But aren't MININT and MAXINT supposed to internal? It's what the manual says.
-Bruce
3. Re: LDL Cholesterol calculation
- Posted by ghaberek (admin) 1 month ago
- 1127 views
axtens_bruce said...
But when I run it I get
C:\TEMP\ldl.ex:67 <0074>:: Errors resolving the following references: 'MININT' (ldl.ex:38) has not been declared. 'MAXINT' (ldl.ex:67) has not been declared.But aren't MININT and MAXINT supposed to internal? It's what the manual says.
That document is meant for anyone who wants to dive into the backend C code. Nothing there is exposed back to the frontend.
-Greg
4. Re: LDL Cholesterol calculation
- Posted by ghaberek (admin) 1 month ago
- 1143 views
Here's my version, which bakes the decision-making values into the table:
constant factor_table= { { -1, 100, 130,160,190,220,999}, { 50, 3.5, 3.4,3.3,3.3,3.2,3.1}, { 57, 4.0, 3.9,3.7,3.6,3.6,3.4}, { 62, 4.3, 4.1,4.0,3.9,3.8,3.6}, { 67, 4.5, 4.3,4.1,4.0,3.9,3.9}, { 72, 4.7, 4.4,4.3,4.2,4.1,3.9}, { 76, 4.8, 4.6,4.4,4.2,4.2,4.1}, { 80, 4.9, 4.6,4.5,4.3,4.3,4.2}, { 84, 5.0, 4.8,4.6,4.4,4.3,4.2}, { 88, 5.1, 4.8,4.6,4.5,4.4,4.3}, { 93, 5.2, 4.9,4.7,4.6,4.4,4.3}, { 97, 5.3, 5.0,4.8,4.7,4.5,4.4}, { 101, 5.4, 5.1,4.8,4.7,4.5,4.3}, { 106, 5.5, 5.2,5.0,4.7,4.6,4.5}, { 111, 5.6, 5.3,5.0,4.8,4.6,4.5}, { 116, 5.7, 5.4,5.1,4.9,4.7,4.5}, { 121, 5.8, 5.5,5.2,5.0,4.8,4.6}, { 127, 6.0, 5.5,5.3,5.0,4.8,4.6}, { 133, 6.1, 5.7,5.3,5.1,4.9,4.7}, { 139, 6.2, 5.8,5.4,5.2,5.0,4.7}, { 147, 6.3, 5.9,5.6,5.3,5.0,4.8}, { 155, 6.5, 6.0,5.7,5.4,5.1,4.8}, { 164, 6.7, 6.2,5.8,5.4,5.2,4.9}, { 174, 6.8, 6.3,5.9,5.5,5.3,5.0}, { 186, 7.0, 6.5,6.0,5.7,5.4,5.1}, { 202, 7.3, 6.7,6.2,5.8,5.5,5.2}, { 221, 7.6, 6.9,6.4,6.0,5.6,5.3}, { 248, 8.0, 7.2,6.6,6.2,5.9,5.4}, { 293, 8.5, 7.6,7.0,6.5,6.1,5.6}, { 400, 9.5, 8.3,7.5,7.0,6.5,5.9}, {13975,11.9,10.0,8.8,8.1,7.5,6.7} } -- CT, TG, HDL en g/L function martin_hopkins(atom CT, atom TG, atom HDL) integer lig=2, col=2, tg=floor(TG*100) -- tg, nonhdl en mg/dL atom factor=5.0, nonhdl=(CT-HDL)*100 while lig <= length(factor_table) and factor_table[lig][1] < tg do lig += 1 end while while col <= length(factor_table[1]) and factor_table[1][col] < nonhdl do col += 1 end while factor = factor_table[lig][col] return CT - HDL - (TG/factor) end function
-Greg