Skip to content

Instantly share code, notes, and snippets.

@DLu
Last active January 1, 2019 18:23
Show Gist options
  • Save DLu/39872970546b92ab1ff76e7d3775184b to your computer and use it in GitHub Desktop.
Save DLu/39872970546b92ab1ff76e7d3775184b to your computer and use it in GitHub Desktop.
WHO Growth Curve Calculation
/**
* Data from https://www.cdc.gov/growthcharts/who/boys_length_weight.htm
* and https://www.cdc.gov/growthcharts/who/girls_length_weight.htm
* Calculation from https://www.cdc.gov/nchs/data/nhsr/nhsr063.pdf
*
* Parameters:
* an age in months (floating point) in the range [0, 24),
* a weight in kg (floating point), and
* a sex (the string 'F' for female or something else for male)
*
* Linearly interpolates between the data from the above data tables for non-integer ages.
*
* Output: z-score
* If used as a Google Sheets script, you can calculate the percentile with 100*NORMDIST(ZSCORE,0,1,True)
*/
FEMALE = [{L: 0.3809, M: 3.2322, S: 0.14171},
{L: 0.1714, M: 4.1873, S: 0.13724},
{L: 0.0962, M: 5.1282, S: 0.13},
{L: 0.0402, M: 5.8458, S: 0.12619},
{L: -0.005, M: 6.4237, S: 0.12402},
{L: -0.043, M: 6.8985, S: 0.12274},
{L: -0.0756, M: 7.297, S: 0.12204},
{L: -0.1039, M: 7.6422, S: 0.12178},
{L: -0.1288, M: 7.9487, S: 0.12181},
{L: -0.1507, M: 8.2254, S: 0.12199},
{L: -0.17, M: 8.48, S: 0.12223},
{L: -0.1872, M: 8.7192, S: 0.12247},
{L: -0.2024, M: 8.9481, S: 0.12268},
{L: -0.2158, M: 9.1699, S: 0.12283},
{L: -0.2278, M: 9.387, S: 0.12294},
{L: -0.2384, M: 9.6008, S: 0.12299},
{L: -0.2478, M: 9.8124, S: 0.12303},
{L: -0.2562, M: 10.0226, S: 0.12306},
{L: -0.2637, M: 10.2315, S: 0.12309},
{L: -0.2703, M: 10.4393, S: 0.12315},
{L: -0.2762, M: 10.6464, S: 0.12323},
{L: -0.2815, M: 10.8534, S: 0.12335},
{L: -0.2862, M: 11.0608, S: 0.1235},
{L: -0.2903, M: 11.2688, S: 0.12369},
{L: -0.2941, M: 11.4775, S: 0.1239}]
MALE = [{L: 0.3487, M: 3.3464, S: 0.14602},
{L: 0.2297, M: 4.4709, S: 0.13395},
{L: 0.197, M: 5.5675, S: 0.12385},
{L: 0.1738, M: 6.3762, S: 0.11727},
{L: 0.1553, M: 7.0023, S: 0.11316},
{L: 0.1395, M: 7.5105, S: 0.1108},
{L: 0.1257, M: 7.934, S: 0.10958},
{L: 0.1134, M: 8.297, S: 0.10902},
{L: 0.1021, M: 8.6151, S: 0.10882},
{L: 0.0917, M: 8.9014, S: 0.10881},
{L: 0.082, M: 9.1649, S: 0.10891},
{L: 0.073, M: 9.4122, S: 0.10906},
{L: 0.0644, M: 9.6479, S: 0.10925},
{L: 0.0563, M: 9.8749, S: 0.10949},
{L: 0.0487, M: 10.0953, S: 0.10976},
{L: 0.0413, M: 10.3108, S: 0.11007},
{L: 0.0343, M: 10.5228, S: 0.11041},
{L: 0.0275, M: 10.7319, S: 0.11079},
{L: 0.0211, M: 10.9385, S: 0.11119},
{L: 0.0148, M: 11.143, S: 0.11164},
{L: 0.0087, M: 11.3462, S: 0.11211},
{L: 0.0029, M: 11.5486, S: 0.11261},
{L: -0.0028, M: 11.7504, S: 0.11314},
{L: -0.0083, M: 11.9514, S: 0.11369},
{L: -0.0137, M: 12.1515, S: 0.11426}]
function LMS_SCORE(age, weight, sex) {
index = Math.floor(age);
pct = age - index;
ipct = 1 - pct;
if (sex == 'F')
{
low = FEMALE[index];
high = FEMALE[index + 1];
}
else
{
low = MALE[index];
high = MALE[index + 1];
}
vals = {};
for (key in low)
{
vals[key] = ipct * low[key] + high[key] * pct;
}
return (Math.pow(weight/vals['M'], vals['L']) - 1) / (vals['L']*vals['S']);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment