LogRank1 <- function(z1,d1,Hz1) # This function compute the one sample logrank test. # z1 are the observed (possibly censored) times, # d1 are the censoring indicators, 1--uncensored, 0--censored; # Hz1 should be a vector of null cumulative hazard at the observed times # i.e. H_0(z1). Please note this is different from the Splus convention. # There you input the Survival at times, i.e. S(z1). [now use glm()] { if( (length(z1)!=length(d1)) | (length(d1)!=length(Hz1)) ) stop("input must have same length") if(any((d1!=0)&(d1!=1)) ) stop("d1 must be 0/1's for censor/not-censor") if(any(Hz1 < 0)) stop("Hz1 must be nonnegative") EE <- sum(Hz1) diff <- sum(d1) - EE temp2 <- diff/sqrt(EE) pval <- 1-pchisq((temp2)^2, df=1) list(Logrank=temp2, ApproxPvalue2side=pval) } # An example of the test in action is LogRank1(z, d, 0.3*z) # this tests if the lifetime distribution of (z,d) is exp(0.3), since # the cumulative hazard function of exp(0.3) is H(t)= 0.3 * t # # In fact we even do not need the z1 in the input! only the length. # For reference see Klein and Moeschberger book ### Wilcoxon-Gehan test: ## S1 <- exp(-Hz1) ## EE <- length(z1) - sum(S1) ## diff <- sum(S1*d1) - EE ## FF <- 0.5*( length(z1) - sum(S1*S1)) ## temp2 <- diff/sqrt(FF) ## pval <- 1-pchisq( (temp2)^2, df=1) ##