Created
May 14, 2019 21:42
-
-
Save CamDavidsonPilon/b44a9a5d321bbc7a005af93782903395 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from lifelines import WeibullFitter | |
lambda_, rho_ = 2, 0.5 | |
N = 10_000 | |
T_actual = lambda_ * np.random.exponential(1, size=N)**(1/rho_) | |
T_censor = lambda_ * np.random.exponential(1, size=N)**(1/rho_) | |
T = np.minimum(T_actual, T_censor) | |
E = T_actual < T_censor | |
# pick a time on the curve to examine. | |
time = [1.0] | |
# lifelines computed confidence interval using delta method | |
print(wf.fit(T, E, timeline=time).confidence_interval_cumulative_hazard_) | |
bootstrap_samples = 10_000 | |
results = [] | |
for _ in range(bootstrap_samples): | |
ix = np.random.randint(0, 10_000, 10_000) | |
wf = WeibullFitter().fit(T[ix], E[ix], timeline=time) | |
results.append(wf.cumulative_hazard_at_times(time).values[0]) | |
# should converge to the values above | |
print(np.percentile(results, [2.5, 97.5])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment