Running 'aareg.R' [4s]
  Comparing 'aareg.Rout' to 'aareg.Rout.save' ... OK
  Running 'anova.R' [3s]
  Comparing 'anova.Rout' to 'anova.Rout.save' ... OK
  Running 'bladder.R' [3s]
  Comparing 'bladder.Rout' to 'bladder.Rout.save' ... OK
  Running 'book1.R' [3s]
  Comparing 'book1.Rout' to 'book1.Rout.save' ... OK
  Running 'book2.R' [3s]
  Comparing 'book2.Rout' to 'book2.Rout.save' ... OK
  Running 'book3.R' [3s]
  Comparing 'book3.Rout' to 'book3.Rout.save' ... OK
  Running 'book4.R' [3s]
  Comparing 'book4.Rout' to 'book4.Rout.save' ... OK
  Running 'book5.R' [3s]
  Comparing 'book5.Rout' to 'book5.Rout.save' ... OK
  Running 'book6.R' [3s]
  Comparing 'book6.Rout' to 'book6.Rout.save' ... OK
  Running 'book7.R' [3s]
  Comparing 'book7.Rout' to 'book7.Rout.save' ... OK
  Running 'cancer.R' [5s]
  Comparing 'cancer.Rout' to 'cancer.Rout.save' ... OK
  Running 'checkSurv2.R' [4s]
  Comparing 'checkSurv2.Rout' to 'checkSurv2.Rout.save' ... OK
  Running 'clogit.R' [3s]
  Comparing 'clogit.Rout' to 'clogit.Rout.save' ... OK
  Running 'concordance.R' [3s]
  Running 'concordance2.R' [19s]
  Comparing 'concordance2.Rout' to 'concordance2.Rout.save' ... OK
  Running 'concordance3.R' [3s]
  Comparing 'concordance3.Rout' to 'concordance3.Rout.save' ... OK
  Running 'counting.R' [3s]
  Comparing 'counting.Rout' to 'counting.Rout.save' ... OK
  Running 'coxsurv.R' [3s]
  Comparing 'coxsurv.Rout' to 'coxsurv.Rout.save' ... OK
  Running 'coxsurv2.R' [3s]
  Comparing 'coxsurv2.Rout' to 'coxsurv2.Rout.save' ... OK
  Running 'coxsurv3.R' [3s]
  Comparing 'coxsurv3.Rout' to 'coxsurv3.Rout.save' ... OK
  Running 'coxsurv4.R' [3s]
  Comparing 'coxsurv4.Rout' to 'coxsurv4.Rout.save' ... OK
  Running 'coxsurv5.R' [3s]
  Comparing 'coxsurv5.Rout' to 'coxsurv5.Rout.save' ... OK
  Running 'detail.R' [3s]
  Comparing 'detail.Rout' to 'detail.Rout.save' ... OK
  Running 'difftest.R' [3s]
  Comparing 'difftest.Rout' to 'difftest.Rout.save' ... OK
  Running 'doaml.R' [3s]
  Comparing 'doaml.Rout' to 'doaml.Rout.save' ... OK
  Running 'doweight.R' [3s]
  Comparing 'doweight.Rout' to 'doweight.Rout.save' ... OK
  Running 'expected.R' [3s]
  Comparing 'expected.Rout' to 'expected.Rout.save' ... OK
  Running 'expected2.R' [3s]
  Comparing 'expected2.Rout' to 'expected2.Rout.save' ... OK
  Running 'factor.R' [3s]
  Comparing 'factor.Rout' to 'factor.Rout.save' ... OK
  Running 'factor2.R' [3s]
  Comparing 'factor2.Rout' to 'factor2.Rout.save' ... OK
  Running 'finegray.R' [3s]
  Comparing 'finegray.Rout' to 'finegray.Rout.save' ... OK
  Running 'fr_cancer.R' [3s]
  Comparing 'fr_cancer.Rout' to 'fr_cancer.Rout.save' ... OK
  Running 'fr_kidney.R' [3s]
  Comparing 'fr_kidney.Rout' to 'fr_kidney.Rout.save' ... OK
  Running 'fr_lung.R' [3s]
  Comparing 'fr_lung.Rout' to 'fr_lung.Rout.save' ... OK
  Running 'fr_ovarian.R' [3s]
  Comparing 'fr_ovarian.Rout' to 'fr_ovarian.Rout.save' ... OK
  Running 'fr_rat1.R' [3s]
  Comparing 'fr_rat1.Rout' to 'fr_rat1.Rout.save' ... OK
  Running 'fr_resid.R' [3s]
  Comparing 'fr_resid.Rout' to 'fr_resid.Rout.save' ... OK
  Running 'fr_simple.R' [3s]
  Comparing 'fr_simple.Rout' to 'fr_simple.Rout.save' ... OK
  Running 'frailty.R' [3s]
  Comparing 'frailty.Rout' to 'frailty.Rout.save' ... OK
  Running 'frank.R' [3s]
  Comparing 'frank.Rout' to 'frank.Rout.save' ... OK
  Running 'infcox.R' [3s]
  Comparing 'infcox.Rout' to 'infcox.Rout.save' ... OK
  Running 'jasa.R' [3s]
  Comparing 'jasa.Rout' to 'jasa.Rout.save' ... OK
  Running 'model.matrix.R' [3s]
  Comparing 'model.matrix.Rout' to 'model.matrix.Rout.save' ... OK
  Running 'mstate.R' [3s]
  Comparing 'mstate.Rout' to 'mstate.Rout.save' ... OK
  Running 'mstrata.R' [4s]
  Comparing 'mstrata.Rout' to 'mstrata.Rout.save' ... OK
  Running 'multi2.R' [3s]
  Comparing 'multi2.Rout' to 'multi2.Rout.save' ... OK
  Running 'multistate.R' [4s]
  Comparing 'multistate.Rout' to 'multistate.Rout.save' ... OK
  Running 'neardate.R' [3s]
  Comparing 'neardate.Rout' to 'neardate.Rout.save' ... OK
  Running 'nested.R' [3s]
  Comparing 'nested.Rout' to 'nested.Rout.save' ... OK
  Running 'nsk.R' [3s]
  Comparing 'nsk.Rout' to 'nsk.Rout.save' ... OK
  Running 'ovarian.R' [3s]
  Comparing 'ovarian.Rout' to 'ovarian.Rout.save' ... OK
  Running 'overlap.R' [3s]
  Comparing 'overlap.Rout' to 'overlap.Rout.save' ... OK
  Running 'prednew.R' [3s]
  Comparing 'prednew.Rout' to 'prednew.Rout.save' ... OK
  Running 'pseudo.R' [4s]
  Comparing 'pseudo.Rout' to 'pseudo.Rout.save' ... OK
  Running 'pspline.R' [3s]
  Comparing 'pspline.Rout' to 'pspline.Rout.save' ... OK
  Running 'pyear.R' [3s]
  Comparing 'pyear.Rout' to 'pyear.Rout.save' ... OK
  Running 'quantile.R' [3s]
  Comparing 'quantile.Rout' to 'quantile.Rout.save' ... OK
  Running 'r_lung.R' [3s]
  Comparing 'r_lung.Rout' to 'r_lung.Rout.save' ... OK
  Running 'r_resid.R' [3s]
  Comparing 'r_resid.Rout' to 'r_resid.Rout.save' ... OK
  Running 'r_sas.R' [9s]
  Comparing 'r_sas.Rout' to 'r_sas.Rout.save' ... OK
  Running 'r_scale.R' [3s]
  Comparing 'r_scale.Rout' to 'r_scale.Rout.save' ... OK
  Running 'r_stanford.R' [3s]
  Comparing 'r_stanford.Rout' to 'r_stanford.Rout.save' ... OK
  Running 'r_strata.R' [3s]
  Comparing 'r_strata.Rout' to 'r_strata.Rout.save' ... OK
  Running 'r_tdist.R' [3s]
  Comparing 'r_tdist.Rout' to 'r_tdist.Rout.save' ... OK
  Running 'r_user.R' [3s]
  Comparing 'r_user.Rout' to 'r_user.Rout.save' ... OK
  Running 'ratetable.R' [3s]
  Comparing 'ratetable.Rout' to 'ratetable.Rout.save' ... OK
  Running 'residsf.R' [3s]
  Comparing 'residsf.Rout' to 'residsf.Rout.save' ... OK
  Running 'royston.R' [3s]
  Comparing 'royston.Rout' to 'royston.Rout.save' ... OK
  Running 'rttright.R' [3s]
  Comparing 'rttright.Rout' to 'rttright.Rout.save' ... OK
  Running 'singtest.R' [3s]
  Comparing 'singtest.Rout' to 'singtest.Rout.save' ... OK
  Running 'strata2.R' [3s]
  Comparing 'strata2.Rout' to 'strata2.Rout.save' ... OK
  Running 'stratatest.R' [3s]
  Comparing 'stratatest.Rout' to 'stratatest.Rout.save' ... OK
  Running 'summary_survfit.R' [3s]
  Comparing 'summary_survfit.Rout' to 'summary_survfit.Rout.save' ... OK
  Running 'surv.R' [3s]
  Comparing 'surv.Rout' to 'surv.Rout.save' ... OK
  Running 'survSplit.R' [3s]
  Comparing 'survSplit.Rout' to 'survSplit.Rout.save' ... OK
  Running 'survcheck.R' [3s]
  Comparing 'survcheck.Rout' to 'survcheck.Rout.save' ... OK
  Running 'survfit1.R' [3s]
  Comparing 'survfit1.Rout' to 'survfit1.Rout.save' ... OK
  Running 'survfit2.R' [3s]
  Comparing 'survfit2.Rout' to 'survfit2.Rout.save' ... OK
  Running 'survreg1.R' [3s]
  Comparing 'survreg1.Rout' to 'survreg1.Rout.save' ... OK
  Running 'survreg2.R' [4s]
  Comparing 'survreg2.Rout' to 'survreg2.Rout.save' ... OK
  Running 'survtest.R' [3s]
  Comparing 'survtest.Rout' to 'survtest.Rout.save' ... OK
  Running 'testci.R' [3s]
  Comparing 'testci.Rout' to 'testci.Rout.save' ... OK
  Running 'testci2.R' [3s]
  Comparing 'testci2.Rout' to 'testci2.Rout.save' ... OK
  Running 'testnull.R' [3s]
  Comparing 'testnull.Rout' to 'testnull.Rout.save' ... OK
  Running 'testreg.R' [3s]
  Comparing 'testreg.Rout' to 'testreg.Rout.save' ... OK
  Running 'tiedtime.R' [3s]
  Comparing 'tiedtime.Rout' to 'tiedtime.Rout.save' ... OK
  Running 'tmerge.R' [3s]
  Comparing 'tmerge.Rout' to 'tmerge.Rout.save' ... OK
  Running 'tmerge2.R' [3s]
  Comparing 'tmerge2.Rout' to 'tmerge2.Rout.save' ... OK
  Running 'tmerge3.R' [3s]
  Comparing 'tmerge3.Rout' to 'tmerge3.Rout.save' ... OK
  Running 'tt.R' [3s]
  Comparing 'tt.Rout' to 'tt.Rout.save' ... OK
  Running 'turnbull.R' [3s]
  Comparing 'turnbull.Rout' to 'turnbull.Rout.save' ... OK
  Running 'update.R' [3s]
  Comparing 'update.Rout' to 'update.Rout.save' ... OK
  Running 'yates0.R' [0s]
  Comparing 'yates0.Rout' to 'yates0.Rout.save' ... OK
  Running 'yates1.R' [3s]
  Comparing 'yates1.Rout' to 'yates1.Rout.save' ... OK
  Running 'yates2.R' [3s]
  Running 'zph.R' [4s]
  Comparing 'zph.Rout' to 'zph.Rout.save' ... OK
Running the tests in 'tests/concordance.R' failed.
Complete output:
  > library(survival)
  > options(na.action=na.exclude) # preserve missings
  > options(contrasts=c('contr.treatment', 'contr.poly')) #ensure constrast type
  > 
  > #
  > # Simple tests of concordance
  > #
  > aeq <- function(x,y, ...) all.equal(as.vector(x), as.vector(y), ...)
  > 
  > grank <- function(x, time, grp, wt) 
  +     unlist(tapply(x, grp, rank))
  > grank2 <- function(x, time, grp, wt) {  #for case weights
  +     if (length(wt)==0) wt <- rep(1, length(x))
  +     z <- double(length(x))
  +     for (i in unique(grp)) {
  +         indx <- which(grp==i)
  +         temp <- tapply(wt[indx], x[indx], sum)
  +         temp <- temp/2  + c(0, cumsum(temp)[-length(temp)])
  +         z[indx] <- temp[match(x[indx], names(temp))]
  +     }
  +     z
  + }
  > 
  > # Concordance by brute force.  O(n^2) algorithm, but ok for n<500 or so
  > allpair <- function(x, time, status, wt, all=FALSE) {
  +     if (missing(wt)) wt <- rep(1, length(x))
  +     count <- sapply(which(status==1), function(i) {
  +         atrisk <- (time > time[i]) | (time==time[i] & status==0)
  +         temp <- tapply(wt[atrisk], factor(sign(x[i] -x[atrisk]), c(1, -1, 0)),
  +                        sum)
  +         wt[i]* c(ifelse(is.na(temp), 0, temp),
  +                  (sum(wt[time==time[i] & status==1]) - wt[i])/2) 
  +     })
  +     rownames(count) <- c("concordant", "discordant", "tied.x", "tied.y")
  +     if (all) {
  +         colnames(count) <- time[status==1]
  +         t(count)
  +     }
  +     else rowSums(count)
  + }
  > 
  > 
  > # The std of C = std(numerator)/(number of comparable pairs)
  > # The information matrix of a Cox model is = to the var(C-D)
  > cfun <- function(fit) fit$cvar * sum(fit$count[1:3])^2
  >                 
  > tdata <- aml[aml$x=='Maintained', c("time", "status")]
  > tdata$x <- c(1,6,2,7,3,7,3,8,4,4,5)
  > tdata$wt <- c(1,2,3,2,1,2,3,4,3,2,1)
  > fit <- concordance(Surv(time, status) ~x, tdata)
  > 
  > aeq(fit$count[1:4], c(24,14,2,0))
  [1] TRUE
  > cfit <- coxph(Surv(time, status) ~ tt(x), tdata, tt=grank, method='breslow',
  +               iter=0, x=T)
  > cdt <- coxph.detail(cfit)
  > aeq(sum(cdt$imat), cfun(fit))
  [1] TRUE
  > aeq(sum(2*cdt$score), diff(fit$count[1:2]))
  [1] TRUE
  > aeq(with(tdata, allpair(x, time, status)), c(14,24,2,0))
  [1] TRUE
  > 
  > # Lots of ties
  > tempy <- Surv(c(1,2,2,2,3,4,4,4,5,2), c(1,0,1,0,1,0,1,1,0,1))
  > tempx <- c(5,5,4,4,3,3,7,6,5,4)
  > fit2 <- concordance(tempy ~ tempx)
  > addxy <- function(x) c(x[1:3], sum(x[4:5]))
  > aeq(addxy(fit2$count), allpair(tempx, tempy[,1], tempy[,2]))
  [1] TRUE
  > cfit2 <-  coxph(tempy ~ tt(tempx), tt=grank, method='breslow', iter=0)
  > aeq(cfit2$var, 1/cfun(fit2))
  [1] TRUE
  > 
  > # Direct call
  > fit2b <- concordancefit(tempy, tempx)
  > fit2c <- concordancefit(tempy, tempx, robustse=FALSE)
  > all.equal(fit2[1:5], fit2b)
  [1] TRUE
  > all.equal(fit2b[-4], fit2c)
  [1] TRUE
  > 
  > # Bigger data
  > fit3 <- concordance(Surv(time, status) ~ age, lung, reverse=TRUE)
  > aeq(addxy(fit3$count), allpair(lung$age, lung$time, lung$status-1))
  [1] TRUE
  > cfit3 <- coxph(Surv(time, status) ~ tt(age), lung, 
  +                iter=0, method='breslow', tt=grank, x=T)
  > cdt <- coxph.detail(cfit3)
  > aeq(sum(cdt$imat), cfun(fit3)) 
  [1] TRUE
  > aeq(2*sum(cdt$score), diff(fit3$count[2:1]))
  [1] TRUE
  > 
  > 
  > # More ties
  > fit4 <- concordance(Surv(time, status) ~ ph.ecog, lung, reverse=TRUE)
  > aeq(addxy(fit4$count), allpair(lung$ph.ecog, lung$time, lung$status-1))
  [1] TRUE
  > aeq(fit4$count[1:5], c(8392, 4258, 7137, 21, 7))
  [1] TRUE
  > cfit4 <- coxph(Surv(time, status) ~ tt(ph.ecog), lung, 
  +                iter=0, method='breslow', tt=grank)
  > aeq(1/cfit4$var, cfun(fit4))
  [1] TRUE
  > 
  > # Case weights
  > fit5 <- concordance(Surv(time, status) ~ x, tdata, weight=wt, reverse=TRUE)
  > fit6 <- concordance(Surv(time, status) ~x, tdata[rep(1:11,tdata$wt),])
  > aeq(addxy(fit5$count), with(tdata, allpair(x, time, status, wt)))
  [1] TRUE
  > aeq(fit5$count[1:4], c(70, 91, 7, 0))  # checked by hand
  [1] TRUE
  > aeq(fit5$count[1:3], fit6$count[c(2,1,3)])  #spurious "tied on time" values, ignore
  [1] TRUE
  > aeq(fit5$std, fit6$std)
  [1] TRUE
  > cfit5 <- coxph(Surv(time, status) ~ tt(x), tdata, weight=wt, 
  +                iter=0, method='breslow', tt=grank2)
  > cfit6 <- coxph(Surv(time, status) ~ tt(x), tdata[rep(1:11,tdata$wt),], 
  +                iter=0, method='breslow', tt=grank)
  > aeq(1/cfit6$var, cfun(fit6))
  [1] TRUE
  > aeq(cfit5$var, cfit6$var)
  [1] TRUE
  > 
  > # Start, stop simplest cases
  > fit7 <- concordance(Surv(rep(0,11), time, status) ~ x, tdata)
  > aeq(fit7$count, fit$count)
  [1] TRUE
  > aeq(fit7$std.err, fit$std.err)
  [1] TRUE
  > fit7 <- concordance(Surv(rep(0,11), time, status) ~ x, tdata, weight=wt)
  > aeq(fit5$count, fit7$count[c(2,1,3:5)])  #one reversed, one not
  [1] TRUE
  > 
  > # Multiple intervals for some, but same risk sets as tdata
  > tdata2 <- data.frame(time1=c(0,3, 5,  6,7,   0,  4,17,  7,  0,16,  2,  0, 
  +                              0,9, 5),
  +                      time2=c(3,9, 13, 7,13, 18, 17,23, 28, 16,31, 34, 45, 
  +                              9,48, 60),
  +                      status=c(0,1, 1, 0,0,  1,  0,1, 0, 0,1, 1, 0, 0,1, 0),
  +                      x = c(1,1, 6, 2,2, 7, 3,3, 7, 3,3, 8, 4, 4,4, 5),
  +                      wt= c(1,1, 2, 3,3, 2, 1,1, 2, 3,3, 4, 3, 2,2, 1))
  > fit8 <- concordance(Surv(time1, time2, status) ~x, tdata2, weight=wt,
  +                     reverse=TRUE)
  > aeq(fit5$count, fit8$count)
  [1] TRUE
  > aeq(fit5$std.err, fit8$std.err)
  [1] TRUE
  > cfit8 <- coxph(Surv(time1, time2, status) ~ tt(x), tdata2, weight=wt, 
  +                iter=0, method='breslow', tt=grank2)
  > aeq(1/cfit8$var, cfun(fit8))
  [1] TRUE
  > 
  > # Stratified
  > tdata3 <- data.frame(time1=c(tdata2$time1, rep(0, nrow(lung))),
  +                      time2=c(tdata2$time2, lung$time),
  +                      status = c(tdata2$status, lung$status -1),
  +                      x = c(tdata2$x, lung$ph.ecog),
  +                      wt= c(tdata2$wt, rep(1, nrow(lung))),
  +                      grp=rep(1:2, c(nrow(tdata2), nrow(lung))))
  > fit9 <- concordance(Surv(time1, time2, status) ~x + strata(grp),
  +                         data=tdata3, weight=wt, reverse=TRUE)