1context("Construction of pseudovalues")
2test_that("pseudo",{
3    library(prodlim)
4    library(pseudo)
5    # comparison to pseudoci
6    # make sure we get the same
7    # results with both packages
8    set.seed(17)
9    N <- 200
10    ddd <- SimCompRisk(200)
11    ttt <- c(3,5,10)
12    # ttt <- ddd$time
13    fff <- prodlim(Hist(time,event)~1,data=ddd)
14    system.time(jack <- with(ddd,pseudoci(time,event,ttt)))
15    system.time({jack2 <- jackknife.competing.risks(fff,times=ttt)})
16    ## check individual 2
17    expect_true(all(round(jack2[,2],9)==round(jack[[3]]$cause1[,2],9)))
18    ## check all individuals
19    expect_true(all(sapply(1:N,function(x){
20        a <- round(jack[[3]]$cause1[x,],8)
21        b <- round(jack2[x,],8)
22        # all(a[!is.na(a)]==b[!is.na(b)])
23        all(a[!is.na(a)]==b[!is.na(a)])
24    })))
25    ## the pseudoci function seems only slightly slower
26    ## for small sample sizes (up to ca. 200) but
27    ## much slower for large sample sizes:
28    set.seed(17)
29    N <- 200
30    ddd <- SimCompRisk(200)
31    ttt <- c(3,5,10)
32    # ttt <- ddd$time
33    fff <- prodlim(Hist(time,event)~1,data=ddd)
34    system.time(jack <- with(ddd,pseudoci(time,event,ttt)))
35    system.time({jack2 <- jackknife.competing.risks(fff,times=ttt)})
36    expect_true(all(round(jack2[,1],9)==round(jack$pseudo$cause1[,1],9)))
37    set.seed(17)
38    N <- 2000
39    ddd <- SimCompRisk(2000)
40    ttt <- c(3,5,10)
41    fff <- prodlim(Hist(time,event)~1,data=ddd)
42    a <- system.time(jack <- with(ddd,pseudoci(time,event,ttt)))
43    b <- system.time({jack2 <- jackknife.competing.risks(fff,times=ttt)})
44    expect_less_than(a,b)
45}
46
47