package com.imsl.test.example.stat; import java.text.*; import com.imsl.stat.*; /** *
* Computes the Kaplan-Meier probability estimates for censored data. *
* * The following example is taken from Kalbfleisch and Prentice (1980, page 1). * The first column inx
contains the death/censoring times for
* rats suffering from vaginal cancer. The second column contains information as
* to which of two forms of treatment were provided, while the third column
* contains the censoring code. Finally, the fourth column contains the
* frequency of each observation. The product-limit estimates of the survival
* probabilities are computed for both groups along with their standard error
* estimates. Tables containing these values along with other statistics are
* printed.
*
*
* @see Code
* @see Output
*/
public class KaplanMeierEstimatesEx1 {
public static void main(String args[]) {
double[][] x = {
{143, 5, 0, 1}, {164, 5, 0, 1}, {188, 5, 0, 2}, {190, 5, 0, 1},
{192, 5, 0, 1}, {206, 5, 0, 1}, {209, 5, 0, 1}, {213, 5, 0, 1},
{216, 5, 0, 1}, {220, 5, 0, 1}, {227, 5, 0, 1}, {230, 5, 0, 1},
{234, 5, 0, 1}, {246, 5, 0, 1}, {265, 5, 0, 1}, {304, 5, 0, 1},
{216, 5, 1, 1}, {244, 5, 1, 1}, {142, 7, 0, 1}, {156, 7, 0, 1},
{163, 7, 0, 1}, {198, 7, 0, 1}, {205, 7, 0, 1}, {232, 7, 0, 2},
{233, 7, 0, 4}, {239, 7, 0, 1}, {240, 7, 0, 1}, {261, 7, 0, 1},
{280, 7, 0, 2}, {296, 7, 0, 2}, {323, 7, 0, 1}, {204, 7, 1, 1},
{344, 7, 1, 1}
};
int nobs = x.length, censorIndex = 2, frequencyIndex = 3;
int stratumIndex = 1, responseIndex = 0;
int i, groupValue;
// Get Kaplan-Meir Estimates
KaplanMeierEstimates km = new KaplanMeierEstimates(x);
km.setCensorColumn(censorIndex);
km.setFrequencyColumn(frequencyIndex);
km.setStratumColumn(stratumIndex);
int[] atRisk = km.getNumberAtRisk();
int[] nFailing = km.getNumberOfFailures();
double[] prob = km.getSurvivalProbabilities();
double[] se = km.getStandardErrors();
// Print Results
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(4);
nf.setMinimumFractionDigits(4);
i = 0;
while (i < nobs) {
groupValue = (int) x[i][stratumIndex];
System.out.println("\n Kaplan-Meier Survival Probabilities");
System.out.println(" For Group Value = "
+ groupValue);
System.out.println("\nNumber Number"
+ " Survival Estimated");
System.out.println("at risk Failing Time"
+ " Probability Std. Error");
while (i < nobs && ((int) x[i][stratumIndex] == groupValue)) {
if ((int) x[i][censorIndex] != 1) {
System.out.println(" " + atRisk[i] + " "
+ nFailing[i] + "" + " "
+ ((int) x[i][responseIndex]) + " "
+ nf.format(prob[i]) + " "
+ nf.format(se[i]));
}
i++;
}
System.out.println("\nTotal number in group = "
+ km.getGroupTotal(groupValue));
System.out.println("Total number failing = "
+ km.getTotalNumberOfFailures(groupValue));
System.out.println("Product Limit likelihood = "
+ nf.format(km.getLogLikelihood(groupValue)));
}
System.out.println("\nThe number of rows of x with missing values is "
+ km.getNumberOfRowsMissing());
}
}