@@ -3,16 +3,16 @@ window.PhenoAge = window.PhenoAge || {};
3
3
4
4
// Attach biomarkers to the namespace
5
5
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 }
16
16
] ;
17
17
18
18
// Helper function to parse input values
@@ -43,11 +43,30 @@ window.PhenoAge.calculateAgeFromDOB = function (birthDate) {
43
43
44
44
// Helper function to calculate PhenoAge based on biomarkers
45
45
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
+ }
47
65
48
66
// 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 ] ;
51
70
}
52
71
53
72
const b0 = - 19.9067 ;
0 commit comments