WLogRk <- function(x1, d1, x2, d2, T, simpleTest = FALSE ) { ######################################################### ### This function performs a combined test of a log rank test and ### another test for cross hazard. We need to specify the location ### of the cross hazard. It depend on the package emplik. ### ### T/2 is the crossing point of the two hazards for the test. ### If simpleTest is TRUE, then it also returns the regular log-rank test ### P-value. Should be similar to SAS proc lifetest, R survdiff(). ######################################################## 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/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) ## x <- c( rep(1,length(x1)), rep( 2, length(x2) ) ) ## tempout <- survdiff(Surv(c(x1, x2), c(d1,d2)) ~ x ) pvalue <- NA if(simpleTest) { output <- emplikHs.test2(x1=x1, d1=d1, x2=x2, d2=d2, theta=0, fun1=flogrank, fun2=flogrank) pvalue <- 1-pchisq(output$"-2LLR", df=1) } list(Pval = 1-pchisq(out1$"-2LLR", df=2), PvalLogrank = pvalue ) }