***HOMA-IR Approximates Average Blood Insulin Resistance in Console Example Demo for TCL***
 
This page is under development. Comments are welcome, but please load any comments in the comments section at the bottom of the page. Please include your wiki MONIKER and date in your comment with the same courtesy that I will give you. Aside from your courtesy, your wiki MONIKER and date as a signature and minimal good faith of any internet post are the rules of this TCL-WIKI. Its very hard to reply reasonably without some background of the correspondent on his WIKI bio page. Thanks, [gold] 20Aug2020

----

<<TOC>>

***Preface***
[gold] 1sep2021  Here are some calculations  for  converting  HOMA-IR measurement  from average blood glucose mg/dl over a 3 month period. Table is in US Units for Blood Glucose etc. Console program outputs data as table in TCL table format and comma delimited spreadsheet. 
----
***Introduction***
Here are TCL calculations on  the equation converting HOMO-IR from Fasting Blood Glucose mg/dl and insulin measures.  HOMA-IR standing for Homeostatic Model Assessment of Insulin Resistance  is an indirect measurement that tells you and your doctor how much insulin your pancreas needs to make to control your blood sugar levels and evaluate pancreas/liver functions. The formula is '''HOMA_IR = expr { $insulin * $glucose * $scale_factor} '''. $scale_factor is '''(1/405.)'''.  Example calculation as '''HOMA_IR = expr { $insulin * $glucose * $scale_factor }, expr { 4 * 100 * $scale_factor }, rounds to 1.0 '''.  Console program example demo was written on Windows 10,  working under TCL version 8.6 Table is in US Units for Blood Glucose etc. As a peg point,  5 HbA1c units converts to 100  mg/dl abbreviation for milligrams per deciliter. Note. This Diabetes Care field is rapidly changing, one  needs to check in at ADA professional.diabetes.org and pubmed search < HOMO-IR > for  the latest up to date  info.
---- 
European SI units as best understood.  The HOMA-IR calculations here requires U.S. standard units. 
======
To convert component terms ( $insulin & $glucose) from international S.I. units:
Insulin: pmol/L to uIU/mL, divide by (÷) 6
Glucose: mmol/L to mg/dL, multiply by (x) 18
======
----
***References:***
----
   * Wikipedia search engine < diabetes insulin resistance >
   * Wikipedia search engine < Richard K. Bernstein >
   * Wikipedia search engine <  Programming Examples  >
   * Google search engine < vaporware   >
   * Google search engine < Blood Glucose  insulin resistance   >
   * Book >> The Diabetes Code: Prevent and Reverse Type 2 Diabetes Naturally
   * [One Liners Programs Pie in the Sky] 
   * [One Liners] 
   * One Liners Programs Compendium [https://wiki.tcl-lang.org/page/One+Liners+Programs+Compendium++and+TCL+demo+examples+calculations%2C+numerical+analysis]
   *        WIKI BOOKS,  Programming_Examples pdf
   *        WIKI BOOKS, Tcl_Programming_Introduction pdf
   * google search engine <  HgA1c to Average Blood Glucose>
   * How Do You Calculate Your A1c?  diabetestalk.net 
   * BLOOD SUGAR HOW DO YOU CALCULATE YOUR A1C? DEC 5, 2017
   * [table]
   * The Diabetes Code: Prevent and Reverse Type 2 Diabetes Naturally
   * 2018 · 4.88 MB by Dr Jason Fung
   * Dr. Bernstein's Diabetes Solution: The Complete Guide to Achieving Normal Blood Sugars
   * 2007  by Richard K. Bernstein
   * care.diabetesjournals.org 2012
   * Measurement of Hemoglobin A1c , Diabetes Care
   * labs.selfdecode.com/blog/homa-ir
   * A new twist on the path to harmony
   * David B. Sacks, December 2012, full pdf available from ADA 
   * Translating the A1C Assay pdf, Richard Kahn and Vivian Fonseca, Diabetes Care, 2008
   * see ADA professional.diabetes.org diapro glucose_calc for up to date
   * see ADA professional.diabetes.org for up to date
   * Use of HOMA-IR to diagnose non-alcoholic fatty liver disease, pubmed search < HOMO-IR >
   * Non-Alcoholic Fatty Liver Disease in Children, pubmed search < HOMO-IR >
   * pubmed search < HOMO-IR children>
   * Insulin resistance index (HOMA-IR) in the differentiation of patients with non-alcoholic fatty liver disease 
   * mdcalc.com, many medical calculators
   * omnicalculator.com/health/homa-ir#homa-ir-result-interpretation
   * David R. Matthews, MD Look up many papers on pubmed. Esp,  Use and abuse of HOMA modeling
   * David R. Matthews, MD, 10-year follow-up of intensive glucose control in type 2 diabetes
----
David R. Matthews, MD is a Professor of Diabetic Medicine at the University of Oxford. He is the Deputy co-ordinator and member of the Executive and Policy Advisory Committees of the UK Prospective Study of Diabetes (UKPDS). David R. Matthews, MD is currently investigating the inter-relationships between insulin resistance and beta cell function, and the effects of a low carbohydrate diet in people with and without type 2 diabetes at Churchill Hospital with the Center of Diabetes, in the United Kingdom.
----
ADA Quotes. Therefore, to change glucose from mg/dL to mmol/L, one divides by 18.016 (usually rounded off to 18), and values are multiplied by 18 to switch from mmol/L to mg/dL. For example, 126 mg/dL is equivalent to 7.0 mmol/L, and 40 mg/dL is 2.2 mmol/L. 
----
   * Developing an HbA1c-Based Equation to Estimate Blood Glucose in Maintenance Hemodialysis Patients
   * Junichi Hoshino, MD, MPH1,2,3, Miklos Z. Molnar, MD, PHD1,
   * September 2020
----
ADA Quotes. Developing an HbA1c-Based Equation to Estimate Blood Glucose in Maintenance Hemodialysis Patients,2013. Some equations showing a good correlation between HbA1c and average BG (AG) levels.The Diabetes Control and Complications Trial [DCCT] formula is Average Blood Glucose  = expr { 35.6 * HbA1c − 77.3}  < in milligrams per deciliter>.
----
----
***Testcases Section***  

In planning any software, it is advisable to gather a number of testcases to check the results of the program.
----
**** Testcase 1,   ****
---- 
Example calculation for 4 insulin and 100 glucose. Calculation as '''HOMA_IR = expr { $insulin * $glucose * $scale_factor }, expr { 4 * 100 * $scale_factor }, rounds to 1.0 '''. Any HOMA_IR result above the cut-off value of 2  suggests insulin resistance. However, the  combined lab blood results have to be evaluated by your doctor MD. 2nd set of calculations reported that HOMA_IR approximates 0.99 or 1.0 rounded. Quicki index =~ 0.38. '''QUICKI_index= 1/(log(insulin) + log(glucose))''', different formula. For the glucose concentration in mmol/L, Use '''HOMA-IR = (insulin * glucose) / 22.5''' For the Blood Glucose in mg/dL. '''HOMA-IR = (insulin * glucose ) / 405.'''  In both cases,  the insulin units is in mU/L.
----
======
    ;# formula QUICKI_index insulin resistance = 1/(log(insulin) + log(glucose)), decimal logs 
    proc QUICKI_INDEX_IR { insulin  glucose } { return [ expr { 1./(log10($insulin) + log10($glucose))} ] }
    ;# Usage set answer [  QUICKI_INDEX_IR 4. 100. ]
======
----
%| table 1|  | printed in|TCL format |% 
%| homa_IR_2 units | insulin units |glucose units  |comment, if any|% 
&| 0.81500 |  3.3000  | 100. | |&
&| 0.84000 |  3.4000  | 100. | |&
&| 0.86400 |  3.5000  | 100. | |&
&| 0.88900 |  3.6000  | 100. | |&
&| 0.91400 |  3.7000  | 100. | |&
&| 0.93800 |  3.8000  | 100. | |&
&| 0.96300 |  3.9000  | 100. | |&
&| 0.98800 |  4.0000  | 100. | answer for testcase 1  |&
&| 1.0120 |  4.1000  | 100. | |&
&| 1.0370 |  4.2000  | 100. | |& 
----
----
**** Testcase 2,   ****
---- 
Example calculation for 6 insulin and 110 glucose. Evals HOMA_IR approximates 1.63. Quicki index =~ 0.35. 
----
**** Testcase 3,   ****
---- 
Example calculation for 2 insulin and 90 glucose. Evals HOMA_IR approximates 0.44. Quicki index =~ 0.44. 
---- 
----
**** Testcase 4,  Protocol for A1c  ****
---- 
Protocol for A1c of 5.0 and insulin of 4. A1c of 5.0 converts to average Blood Glucose of 96.8. Example calculation for 4 insulin and 96.8 glucose evals to HOMA-IR of 0.48. Quicki index =~ 0.44 
----
***Screenshots Section***
----
****figure 1. Screenshot, HOMA_IR_Average_Blood_Insulin_resistance ****
----

----
----   
[HOMA_IR_Average_Blood_Insulin_resistance_2]
----
***Appendix TCL programs and scripts ****

*** Pretty Print Version*** 

----
======        #  pretty print from autoindent and ased editor
        #  Convert homa_IR_2 from Average Blood Glucose mg/dl V2
        #  Console program example demo
        #  written on Windows 10 on  TCL
        #  working under TCL version 8.6
        #  gold on TCL Club , 30aug2021
        #  Each homa_IR_2 reading usually from
        #  limits of 0.4 to 11
        #  Roughly 5 HbA1c converts to 100
        #  mg/dl abbrev. for milligrams per deciliter
        #  mmol/L abbrev. for milligrams per Liter
        package require Tk
        package require math::numtheory
        package require math::constants
        package require math::trig
        package require math
        namespace path {::tcl::mathop ::tcl::mathfunc math::numtheory math::trig math::constants }
        set tclprecision 17
        console show        #  following dresses up console output to easy eye
        console eval {.console config -bg palegreen}
        console eval {.console config -font {fixed 20 bold}}
        console eval {wm geometry . 40x20}
        set tclprecision 17        #  conversion unit formulas in procs
        #  HOMA_IR = expr { $insulin * $glucose * $scale_factor}
        proc HOMA_IR2 { insulin  glucose }  {
            set scale_factor [ expr { 1. / 405. } ]
            return [expr { $insulin * $glucose * $scale_factor}]}        #  hbA1c_convert_to_average_blood_glucose mg/dl  HbA1c
        proc a1c hbA1c {  expr { 35.6*$hbA1c -77.3} }        #  convert mg/dl to mmol/L average blood glucose
        #  some papers round off 18.016 to mgdl/18.
        proc mgdl_to_mmoll mgdl {  expr { $mgdl/18.0 } }        #  convert  mmol/L to mg/dl average blood glucose
        proc mmoll_to_mgdl mmoll {  expr { $mmoll*18.0 } }        #  proc precisionx used to round off floating point numbers
        proc precisionx {precision float}  {            #   tcl:wiki:Floating-point formatting, <AM>
            #  select numbers only, not used on every number.
            set x [ expr {round( 10 ** $precision * $float) / (10.0 ** $precision)} ]            #   rounded or clipped to nearest 5ird significant figure
            set x [ format "%#.5g" $x ]
            return $x
        }
        proc table_format_out  n {
            set sum 0            #  initial  level
            set count 0.0
            set glucose 100.
            puts "%| table|  | printed in|TCL format |% "
            puts "%| homa_IR_2 units | insulin units |glucose units  |comment, if any|% "            #  adapted proc from <RS>
            #  printout in TCL WIKI format table
            for { set i 1 } { $i <= $n } { incr i } {
                set count [+ $count .1]
                set insulin $count
                set homa_IR_2 [ HOMA_IR2 $insulin $glucose  ]
                set insulin [ precisionx 3 $insulin ]
                set glocose [ precisionx 3 $glucose ]
                puts "&| [ precisionx 3  $homa_IR_2  ] |  $insulin  | $glucose | |&"
                incr sum $i
            }
            return $sum
        }        puts "  Console wrapper for solution proc"
        puts "  ***************************"
        puts "  ***************************"
        table_format_out 90
        wm title . "Homa_IR_2 V2 "
        #  end of working deck
        #  add cosmetics below to bottom of file
        console eval {.console config -bg palegreen}
        console eval {.console config -font {fixed 20 bold}}
        console eval {wm geometry . 40x20}
        console eval {wm title . " Report for Homa_IR_2  "}
        console eval {. configure -background orange -highlightcolor brown -relief raised -border 30}
======
----
----
*** Conversion unit formulas in one line TCL procs ***
----
----
======    ;#  conversion unit formulas in one line TCL procs
    ;#  HOMA-IR standing for Homeostatic Model Assessment of Insulin Resistance 
    ;#  HOMA_IR = expr { $insulin * $glucose * $scale_factor}
    ;#  fasting blood insulin in units  uIU/mL
    ;#  fasting blood glucose in units mg/dL
    proc HOMA_IR2 { insulin  glucose }  {
            set scale_factor [ expr { 1. / 405. } ]
            return [expr { $insulin * $glucose * $scale_factor}]}    ;#  HOMA-IR calculations here requires U.S. standard units.
    ;#  European SI units as best understood. 
    ;#  To convert component terms of  HOMA-IR ( $insulin & $glucose)
    ;#  from international S.I. units:
    ;#  Insulin: pmol/L to uIU/mL, divide by (÷) 6
    ;#  Glucose: mmol/L to mg/dL, multiply by (x) 18
    ;#  hbA1c_convert_to_average_blood_glucose mg/dl  HbA1c
    ;#  HbA1c test is a simple blood test that measures your 
    ;#  average blood sugar levels over the past 3 months.
    ;#  As a peg point, 5 HbA1c units converts to 100 mg/dl,
    ;#  mg/dl is abbreviation for milligrams per deciliter.
    proc a1c hbA1c {  expr { 35.6*$hbA1c -77.3} }    ;#  convert mg/dl to mmol/L average blood glucose
    ;#   European SI units conversion on blood glucose
    ;#  some papers round off 18.016 to mgdl/18.
    proc mgdl_to_mmoll mgdl {  expr { $mgdl/18.0 } }    ;#  convert  mmol/L to mg/dl average blood glucose
    proc mmoll_to_mgdl mmoll {  expr { $mmoll*18.0 } }    ;#  formula QUICKI_index insulin resistance = 1/(log(insulin) + log(glucose)), decimal logs 
    proc QUICKI_INDEX_IR { insulin  glucose } { return [ expr { 1./(log10($insulin) + log10($glucose))} ] }    ;#  Usage set answer [  QUICKI_INDEX_IR 4. 100. ] ;#  eval 0.38
======
----
----
 
**Hidden Comments Section**

<<discussion>>
Please include your wiki MONIKER and date in your comment with the same courtesy that I will give you. Thanks, [gold] 12Aug2020 ---- 
----
[gold] 9/27/2021. Switched some comment signs ;# to #. This a big file. Check earlier editions, if not compatible. Maybe obvious, but this page was written on Windows10 Tcl ports including ActiveTCL.  I assume reader can cut and paste on screen, what the reader needs, and tootle on to his own project and own contribution pages to the TCL Wiki.
----     
----       
                              
----
<<categories>> Numerical Analysis | Toys | Calculator | Mathematics| Example| Toys and Games | Games | Application | GUI
----
<<categories>> Development | Concept| Algorithm  | Biology