Skip to content

Commit 97dbdf8

Browse files
committed
cap biomarkers
1 parent 115e2c4 commit 97dbdf8

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

LongevityWorldCup.Website/wwwroot/js/pheno-age.js

+32-13
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ window.PhenoAge = window.PhenoAge || {};
33

44
// Attach biomarkers to the namespace
55
window.PhenoAge.biomarkers = [
6-
{ id: 'age', name: 'Age', coeff: 0.0804 },
7-
{ id: 'albumin', name: 'Albumin', coeff: -0.0336 },
8-
{ id: 'creatinine', name: 'Creatinine', coeff: 0.0095 },
9-
{ id: 'glucose', name: 'Glucose', coeff: 0.1953 },
10-
{ id: 'crp', name: 'C-reactive protein', coeff: 0.0954 },
11-
{ id: 'wbc', name: 'White blood cell count', coeff: 0.0554 },
12-
{ id: 'lymphocyte', name: 'Lymphocytes', coeff: -0.012 },
13-
{ id: 'mcv', name: 'Mean corpuscular volume', coeff: 0.0268 },
14-
{ id: 'rcdw', name: 'Red cell distribution width', coeff: 0.3306 },
15-
{ id: 'ap', name: 'Alkaline phosphatase', coeff: 0.0019 }
6+
{ id: 'age', name: 'Age', coeff: 0.0804 }, // Age has no known lower cap
7+
{ id: 'albumin', name: 'Albumin', coeff: -0.0336, cap: 50 },
8+
{ id: 'creatinine', name: 'Creatinine', coeff: 0.0095, cap: 60 },
9+
{ id: 'glucose', name: 'Glucose', coeff: 0.1953, cap: 4 },
10+
{ id: 'crp', name: 'C-reactive protein', coeff: 0.0954 }, // CRP has no known lower cap
11+
{ id: 'wbc', name: 'White blood cell count', coeff: 0.0554, cap: 4.5 },
12+
{ id: 'lymphocyte', name: 'Lymphocytes', coeff: -0.012, cap: 40 },
13+
{ id: 'mcv', name: 'Mean corpuscular volume', coeff: 0.0268, cap: 85 },
14+
{ id: 'rcdw', name: 'Red cell distribution width', coeff: 0.3306, cap: 11.5 },
15+
{ id: 'ap', name: 'Alkaline phosphatase', coeff: 0.0019, cap: 50 }
1616
];
1717

1818
// Helper function to parse input values
@@ -43,11 +43,30 @@ window.PhenoAge.calculateAgeFromDOB = function (birthDate) {
4343

4444
// Helper function to calculate PhenoAge based on biomarkers
4545
window.PhenoAge.calculatePhenoAge = function (markerValues, coefficients) {
46-
let rollingTotal = 0;
46+
// Cap marker values to reference ranges
47+
let cappedMarkerValues = [];
48+
for (let i = 0; i < markerValues.length; i++) {
49+
if (i == 0 || i == 4) {
50+
// Age marker is not capped
51+
// CRP is not capped
52+
cappedMarkerValues.push(markerValues[i]);
53+
}
54+
else {
55+
if (window.PhenoAge.biomarkers[i].coeff < 0) {
56+
var cappedValue = Math.min(markerValues[i], window.PhenoAge.biomarkers[i].cap);
57+
cappedMarkerValues.push(cappedValue);
58+
}
59+
else {
60+
var cappedValue = Math.max(markerValues[i], window.PhenoAge.biomarkers[i].cap);
61+
cappedMarkerValues.push(cappedValue);
62+
}
63+
}
64+
}
4765

4866
// Sum all coefficients multiplied by the respective marker values
49-
for (let i = 0; i < markerValues.length; i++) {
50-
rollingTotal += markerValues[i] * coefficients[i];
67+
let rollingTotal = 0;
68+
for (let i = 0; i < cappedMarkerValues.length; i++) {
69+
rollingTotal += cappedMarkerValues[i] * coefficients[i];
5170
}
5271

5372
const b0 = -19.9067;

0 commit comments

Comments
 (0)