public void GetPercentile_Success(double z, double p) { double result = StatisticsHelper.CalculatePercentile(z); double diff = Math.Abs(p - result); Assert.True(diff < PERCENTILE_TOLERANCE); }
public void CalculateZScoresWho2007() { var who2007 = new AnthStat.Statistics.WHO2007(); double ageMonths = double.Parse(TxtEdadMeses.Text); double Weight = double.Parse(TxtPeso.Text); double Lenght = double.Parse(TxtTalla.Text); double LenghtMeters = Lenght / 100; double imc = Weight / (LenghtMeters * LenghtMeters); double z = 0.0; double x = 0.0; double y = 0.0; TxtIMCCalculado.Text = Math.Round(imc, 2).ToString(); if (txtSexo.Text == "Masculino" || txtSexo.Text == "Masculino\t") { if (who2007.TryCalculateZScore(indicator: Indicator.BodyMassIndexForAge, measurement: imc, age: ageMonths, sex: Sex.Male, z: ref z)) { double p = StatisticsHelper.CalculatePercentile(z); TxtIMCEdadWho2007Z.Text = Math.Round(z, 2).ToString(); TxtIMCEdadWho2007P.Text = Math.Round(p, 2).ToString(); } if (who2007.TryCalculateZScore(indicator: Indicator.WeightForAge, measurement: Weight, age: ageMonths, sex: Sex.Male, z: ref x)) { double p = StatisticsHelper.CalculatePercentile(x); TxtPesoEdadWho2007Z.Text = Math.Round(x, 2).ToString(); TxtPesoEdadWho2007P.Text = Math.Round(p, 2).ToString(); } if (who2007.TryCalculateZScore(indicator: Indicator.HeightForAge, measurement: Lenght, age: ageMonths, sex: Sex.Male, z: ref y)) { double p = StatisticsHelper.CalculatePercentile(y); TxtTallaEdadWho2007Z.Text = Math.Round(y, 2).ToString(); TxtTallaEdadWho2007P.Text = Math.Round(p, 2).ToString(); } } else if (txtSexo.Text == "Femenino" || txtSexo.Text == "Femenino\t") { if (who2007.TryCalculateZScore(indicator: Indicator.BodyMassIndexForAge, measurement: imc, age: ageMonths, sex: Sex.Female, z: ref z)) { double p = StatisticsHelper.CalculatePercentile(z); TxtIMCEdadWho2007Z.Text = Math.Round(z, 2).ToString(); TxtIMCEdadWho2007P.Text = Math.Round(p, 2).ToString(); } if (who2007.TryCalculateZScore(indicator: Indicator.WeightForAge, measurement: Weight, age: ageMonths, sex: Sex.Female, z: ref x)) { double p = StatisticsHelper.CalculatePercentile(x); TxtPesoEdadWho2007Z.Text = Math.Round(x, 2).ToString(); TxtPesoEdadWho2007P.Text = Math.Round(p, 2).ToString(); } if (who2007.TryCalculateZScore(indicator: Indicator.HeightForAge, measurement: Lenght, age: ageMonths, sex: Sex.Female, z: ref y)) { double p = StatisticsHelper.CalculatePercentile(y); TxtTallaEdadWho2007Z.Text = Math.Round(y, 2).ToString(); TxtTallaEdadWho2007P.Text = Math.Round(p, 2).ToString(); } } }
/// <summary> /// Calculates both the Zscore and Percentile. /// </summary> /// <param name="indicator">The growth indicator</param> /// <param name="measurement">The specified measured value</param> /// <param name="ageInDays">The age in total days</param> /// <param name="sex">Human sex designation per ISO/IEC 5218 code</param> /// <returns>Returns the z-score and percentile for a growth measure using a specified value.</returns> public static async Task <Tuple <double, double> > GetScore(Indicator indicator, double measurement, double ageInDays, Sex sex) { WHO2006 who2006 = new(); double z = 0.0; double p = 0.0; if (who2006.TryCalculateZScore(indicator, measurement, ageInDays, sex, z: ref z)) { p = await Task.FromResult(StatisticsHelper.CalculatePercentile(z)); } z = Math.Round(z, 2); p = Math.Round(p, 1); return(Tuple.Create(z, p)); }
private IActionResult Calculate(Sex sex, Indicator indicator, double measurement1, double measurement2) { double z = default(double); bool success = _cdcReference.TryCalculateZScore(Indicator.BodyMassIndexForAge, measurement1, measurement2, sex, ref z); if (success) { var scoreResult = new ZScoreResult() { Z = z, P = StatisticsHelper.CalculatePercentile(z), Reference = "CDC2000", Sex = sex, Indicator = indicator, InputMeasurement1 = measurement1, InputMeasurement2 = measurement2 }; return(Ok(scoreResult)); } else { return(BadRequest()); } }
/// <summary> /// Calculates the percentile using z-score. /// </summary> /// <param name="zScore"></param> /// <returns>Returns the percentile using z-score.</returns> public async Task <double> CalculatePercentile(double zScore) { double p = await Task.FromResult(StatisticsHelper.CalculatePercentile(zScore)); return(p); }
public void CalculateZScoresWho2006() { var who2006 = new AnthStat.Statistics.WHO2006(); double ageDays = double.Parse(TxtEdad.Text); double Weight = double.Parse(TxtPeso.Text); double Lenght = double.Parse(TxtTalla.Text); double CC = double.Parse(TxtCC.Text); double CMB = double.Parse(TxtCMB.Text); double Muac = double.Parse(TxtTricep.Text); double LenghtMeters = Lenght / 100; double imc = Weight / (LenghtMeters * LenghtMeters); TxtIMCCalculado.Text = Math.Round(imc, 2).ToString(); double z = 0.0; double x = 0.0; double y = 0.0; double w = 0.0; if (txtSexo.Text == "Masculino" || txtSexo.Text == "Masculino\t") { if (who2006.TryCalculateZScore(indicator: Indicator.BodyMassIndexForAge, measurement1: imc, measurement2: ageDays, sex: Sex.Male, z: ref z)) { TxtZIMC.Text = Math.Round(z, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(z); TxtImc.Text = Math.Round(p, 1).ToString(); } if (ageDays > 720) { if (who2006.TryCalculateZScore(indicator: Indicator.WeightForHeight, measurement1: Weight, measurement2: Lenght, sex: Sex.Male, z: ref x)) { TxtZPesoTalla.Text = Math.Round(x, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(x); TxtPesoTalla.Text = Math.Round(p, 1).ToString(); } } if (ageDays < 720) { if (who2006.TryCalculateZScore(indicator: Indicator.WeightForLength, measurement1: Weight, measurement2: Lenght, sex: Sex.Male, z: ref x)) { TxtZPesoTalla.Text = Math.Round(x, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(x); TxtPesoTalla.Text = Math.Round(p, 1).ToString(); } } if (who2006.TryCalculateZScore(indicator: Indicator.WeightForAge, measurement1: Weight, measurement2: ageDays, sex: Sex.Male, z: ref y)) { TxtZPesoEdad.Text = Math.Round(y, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(y); TxtPesoEdad.Text = Math.Round(p, 1).ToString(); } if (who2006.TryCalculateZScore(indicator: Indicator.LengthForAge, measurement1: Lenght, measurement2: ageDays, sex: Sex.Male, z: ref w)) { TxtZTallaEdad.Text = Math.Round(w, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(w); TxtTallaEdad.Text = Math.Round(p, 1).ToString(); } if (who2006.TryCalculateZScore(indicator: Indicator.HeadCircumferenceForAge, measurement1: CC, measurement2: ageDays, sex: Sex.Male, z: ref w)) { TxtZCC.Text = Math.Round(w, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(w); TxtCCP.Text = Math.Round(p, 1).ToString(); } if (who2006.TryCalculateZScore(indicator: Indicator.ArmCircumferenceForAge, measurement1: CMB, measurement2: ageDays, sex: Sex.Male, z: ref w)) { TxtZMuac.Text = Math.Round(w, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(w); TxtMuacP.Text = Math.Round(p, 1).ToString(); } if (who2006.TryCalculateZScore(indicator: Indicator.TricepsSkinfoldForAge, measurement1: double.Parse(TxtTricep.Text), measurement2: ageDays, sex: Sex.Male, z: ref w)) { TxtTSFZ.Text = Math.Round(w, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(w); TxtTSFP.Text = Math.Round(p, 1).ToString(); } if (who2006.TryCalculateZScore(indicator: Indicator.SubscapularSkinfoldForAge, measurement1: double.Parse(TxtSSF.Text), measurement2: ageDays, sex: Sex.Male, z: ref w)) { TxtSSFZ.Text = Math.Round(w, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(w); TxtSSFP.Text = Math.Round(p, 1).ToString(); } } else if (txtSexo.Text == "Femenino" || txtSexo.Text == "Femenino\t") { if (who2006.TryCalculateZScore(indicator: Indicator.BodyMassIndexForAge, measurement1: imc, measurement2: ageDays, sex: Sex.Female, z: ref z)) { TxtZIMC.Text = Math.Round(z, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(z); TxtImc.Text = Math.Round(p, 1).ToString(); } if (ageDays > 720) { if (who2006.TryCalculateZScore(indicator: Indicator.WeightForHeight, measurement1: Weight, measurement2: Lenght, sex: Sex.Female, z: ref x)) { TxtZPesoTalla.Text = Math.Round(x, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(x); TxtPesoTalla.Text = Math.Round(p, 1).ToString(); } } if (ageDays < 720) { if (who2006.TryCalculateZScore(indicator: Indicator.WeightForLength, measurement1: Weight, measurement2: Lenght, sex: Sex.Female, z: ref x)) { TxtZPesoTalla.Text = Math.Round(x, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(x); TxtPesoTalla.Text = Math.Round(p, 1).ToString(); } } if (who2006.TryCalculateZScore(indicator: Indicator.WeightForAge, measurement1: Weight, measurement2: ageDays, sex: Sex.Female, z: ref y)) { TxtZPesoEdad.Text = Math.Round(y, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(y); TxtPesoEdad.Text = Math.Round(p, 1).ToString(); } if (who2006.TryCalculateZScore(indicator: Indicator.LengthForAge, measurement1: Lenght, measurement2: ageDays, sex: Sex.Female, z: ref w)) { TxtZTallaEdad.Text = Math.Round(w, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(w); TxtTallaEdad.Text = Math.Round(p, 1).ToString(); } if (who2006.TryCalculateZScore(indicator: Indicator.HeadCircumferenceForAge, measurement1: CC, measurement2: ageDays, sex: Sex.Female, z: ref w)) { TxtZCC.Text = Math.Round(w, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(w); TxtCCP.Text = Math.Round(p, 1).ToString(); } if (who2006.TryCalculateZScore(indicator: Indicator.ArmCircumferenceForAge, measurement1: CMB, measurement2: ageDays, sex: Sex.Female, z: ref w)) { TxtZMuac.Text = Math.Round(w, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(w); TxtMuacP.Text = Math.Round(p, 1).ToString(); } if (who2006.TryCalculateZScore(indicator: Indicator.TricepsSkinfoldForAge, measurement1: double.Parse(TxtTricep.Text), measurement2: ageDays, sex: Sex.Female, z: ref w)) { TxtTSFZ.Text = Math.Round(w, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(w); TxtTSFP.Text = Math.Round(p, 1).ToString(); } if (who2006.TryCalculateZScore(indicator: Indicator.SubscapularSkinfoldForAge, measurement1: double.Parse(TxtSSF.Text), measurement2: ageDays, sex: Sex.Female, z: ref w)) { TxtSSFZ.Text = Math.Round(w, 2).ToString(); double p = StatisticsHelper.CalculatePercentile(w); TxtSSFP.Text = Math.Round(p, 1).ToString(); } } }
/// <summary> /// Calculates the percentile using z-score. /// </summary> /// <param name="zScore"></param> /// <returns>Returns the percentile using z-score.</returns> public double CalculatePercentile(double zScore) { double p = StatisticsHelper.CalculatePercentile(zScore); return(p); }
static void Main(string[] args) { var cdc2000 = new CDC2000(); var who2006 = new WHO2006(); var who2007 = new WHO2007(); // Calculates a BMI-for-age z-score using CDC 2000 double ageMonths = 26; double z = 0.0; double bmi = 18.0; if (cdc2000.TryCalculateZScore(indicator: Indicator.BodyMassIndexForAge, measurement1: bmi, measurement2: ageMonths, sex: Sex.Female, z: ref z)) { double p = StatisticsHelper.CalculatePercentile(z); z = Math.Round(z, 2); p = Math.Round(p, 2); Console.WriteLine($"[CDC 2000] - {ageMonths} month old female with BMI = {bmi} has z-score of {z} and percentile of {p}"); } else { Console.WriteLine($"{ageMonths} is a valid age in months for the CDC 2000 BMI-for-age indicator."); } // Calculates a BMI-for-age z-score using WHO 2006 double ageDays = 32; bmi = 16; if (who2006.TryCalculateZScore(indicator: Indicator.BodyMassIndexForAge, measurement1: bmi, measurement2: ageDays, sex: Sex.Female, z: ref z)) { double p = StatisticsHelper.CalculatePercentile(z); z = Math.Round(z, 2); p = Math.Round(p, 2); Console.WriteLine($"[WHO 2006] - {ageDays} day old female with BMI = {bmi} has z-score of {z} and percentile of {p}"); } else { Console.WriteLine($"{ageMonths} is a valid age in days for the WHO 2006 BMI-for-age indicator."); } // Calculates a BMI-for-age z-score using WHO 2007 ageMonths = 64; bmi = 17; if (who2007.TryCalculateZScore(indicator: Indicator.BodyMassIndexForAge, measurement: bmi, age: ageMonths, sex: Sex.Female, z: ref z)) { double p = StatisticsHelper.CalculatePercentile(z); z = Math.Round(z, 2); p = Math.Round(p, 2); Console.WriteLine($"[WHO 2007] - {ageMonths} month old male with BMI = {bmi} has z-score of {z} and percentile of {p}"); } else { Console.WriteLine($"{ageMonths} is a valid age in months for the WHO 2007 BMI-for-age indicator."); } Console.WriteLine(); // If interested in performance tests, see below TestCDC2000ComputeSpeed(true); // forces test to use interpolation of L, M, and S values (more computationally expensive) TestCDC2000ComputeSpeed(false); // forces test to never use interpolation Console.WriteLine(); TestWHO2006ComputeSpeed(); // WHO 2006 standard doesn't typically need interpolation since age is measured in days, and trying to interpolate LMS values between e.g. day 66 and 67 is not worthwhile Console.WriteLine(); TestWHO2007ComputeSpeed(true); // forces test to use interpolation of L, M, and S values (more computationally expensive) TestWHO2007ComputeSpeed(false); // forces test to never use interpolation }