Last active
August 29, 2015 13:56
-
-
Save CamDavidsonPilon/9315065 to your computer and use it in GitHub Desktop.
Generate exponential survival data with probability alpha of censorship
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
def exponential_survival_data(n, cr=0.05, scale=1.): | |
t = stats.expon.rvs(scale=scale, size=n) | |
if cr == 0.0: | |
return t, np.ones(n, dtype=bool) | |
def pF(h): | |
v = 1.0*h/scale | |
return v / (np.exp(v)-1) - cr | |
#find the threshold: | |
h = newton(pF, 1., maxiter=500) | |
#generate truncated data | |
R = (1-exp(-h/scale))*stats.uniform.rvs(size=n) | |
entrance = -log(1-R)*scale | |
C = (t+entrance) < h #should occur 1-cr of the time. | |
T = np.minimum(h-entrance,t) | |
return T,C | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment