Simulate survival times given a true survivor function? Suppose I have a true survivor function, for example,
$$
S(t) = \sqrt{1-t^2} \quad \text{for} \quad 0<t<1
$$
How can I generate simulated data from this function? Such as generate 1,000 survival times (assuming no censoring).
 A: You could use inverse transform sampling method for intuitive explanation.
Given survivor function: $S(t)$  you could get cumulative distribution function $F(t) = 1-S(t)$.
$F(t) = 1 - \sqrt{1-t^2}$.
Using inverse transform method:
Let $T$ be a random variable whose distribution can be described by the cumulative distribution function $F_T$.
Compute : $T=F_{T}^{-1}(U)$. Where $ U \sim Uniform(0,1)$.
So for your problem using the equation, $u =  1 - \sqrt{1-t^2} $ solve for $t$.
we get, $t = \sqrt{2u - u^2}$. Now we could use a software program like R to generate/simulate random variates.
n = 1000 # of sample
u = runif(n) #generate n random samples
t = sqrt(2*u-u^2) #generate n random variates for CDF = 1 - sqrt(1- t^2)

You Could check Empirical and theoretical survivor function as follows.
#Theoritical Survivor function
tx = seq(0,1,0.1)
sty = (sqrt(1- tx^2))

#empirical survivor function

freq <- rep(NA,length(tx))
for (i in seq_along(tx)){
  freq[i] <- (sum(t >= tx[i]))
  
}

st_empirical <- freq/length(t)

## Plot both empirical and theoritical
plot(tx,sty,col="red",type="o",ylab = expression(S(t) == sqrt(1-t^2)),xlab = "t", main="Empirical (blue) vs Theoritical (red) Survival")
lines(tx,st_empirical,col="blue")

Here is the comparison plot:

A: You can do this using inverse transform sampling. If $U \sim \mathcal U_{[0,1]}$ then
$$
T = S^{-1}(U)
$$
will have $S(t)$ as survival function (and $1-S(t)$ as cdf).
It easy to show that, since $0 \leq t \leq 1$,
\begin{align*}
S^{-1}(y) &= \sqrt{1-y^2} \\
&= S(y) 
\end{align*}
Thus you can generate the survival times through $\sqrt{1- U^2}$ with $U \sim \mathcal U_{[0,1]}$.
Here is a R code to visually check if this works or not:
#survival function (which is its own inverse)
surv<-function(t) sqrt(1-t**2)

#10000 simulated survival times
survtimes<-sapply(1:1e4,function(i) surv(runif(1)))

#empirical survival function based on the sample
surv_emp<-function(t) mean(survtimes>=t)
surv_emp<-Vectorize(surv_emp)

#we plot both the true and empirical survival function to see if they match
x<-seq(0,1,0.01)
plot(x,surv_emp(x),type='l',col="red")
lines(x,surv(x),type='l',col="green")

