public Double getNearestAtRisk ( double t ) { Integer index = 0 ; /* String timeValue = t + ""; String format = "#"; int numDecimals = 0; int decimalIndex = timeValue.indexOf("."); if (decimalIndex > 0) { for (int i = timeValue.length() - 1; i > decimalIndex; i--) { if (timeValue.charAt(i) == '0' && numDecimals == 0) { continue; } if (i == decimalIndex - 1) { format = format + ".#"; } else { format = format + "#"; } } } */ DecimalFormat newFormat = new DecimalFormat ( "#.#" ) ; //used to round on expected precision of time. Not correct but trying to match the other packages for ( int i = 0 ; i < time . size ( ) ; i ++ ) { Double compareTime = time . get ( i ) ; // compareTime = new Double(Math.round(compareTime)); //this is rounding up so that we stop on the first match trying to get this to match another report. Not correct or the other report is wrong compareTime = Double . valueOf ( newFormat . format ( compareTime ) ) ; if ( compareTime < t ) { index = i + 1 ; } else if ( compareTime == t ) { index = i ; break ; } else { break ; } } //http://www.inside-r.org/packages/cran/rms/docs/survplot //per validation using survplot from RMS package and ggkm they select the next //time in the future which doesn't seem to be correct as the next time represents //knowledge about the future but maybe nrisk at that point in time is defined //as the nrisk prior to that time. This appears to be the case where at time 0 //you would expect that everyone is at risk and you should report that time which //is the case in survplot. Added in index = 0 or if the time you are requesting has //an exact match //survplot(kma,n.risk=TRUE,time.inc=1090) //ggkm(kma,timeby=1090) // if(index != 0 && time.get(index) != t){ // index++; // } if ( index >= nrisk . size ( ) ) { return null ; } else { return nrisk . get ( index ) ; } }
Selection of number of risk will depend on the precision and rounding of time in the survival table . If you are asking for 12 and entry exists for 11 . 9999999 then 12 is greater than 11 . 99999 unless you round .