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' [4s]
  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' [4s]
  Comparing 'cancer.Rout' to 'cancer.Rout.save' ... OK
  Running 'clogit.R' [3s]
  Comparing 'clogit.Rout' to 'clogit.Rout.save' ... OK
  Running 'concordance.R' [4s]
  Comparing 'concordance.Rout' to 'concordance.Rout.save' ... OK
  Running 'concordance2.R' [18s]
  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' [4s]
  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' [4s]
  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' [2s]
  Comparing 'frailty.Rout' to 'frailty.Rout.save' ... OK
  Running 'frank.R' [3s]
  Comparing 'frank.Rout' to 'frank.Rout.save' ... OK
  Running 'infcox.R' [2s]
  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 'multi2.R' [4s]
  Comparing 'multi2.Rout' to 'multi2.Rout.save' ... OK
  Running 'multistate.R' [4s]
  Comparing 'multistate.Rout' to 'multistate.Rout.save' ... OK
  Running 'nested.R' [3s]
  Comparing 'nested.Rout' to 'nested.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 '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_donnell.R' [4s]
  Comparing 'r_donnell.Rout' to 'r_donnell.Rout.save' ... OK
  Running 'r_lung.R' [3s]
  Comparing 'r_lung.Rout' to 'r_lung.Rout.save' ... OK
  Running 'r_peterson.R' [3s]
  Comparing 'r_peterson.Rout' to 'r_peterson.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' ...412,413c412,413
< null device 
<           1 
---
> pdf 
>   2 
  Running 'r_scale.R' [4s]
  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 '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' [1s]
  Comparing 'yates0.Rout' to 'yates0.Rout.save' ... OK
  Running 'yates1.R' [4s]
  Comparing 'yates1.Rout' to 'yates1.Rout.save' ... OK
  Running 'yates2.R' [3s]
  Running 'zph.R' [4s]
Running the tests in 'tests/zph.R' failed.
Complete output:
  > library(survival)
  > aeq <- function(x,y) all.equal(as.vector(x), as.vector(y))
  > 
  > test1 <- data.frame(time=  c(9, 3,1,1,6,6,8),
  +                     status=c(1,NA,1,0,1,1,0),
  +                     x=     c(0, 2,1,1,1,0,0))
  > 
  > # Verify that cox.zph computes a score test
  > # First for the Breslow estimate
  > r <- (3 + sqrt(33))/2   # actual MLE for log(beta)
  > U <- c(1/(r+1), 3/(r+3), -r/(r+3), 0)   # score statistic
  > imat <- c(r/(r+1)^2, 3*r/(r+3)^2, 3*r/(r+3)^2, 0)  # information matrix
  > g = c(1, 6, 6, 9)  # death times
  > 
  > u2 <- c(sum(U), sum(g*U))  # first derivative
  > i2 <- matrix(c(sum(imat), sum(g*imat), sum(g*imat), sum(g^2*imat)),
  +                2,2)  # second derivative
  > sctest <- solve(i2, u2) %*% u2
  > 
  > # Verify that centering makes no difference for the test (though i2 changes)
  > g2 <- g - mean(g)
  > u2b <- c(sum(U), sum(g2*U))
  > i2b <- matrix(c(sum(imat), sum(g2*imat), sum(g2*imat), sum(g2^2*imat)),
  +                2,2) 
  > sctest2 <- solve(i2b, u2b) %*% u2b
  > all.equal(sctest, sctest2)
  [1] TRUE
  > 
  > # Now check the program
  > fit1 <- coxph(Surv(time, status) ~ x, test1, ties='breslow')
  > aeq(fit1$coef, log(r))
  [1] TRUE
  > zp1 <- cox.zph(fit1, transform='identity', global=FALSE)
  > aeq(zp1$table[,1], sctest)
  [1] TRUE
  > aeq(zp1$y, resid(fit1, type="scaledsch"))
  [1] TRUE
  > 
  > dummy <- rep(0, nrow(test1))
  > fit1b <- coxph(Surv(dummy, time, status) ~ x, test1, ties='breslow')
  > aeq(fit1b$coef, log(r))
  [1] TRUE
  > zp1b <- cox.zph(fit1b, transform='identity', global=FALSE)
  > aeq(zp1b$table[,1], sctest)
  [1] TRUE
  > # the pair of tied times gets reversed in the zph result
  > #  but since the 'y' values are only used to plot it doesn't matter
  > aeq(zp1b$y[c(1,3,2,4)], resid(fit1b, type="scaledsch"))  
  [1] TRUE
  > 
  > # log time check
  > g3 <- log(g) - mean(log(g))
  > u3 <- c(sum(U), sum(g3*U))  # first derivative
  > i3 <- matrix(c(sum(imat), sum(g3*imat), sum(g3*imat), sum(g3^2*imat)),
  +                2,2)  # second derivative
  > sctest3 <- solve(i3, u3) %*% u3
  > zp3 <- cox.zph(fit1, transform='log', global=FALSE)
  > aeq(zp3$table[,1], sctest3)
  [1] TRUE
  > 
  > # Efron approximation
  > phi <- acos((45/23)*sqrt(3/23))
  > r <- 2*sqrt(23/3)* cos(phi/3)   # actual MLE for log(beta)
  > U <- c(1/(r+1), 3/(r+3), -r/(r+5), 0)   # score statistic
  > imat <- c(r/(r+1)^2, 3*r/(r+3)^2, 5*r/(r+5)^2, 0)  # information matrix
  > 
  > u4 <- c(sum(U), sum(g3*U))  # first derivative
  > i4 <- matrix(c(sum(imat), sum(g3*imat), sum(g3*imat), sum(g3^2*imat)),
  +                2,2)  # second derivative
  > sctest4 <- solve(i4, u4) %*% u4
  > 
  > fit4 <- coxph(Surv(time, status) ~ x, test1, ties='efron')
  > aeq(fit4$coef, log(r))
  [1] TRUE
  > zp4 <- cox.zph(fit4, transform='log', global=FALSE)
  > aeq(zp4$table[,1], sctest4)
  [1] TRUE
  > aeq(zp4$y, resid(fit4, type="scaledsch"))
  [1] TRUE
  > 
  > fit5 <-  coxph(Surv(dummy, time, status) ~ x, test1, ties="efron")
  > aeq(fit5$coef, log(r))
  [1] TRUE
  > zp5 <- cox.zph(fit5, transform="log", global=FALSE)
  > aeq(zp5$table[,1], sctest4)
  [1] TRUE
  > 
  > # Artificial stratification
  > test2 <- rbind(test1, test1)
  > test2$group <- rep(letters[1:2], each=nrow(test1))
  > # U, imat, and sctest will all double
  > dummy <- c(dummy, dummy)
  > fit6 <- coxph(Surv(dummy, time, status) ~ x + strata(group), test2)
  > aeq(fit6$coef, log(r))
  [1] TRUE
  > zp6 <- cox.zph(fit6, transform="log", globa=FALSE)
  > aeq(zp6$table[,1], 2*sctest4)
  [1] TRUE
  > 
  > # A multi-state check, 2 covariates
  > #  Verify that the multi-state result = the single state Cox models
  > etime <- with(mgus2, ifelse(pstat==0, futime, ptime))
  > event <- with(mgus2, ifelse(pstat==0, 2*death, 1))
  > event <- factor(event, 0:2, labels=c("censor", "pcm", "death"))
  > table(event)
  event
  censor    pcm  death 
     409    115    860 
  > 
  > ct1 <- coxph(Surv(etime, event) ~ sex + age, mgus2, id=id)
  > ct2 <- coxph(Surv(etime, event=='pcm') ~ sex + age, mgus2)
  > ct3 <- coxph(Surv(etime, event=='death') ~ sex + age, mgus2)
  > 
  > zp1 <- cox.zph(ct1, transform='identity')
  > zp2 <- cox.zph(ct2, transform='identity')
  > zp3 <- cox.zph(ct3, transform='identity')
  > aeq(zp1$table[1:2,], zp2$table[1:2,])
  [1] TRUE
  > aeq(zp1$table[3:4,], zp3$table[1:2,])
  [1] TRUE
  > 
  > # Now add a starting time of zero
  > dummy <- rep(0, nrow(mgus2))
  > ct4 <- coxph(Surv(dummy, etime, event) ~ sex + age, mgus2, id=id)
  Error in if (flag["teleport"] > 0) { : 
    missing value where TRUE/FALSE needed
  Calls: coxph -> survcheck2
  Execution halted