***HbA1c Approximates Average Blood Glucose in Console Example Demo for TCL table format V2*** 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] 01JAN2024 ---- <> ***Preface*** [gold] 20aug2020 Here are some calculations for converting HbA1c measurement to average blood glucose mg/dl over a 3 month period. Console program outputs data as table in TCL table format and comma delimited spreadsheet. ---- ***Introduction*** Here are TCL calculations on the equation converting HbA1c to Average Blood Glucose mg/dl. Console program example demo was written on Windows 10, working under TCL version 8.6 20aug2020. Each HbA1c reading usually from limits of 4.0 to 11 has an equivalent average blood glucose over a 3 month period. ADA formula from Diabetes Care, 2012. As 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 for the latest up to date info. ---- ---- ***References:*** ---- * Wikipedia search engine < diabetes > * Wikipedia search engine < Richard K. Bernstein > * Wikipedia search engine < Programming Examples > * Google search engine < vaporware > * Google search engine < Blood Glucose > * 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 * Measurement of Hemoglobin A1c * 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 ---- 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. The math for the testcases can be checked by pasting statements in the TCL console. Aside from the TCL calculator display, when one presses the report button on the calculator, one will have console show access to the capacity functions (subroutines). **** Testcase 1 **** ====== Problem 1. sum = 114+120+92+98+92+109 = 625, average here taken over 3 days average = (114+120+92+98+92+109)/6=104.166 average 104.166 converts to average A1c of 5.3 on the web tool ( 104.166 +46.7 )/28.7=5.25665505226, hand calculations ====== **** Testcase 2 **** ====== Problem 2 sum = 118+114+101+100+103+106 =642 , average here taken over 3 days average= (118+114+101+100+103+106)/6=107 average 107 converts to average A1c of 5.4 on the web tool Formula for average A1C = ( eAG +46.7 )/28.7 = subbing ( 107 +46.7 )/28.7 =5.37860627178 ( 107.666 +46.7 )/28.7=5.37860627178 hand calculations ====== **** Testcase 3 **** ====== Problem 3 sum = 99+102+108+120+109+108= 646 , average here taken over 3 days average= (99+102+108+120+109+108)/6= 107.666 average 107.666 converts to average A1c of 5.4 on the web tool Formula for average A1C = ( eAG +46.7 )/28.7 = subbing ( 107.666 +46.7 )/28.7 =5.3554 hand calculations ====== **** Testcase 4 **** ====== Problem 4 sample = average sum = 96 + 90 + 87 + 101 + 100 + 88 = 562 562/6 = 93.6666 average glucose level, 93.7 rounded conversion on net page , 93.7 glucose average converts to 4.9 HbA1C, average, using net tool Formula for average A1C = ( eAG +46.7 )/28.7 = subbing ( 93.7 +46.7 )/28.7 =5.3554 hand calculations formula = ( 93.7 +46.7 )/28.7= 4.89198606272, hand calculations ====== ---- **** Testcase 5 **** ====== Problem 5 3 Hamburger meals over a day, testing Glucose Meter response breakfast starts at BG 93, after hour BG is 105, BG raises 12 points lunch starts at BG 100, after hour BG is 99, BG dropped one point supper starts at BG 84, after hour BG is 88, BG raises 4 points sum = 93+105+100+99+84+88= 569 average BG =(93+105+100+99+84+88)/6= 94.8333333 average A1c = ( 94.8333 +46.7 )/28.7 = 4.93147 , hand calculations BG ideal for adult male 83, calculating = (83 +46.7 )/28.7= 4.51916 average A1C ====== 1/3 pound hamburger in George Foreman Grill. Just hamburger and no bun and extra fixings. Normally one would add non starchy veggies and fiber. Caffeine and coffee will confuse issues, raising BG by 5-14 points. Very fit individual has been low carb for a least 6 years and very nearly normal glucose metabolism for male adult. Normal metabolism or BG ideal for adult male is estimated to be BG of 83 and A1c of 4.5 , reference from Dr. Bernstein. ---- **** Testcase 6 **** ====== Problem 6 entered 1/2/2024 Sum of 5 readings over a day. Search engine math >>>>[88+98+91+92+91+ 93] = 462 correct sum over a day, ---- Search engine math >>>> ( 88+98+91+92+91+ 93 ) / 5 = 92.4 correct sum --- Search engine math >>>> ( (88+98+91+92+91+ 93) / 5.) + 46.7) / 28.7 ---- 5.48083624 correct ---- Note. This formula uses average BG readings from a home glucometer, not as accurate as lab blood test. Testcase samples over one day only, but over three days would be more accurate, in opinion, Results may be useful as a check on home glucometer results. ---- Formula for average A1C = ( eAG +46.7 )/28.7 ---- formula = subbing hand calculations ---- ---- Note. Additional significant figures are used to check the TCL calculator, not to infer the accuracy of inputs and product reports. Meaning here, round to nearest tenth 0.1. ---- ====== ---- ***Screenshots Section*** ---- ****figure 1. Screenshot, HgA1c_Average_Blood_Glucose **** ---- ---- ---- ---- [HgA1c_Average_Blood_Glucose] ======= ---- ---- ****Appendix TCL programs and scripts **** **** Pretty Print Version*** ---- ====== ;# pretty print from autoindent and ased editor ;# Convert HbA1c to 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 , 20aug2020 ;# Each HbA1c reading usually from ;# limits of 4.0 to 11 ;# has an equivalent average blood glucose ;# over a 3 month period. ;# formula from Diabetes Care, 2012. ;# 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 ;# 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, ;# 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 hbA1c level set count 4.0 puts "%| table| | printed in|TCL format |% " puts "%| HbA1c units | mg/dl units |conv. mmol/L units |comment, if any|% " ;# adapted proc from ;# printout in TCL WIKI format table for { set i 1 } { $i <= $n } { incr i } { set count [+ $count .1] set mgdl5 [ precisionx 3 [ a1c $count ]] set mmoll [ precisionx 3 [mgdl_to_mmoll [ a1c $count ]]] puts "&| [ precisionx 3 $count ] | $mgdl5 | $mmoll | |&" incr sum $i } return $sum } proc comma_delimit_format n { set sum 0 ;# initial hbA1c level set count 4.0 puts "table, , printed in, TCL format " puts "HbA1c units , mg/dl units , conv. mmol/L units, comment, if any " ;# adapted proc from ;# printout in TCL comma delimited format for { set i 1 } { $i <= $n } { incr i } { set count [+ $count .1] set mgdl5 [ precisionx 3 [ a1c $count ]] set mmoll [ precisionx 3 [mgdl_to_mmoll [ a1c $count ]]] puts "[ precisionx 3 $count ] , $mgdl5, $mmoll , ," incr sum $i } return $sum } puts " Console wrapper for solution proc" puts " ***************************" puts " ***************************" table_format_out 90 comma_delimit_format 90 ;# 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** <> Please include your wiki MONIKER and date in your comment with the same courtesy that I will give you. Thanks, [gold] 12Aug2020 x ---- <> Numerical Analysis | Toys | Calculator | Mathematics| Example| Toys and Games | Games | Application | GUI ---- <> Development | Concept| Algorithm | Biology