dat=data.frame(time=time, status=status)
|
SIZE=function(delta, ta, tf, alpha, beta, data)
|
{
|
tau=tf+ta
|
z0=qnorm(1-alpha)
|
z1=qnorm(1-beta)
|
######### fit KM curve #############
|
surv=Surv(time, status)
|
fitKM<- survfit(surv ~ 1, data = dat)
|
p0<-c(1, summary(fitKM)$surv)
|
# KM survival probability ###
|
t0<-c(0, summary(fitKM)$time)
|
# ordered failure times ###
|
outKM<-data.frame(t0=t0,p0=p0)
|
KM<-function(t){
|
t0=outKM$t0; p0=outKM$p0; k=length(t0)
|
if (t>=t0[k] || t<0) {ans<-0}
|
for (i in 1:(k-1)){
|
if (t>=t0[i] & t<t0[i+1]) {S0=p0[i]}}
|
return(S0)}
|
######### fit Weibull curve ###########
|
fitWB=survreg(formula=surv~1, dist=“weibull”)
|
scale=as.numeric(exp(fitWB$coeff))
|
shape=1/fitWB$scale
|
WB=function(t){
|
kappa=shape; lambda0=1/scaleˆkappa
|
S0 = exp(-lambda0*tˆkappa); return(S0)}
|
######## fit spline curve ##########
|
fitSP=oldlogspline(time[status == 1], time[status == 0], lbound = 0)
|
SP=function(t) {S0=1-poldlogspline(t, fitSP); return(S0)}
|
####### sample size calculation #####
|
S0=function(t){WB(t)}
|
S1=function(t){WB(t)ˆdelta}
|
p0=1-integrate(S0, tf, tau)$value/ta
|
p1=1-integrate(S1, tf, tau)$value/ta
|
PWB=(p0+p1)/2
|
S0=function(t){SP(t)}
|
S1=function(t){SP(t)ˆdelta}
|
p0=1-integrate(S0, tf, tau)$value/ta
|
p1=1-integrate(S1, tf, tau)$value/ta
|
PSP=(p0+p1)/2
|
S0=function(t){KM(t)}
|
S1=function(t){KM(t)ˆdelta}
|
p0=1-(S0(tf)+4*S0(0.5*ta+tf)+S0(ta+tf))/6
|
p1=1-(S1(tf)+4*S1(0.5*ta+tf)+S1(ta+tf))/6
|
PKM=(p0+p1)/2
|
d0=(z0+z1)ˆ2/log(delta)ˆ2
|
# number of events formula (3) |
nWB=ceiling(d0/PWB)
|
# sample size formula (4)
under Weibull model
|
nSP=ceiling(d0/PSP)
|
# sample size formula (4)
under spine curve
|
nKM=ceiling(d0/PKM)
|
# sample size formula (4)
under KM curve
|
d=ceiling(d0)
|
ans=list(c(d=d, nWB=nWB, nSP=nSP, nKM=nKM))
|
return(ans)
|
}
|
#### 80% power ####
|
SIZE(delta=0.58, ta=8, tf=3, alpha=0.05, beta=0.2, data=dat)
|
d nWB nSP nKM
|
21 63 63 63
|
#### 90% power ####
|
SIZE(delta=0.58, ta=8, tf=3, alpha=0.05, beta=0.1, data=dat)
|
d nWB nSP nKM
|
29 88 87 88
|