WLogRk <- function(x1, d1, x2, d2, T, simpleTest = FALSE) { ##################################################################### ### T is the crossing point of the two hazards. ### If simpleTest is TRUE, then it also returns the regular log-rank test ### P-value. Should be similar to SAS proc lifetest, or R survdiff(). ### [this is included here as a check] Need to load package emplik first. ### Assume all x1 x2 are nonnegative, hazards cross at T. ###################################################################### temp11 <- Wdataclean3(z=x1, d=d1) temp12 <- DnR(x=temp11$value, d=temp11$dd, w=temp11$weight) TIME1 <- temp12$times RISK1 <- temp12$n.risk fR1 <- approxfun(x=TIME1, y=RISK1, method="constant", yright=0, rule=2, f=1) temp21 <- Wdataclean3(z=x2, d=d2) temp22 <- DnR(x=temp21$value, d=temp21$dd, w=temp21$weight) TIME2 <- temp22$times RISK2 <- temp22$n.risk fR2 <- approxfun(x=TIME2, y=RISK2, method="constant", yright=0, rule=2, f=1) flogrank <- function(t){fR1(t)*fR2(t)/(fR1(t)+fR2(t))} myfun6 <- function(x) {temp <- 8*( 0.5 - x ) return( pmax( -1, pmin(temp, 1)) ) } fWlogrank <- function(t) { myfun6(t/(2*T))*flogrank(t) } ############################################ fBOTH <- function(t) { cbind( flogrank(t), fWlogrank(t) ) } out1 <- emplikHs.test2(x1=x1, d1=d1, x2=x2, d2=d2, theta=c(0,0), fun1=fBOTH, fun2=fBOTH) pvalue <- NA if(simpleTest) {out2 <- emplikHs.test2(x1=x1, d1=d1, x2=x2, d2=d2, theta=0, fun1=flogrank, fun2=flogrank) pvalue <- 1-pchisq(out2$"-2LLR", df=1) } list(Pval = 1-pchisq(out1$"-2LLR", df=2), Pval(log-rank) = pvalue ) }