The following example illustrate use of 3 dimentional array with the function `apply', useful in doing bootstrap with censored data. (since censored data itself is two dim). -Mai Zhou > # first create a 3 dim array by paste 2 regular 2x75 matricis, mat1 and mat2 > mat1 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] x1 2.01 2.02 2.03 2.04 2.05 2.06 2.07 2.08 2.09 2.1 2.11 2.12 2.13 2.14 d1 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.0 1.00 1.00 1.00 1.00 [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26] x1 2.15 2.16 2.17 2.18 2.19 2.2 2.21 2.22 2.23 2.24 2.25 2.26 d1 1.00 1.00 1.00 1.00 1.00 1.0 1.00 1.00 1.00 1.00 1.00 1.00 [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37] [,38] x1 2.27 2.28 2.29 2.3 2.31 2.32 2.33 2.34 2.35 2.36 2.37 2.38 d1 1.00 1.00 1.00 1.0 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49] [,50] x1 2.39 2.4 2.41 2.42 2.43 2.44 2.45 2.46 2.47 2.48 2.49 2.5 d1 1.00 1.0 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.0 [,51] [,52] [,53] [,54] [,55] [,56] [,57] [,58] [,59] [,60] [,61] [,62] x1 2.51 2.52 2.53 2.54 2.55 2.56 2.57 2.58 2.59 2.6 2.61 2.62 d1 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.0 1.00 1.00 [,63] [,64] [,65] [,66] [,67] [,68] [,69] [,70] [,71] [,72] [,73] [,74] x1 2.63 2.64 2.65 2.66 2.67 2.68 2.69 2.7 2.71 2.72 2.73 2.74 d1 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.0 1.00 1.00 1.00 1.00 [,75] x1 2.75 d1 1.00 > # mat2 looks similar, with same dimentions, but entries are different > mat2 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [1,] 2.76 2.77 2.78 2.79 2.8 2.81 2.82 2.83 2.84 2.85 2.86 2.87 2.88 [2,] 1.00 0.00 0.00 1.00 0.0 1.00 1.00 1.00 0.00 1.00 1.00 0.00 1.00 ............the rest of mat2 omitted > dim(mat2) [1] 2 75 > dim(mat1) [1] 2 75 > # Now combine mat1 and mat2 to create a 3 dim array > mat3 <- array( c(mat1, mat2), dim = c(2,75,2) ) > dim(mat3) [1] 2 75 2 > mat3 , , 1 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [1,] 2.01 2.02 2.03 2.04 2.05 2.06 2.07 2.08 2.09 2.1 2.11 2.12 2.13 [2,] 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.0 1.00 1.00 1.00 ......... I omit the rest of mat3, but you should try to convince yourself that you want `apply' to work with the depth, the 3rd dim of mat3. Because at each fixed depth, mat3 is a matrix of 2 rows and 75 col, with the first row as observed times and second row as censoring status. You can check this by try look at mat3[,,1] and mat3[,,2] > # Next wrap the function survfit to take a 2 row matrix as input > # the first row as the time and second row as the status > mysurvfit<-function( mat ) { + temp<-survfit(Surv(mat[1,],mat[2,]),se.fit=F,type="fleming",conf.type="none") + temp$n.event + } > mysurvfit function(mat) { temp <- survfit(Surv(mat[1, ], mat[2, ]), se.fit = F, type = "fleming", conf.type = "none") temp$n.event } > # I only output the n.event of survfit. (may be temp$median make more sense) > # When each output is more then a vector, the output of apply can be > # hard to read (eg. an array of many dim) so you want to simplify the output. > # Test the function > mysurvfit(mat1) [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 [39] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 > mysurvfit(mat2) [1] 1 0 0 1 0 1 1 1 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 1 1 1 0 1 0 0 0 0 1 0 1 0 0 0 [39] 0 1 1 1 1 1 0 1 0 0 1 1 0 0 1 1 0 0 0 0 1 1 1 0 0 1 1 1 1 0 0 1 1 1 0 1 1 > # looks OK on regular matrix. Now on to 3 dim array > apply(mat3, 3, mysurvfit) # notice I apply on the 3rd dim (depth) of mat3 [,1] [,2] [1,] 1 1 [2,] 1 0 [3,] 1 0 ...................... the rest omitted, a matrix of 75 row and 2 col. Looks OK too.