5.13.1.1.1.8. statsmodels.sandbox.survival2.KaplanMeier.test_diff¶
-
KaplanMeier.
test_diff
(groups, rho=0)[source]¶ Test for difference between survival curves
Parameters: groups: A list of the values for exog to test for difference.
tests the null hypothesis that the survival curves for all
values of exog in groups are equal
rho: compute the test statistic with weight S(t)^rho, where
S(t) is the pooled estimate for the Kaplan-Meier survival function.
If rho = 0, this is the logrank test, if rho = 0, this is the
Peto and Peto modification to the Gehan-Wilcoxon test.
weight: User specified function that accepts as its sole arguement
an array of times, and returns an array of weights for each time
to be used in the test
Returns: An array whose zeroth element is the chi-square test statistic for
the global null hypothesis, that all survival curves are equal,
the index one element is degrees of freedom for the test, and the
index two element is the p-value for the test.
Examples
>>> import statsmodels.api as sm >>> import matplotlib.pyplot as plt >>> import numpy as np >>> from statsmodels.sandbox.survival2 import KaplanMeier >>> dta = sm.datasets.strikes.load() >>> dta = dta.values()[-1] >>> censoring = np.ones_like(dta[:,0]) >>> censoring[dta[:,0] > 80] = 0 >>> dta = np.c_[dta,censoring] >>> km = KaplanMeier(dta,0,exog=1,censoring=2) >>> km.fit()
Test for difference of survival curves
>>> log_rank = km3.test_diff([0.0645,-0.03957])
The zeroth element of log_rank is the chi-square test statistic for the difference between the survival curves using the log rank test for exog = 0.0645 and exog = -0.03957, the index one element is the degrees of freedom for the test, and the index two element is the p-value for the test
>>> wilcoxon = km.test_diff([0.0645,-0.03957], rho=1)
wilcoxon is the equivalent information as log_rank, but for the Peto and Peto modification to the Gehan-Wilcoxon test.
User specified weight functions
>>> log_rank = km3.test_diff([0.0645,-0.03957], weight=np.ones_like)
This is equivalent to the log rank test
More than two groups
>>> log_rank = km.test_diff([0.0645,-0.03957,0.01138])
The test can be performed with arbitrarily many groups, so long as they are all in the column exog