R Under development (unstable) (2024-05-16 r86559 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(cmprsk) Loading required package: survival > > options(warn=-1) > RNGversion("1.6.2") > options(warn=0) > > set.seed(2) > ss <- rexp(100) > gg <- factor(sample(1:3,100,replace=TRUE),1:3,c('a','b','c')) > cc <- sample(0:2,100,replace=TRUE) > strt <- sample(1:2,100,replace=TRUE) > dd <- data.frame(ss=abs(rnorm(100))) > d2 <- data.frame(ssd=ss,ggd=gg,ccd=cc,strtd=strt,X=c(rep(1,80),rep(0,20))) > gg2 <- gg > gg2[c(5,10,50)] <- NA > print(xx <- cuminc(dd$ss,cc,gg,strt)) Tests: stat pv df 1 1.214132 0.5449473 2 2 3.269462 0.1950048 2 Estimates and Variances: $est 1 2 3 a 1 0.2105985 NA NA b 1 0.2685413 0.3471880 0.3471880 c 1 0.3082577 0.4989848 NA a 2 0.3156040 NA NA b 2 0.3382252 0.6036578 0.6036578 c 2 0.2376301 0.2830413 NA $var 1 2 3 a 1 0.006386094 NA NA b 1 0.007003493 0.008623542 0.008623542 c 1 0.008874672 0.012216283 NA a 2 0.008549829 NA NA b 2 0.008107166 0.010928915 0.010928915 c 2 0.007656447 0.008944878 NA > print(xx <- cuminc(d2$ssd,d2$ccd)) Estimates and Variances: $est 1 2 3 4 5 1 1 0.2352861 0.3287068 0.4247898 0.4247898 0.4247898 1 2 0.2567862 0.3931580 0.4631781 0.4911861 0.4911861 $var 1 2 3 4 5 1 1 0.002062112 0.002957844 0.004170634 0.004170634 0.004170634 1 2 0.002190305 0.003273248 0.004004514 0.004369940 0.004369940 > print(xx <- cuminc(ss,cc)) Estimates and Variances: $est 1 2 3 4 5 1 1 0.2352861 0.3287068 0.4247898 0.4247898 0.4247898 1 2 0.2567862 0.3931580 0.4631781 0.4911861 0.4911861 $var 1 2 3 4 5 1 1 0.002062112 0.002957844 0.004170634 0.004170634 0.004170634 1 2 0.002190305 0.003273248 0.004004514 0.004369940 0.004369940 > print(xx <- cuminc(ss,cc,gg,strt)) Tests: stat pv df 1 3.393977 0.1832345 2 2 1.989511 0.3698139 2 Estimates and Variances: $est 1 2 3 4 5 a 1 0.1311269 0.2699184 0.3420625 0.3420625 0.3420625 b 1 0.2176471 0.2615686 NA NA NA c 1 0.3816280 0.4889137 0.5723581 NA NA a 2 0.2257601 0.2972171 0.4415053 0.4415053 0.4415053 b 2 0.3117647 0.5878431 NA NA NA c 2 0.2160508 0.2607532 0.2607532 NA NA $var 1 2 3 4 5 a 1 0.003922836 0.009113464 0.012507959 0.01250796 0.01250796 b 1 0.005528913 0.006916070 NA NA NA c 1 0.009854126 0.012351948 0.015575726 NA NA a 2 0.005947601 0.007356628 0.014479506 0.01447951 0.01447951 b 2 0.007033454 0.010927780 NA NA NA c 2 0.006497566 0.007867543 0.007867543 NA NA > plot(xx) > plot(xx,lty=1,color=1:6) > print(xx <- cuminc(dd$ss,cc,gg2,strt)) 3 cases omitted due to missing values Tests: stat pv df 1 1.008453 0.6039725 2 2 2.728735 0.2555423 2 Estimates and Variances: $est 1 2 3 a 1 0.2105985 NA NA b 1 0.2987226 0.3888341 0.3888341 c 1 0.3082577 0.4989848 NA a 2 0.3156040 NA NA b 2 0.3408314 0.5661101 0.5661101 c 2 0.2376301 0.2830413 NA $var 1 2 3 a 1 0.006386094 NA NA b 1 0.008392163 0.010391194 0.01039119 c 1 0.008874672 0.012216283 NA a 2 0.008549829 NA NA b 2 0.009203557 0.011899088 0.01189909 c 2 0.007656447 0.008944878 NA > print(xx <- cuminc(ss,cc,gg2,strt,subset=d2$X == 1)) 3 cases omitted due to missing values Tests: stat pv df 1 4.716769 0.0945729 2 2 2.696396 0.2597078 2 Estimates and Variances: $est 1 2 3 4 5 a 1 0.1279762 0.1848443 0.1848443 0.1848443 0.1848443 b 1 0.1431818 0.2147727 NA NA NA c 1 0.3740171 0.4874823 0.5757330 NA NA a 2 0.2085623 0.3033425 0.5080678 0.5080678 0.5080678 b 2 0.3795455 0.6062500 NA NA NA c 2 0.2004884 0.2477656 0.2477656 NA NA $var 1 2 3 4 5 a 1 0.005087085 0.007761560 0.007761560 0.00776156 0.00776156 b 1 0.006224509 0.010655685 NA NA NA c 1 0.010614083 0.013441268 0.017054461 NA NA a 2 0.007382690 0.009967497 0.022418302 0.02241830 0.02241830 b 2 0.012049806 0.019716303 NA NA NA c 2 0.006846162 0.008398669 0.008398669 NA NA > attach(d2) > print(xx <- cuminc(ssd,ccd,gg2,strtd,subset=X == 1)) 3 cases omitted due to missing values Tests: stat pv df 1 4.716769 0.0945729 2 2 2.696396 0.2597078 2 Estimates and Variances: $est 1 2 3 4 5 a 1 0.1279762 0.1848443 0.1848443 0.1848443 0.1848443 b 1 0.1431818 0.2147727 NA NA NA c 1 0.3740171 0.4874823 0.5757330 NA NA a 2 0.2085623 0.3033425 0.5080678 0.5080678 0.5080678 b 2 0.3795455 0.6062500 NA NA NA c 2 0.2004884 0.2477656 0.2477656 NA NA $var 1 2 3 4 5 a 1 0.005087085 0.007761560 0.007761560 0.00776156 0.00776156 b 1 0.006224509 0.010655685 NA NA NA c 1 0.010614083 0.013441268 0.017054461 NA NA a 2 0.007382690 0.009967497 0.022418302 0.02241830 0.02241830 b 2 0.012049806 0.019716303 NA NA NA c 2 0.006846162 0.008398669 0.008398669 NA NA > print(xx <- cuminc(ssd,ccd,gg2,strtd,subset=gg != 'b')) Tests: stat pv df 1 3.5151549 0.06080997 1 2 0.1400145 0.70826655 1 Estimates and Variances: $est 1 2 3 4 5 a 1 0.1311269 0.2699184 0.3420625 0.3420625 0.3420625 c 1 0.3816280 0.4889137 0.5723581 NA NA a 2 0.2257601 0.2972171 0.4415053 0.4415053 0.4415053 c 2 0.2160508 0.2607532 0.2607532 NA NA $var 1 2 3 4 5 a 1 0.003922836 0.009113464 0.012507959 0.01250796 0.01250796 c 1 0.009854126 0.012351948 0.015575726 NA NA a 2 0.005947601 0.007356628 0.014479506 0.01447951 0.01447951 c 2 0.006497566 0.007867543 0.007867543 NA NA > print(xx <- cuminc(ssd,ccd,gg2,strtd,subset=ggd != 'b')) Tests: stat pv df 1 3.5151549 0.06080997 1 2 0.1400145 0.70826655 1 Estimates and Variances: $est 1 2 3 4 5 a 1 0.1311269 0.2699184 0.3420625 0.3420625 0.3420625 c 1 0.3816280 0.4889137 0.5723581 NA NA a 2 0.2257601 0.2972171 0.4415053 0.4415053 0.4415053 c 2 0.2160508 0.2607532 0.2607532 NA NA $var 1 2 3 4 5 a 1 0.003922836 0.009113464 0.012507959 0.01250796 0.01250796 c 1 0.009854126 0.012351948 0.015575726 NA NA a 2 0.005947601 0.007356628 0.014479506 0.01447951 0.01447951 c 2 0.006497566 0.007867543 0.007867543 NA NA > print(xx <- cuminc(ssd,ccd,gg2,strtd,subset=gg2 != 'b')) 3 cases omitted due to missing values Tests: stat pv df 1 3.5151549 0.06080997 1 2 0.1400145 0.70826655 1 Estimates and Variances: $est 1 2 3 4 5 a 1 0.1311269 0.2699184 0.3420625 0.3420625 0.3420625 c 1 0.3816280 0.4889137 0.5723581 NA NA a 2 0.2257601 0.2972171 0.4415053 0.4415053 0.4415053 c 2 0.2160508 0.2607532 0.2607532 NA NA $var 1 2 3 4 5 a 1 0.003922836 0.009113464 0.012507959 0.01250796 0.01250796 c 1 0.009854126 0.012351948 0.015575726 NA NA a 2 0.005947601 0.007356628 0.014479506 0.01447951 0.01447951 c 2 0.006497566 0.007867543 0.007867543 NA NA > detach(d2) > > cv <- matrix(sample(0:1,3*100,replace=TRUE),ncol=3) > cv[c(1,10,20)] <- NA > print(xx <- crr(ss,cc,cv)) 3 cases omitted due to missing values convergence: TRUE coefficients: cv1 cv2 cv3 -0.29130 -0.06346 -0.47510 standard errors: [1] 0.3698 0.3566 0.3544 two-sided p-values: cv1 cv2 cv3 0.43 0.86 0.18 > cov2 <- cbind(cv[,1],cv[,1]) > tf <- function(uft) cbind(uft,uft^2) > print(ww <- crr(ss,cc,cv,cov2,tf=tf,cengroup=cv[,3])) 3 cases omitted due to missing values convergence: TRUE coefficients: cv1 cv2 cv3 cov21*uft cov22*tf2 0.02944 -0.06263 -0.42160 -0.84780 0.29850 standard errors: [1] 0.8029 0.3583 0.3595 1.3090 0.4004 two-sided p-values: cv1 cv2 cv3 cov21*uft cov22*tf2 0.97 0.86 0.24 0.52 0.46 > plot(ww$uft,ww$res[,1]) > lines(lowess(ww$uft,ww$res[,1],iter=0,f=.75)) > print(wp <- predict(ww,rbind(c(1,1,1),c(0,0,0)),rbind(c(1,1),c(0,0)))) [,1] [,2] [,3] [1,] 0.06246194 0.008345203 0.01381136 [2,] 0.09786020 0.016721921 0.02799111 [3,] 0.13602406 0.025009866 0.04235389 [4,] 0.18390522 0.033273945 0.05710125 [5,] 0.26471120 0.041754133 0.07301143 [6,] 0.28678273 0.050225177 0.08901147 [7,] 0.31027641 0.058637012 0.10501213 [8,] 0.33519487 0.067025773 0.12108626 [9,] 0.39744032 0.075343709 0.13750391 [10,] 0.41997041 0.083655640 0.15396776 [11,] 0.42598719 0.092000584 0.17038559 [12,] 0.51517185 0.100319016 0.18741181 [13,] 0.52041769 0.108625866 0.20426566 [14,] 0.66116579 0.116924371 0.22209367 [15,] 0.66629928 0.125218167 0.23971535 [16,] 0.68071685 0.133587124 0.25736827 [17,] 0.72376095 0.141928165 0.27503823 [18,] 0.76292157 0.150413747 0.29303279 [19,] 0.83195027 0.158786065 0.31096864 [20,] 0.99487195 0.167078366 0.32932628 [21,] 1.00385049 0.175426033 0.34753107 [22,] 1.34699176 0.184027027 0.36689077 [23,] 1.52725592 0.194206812 0.38927550 [24,] 1.56248132 0.204500082 0.41132235 [25,] 1.85467950 0.217642436 0.43739727 [26,] 1.93791303 0.232103772 0.46459689 [27,] 2.08096688 0.248451634 0.49291950 [28,] 2.22551104 0.267544962 0.52293238 [29,] 2.23866481 0.286966924 0.55219966 [30,] 2.99739926 0.314891008 0.57604023 [31,] 5.24864987 0.389042862 0.57779641 attr(,"class") [1] "predict.crr" > plot(wp) > plot(wp,lty=1,col=c(2,4)) > d2 <- cbind(d2,cv3=cv[,3],cv1=cv[,1]) > attach(d2) > print(ww <- crr(ssd,ccd,cbind(cv[,1:2],cv3),cov2,tf=tf,cengroup=cv3)) 3 cases omitted due to missing values convergence: TRUE coefficients: cbind(cv[, 1:2], cv3)1 cbind(cv[, 1:2], cv3)2 cv3 0.02944 -0.06263 -0.42160 cov21*uft cov22*tf2 -0.84780 0.29850 standard errors: [1] 0.8029 0.3583 0.3595 1.3090 0.4004 two-sided p-values: cbind(cv[, 1:2], cv3)1 cbind(cv[, 1:2], cv3)2 cv3 0.97 0.86 0.24 cov21*uft cov22*tf2 0.52 0.46 > print(ww <- crr(ssd,ccd,cbind(cv[,1:2],cv3),cov2,tf=tf)) 3 cases omitted due to missing values convergence: TRUE coefficients: cbind(cv[, 1:2], cv3)1 cbind(cv[, 1:2], cv3)2 cv3 0.03695 -0.05995 -0.46280 cov21*uft cov22*tf2 -0.89860 0.32020 standard errors: [1] 0.7862 0.3579 0.3538 1.2180 0.3547 two-sided p-values: cbind(cv[, 1:2], cv3)1 cbind(cv[, 1:2], cv3)2 cv3 0.96 0.87 0.19 cov21*uft cov22*tf2 0.46 0.37 > print(ww <- crr(ssd,ccd,cbind(cv[,1:2],cv3),cbind(cv1,cv1),tf=tf,cengroup=cv3)) 3 cases omitted due to missing values convergence: TRUE coefficients: cbind(cv[, 1:2], cv3)1 cbind(cv[, 1:2], cv3)2 cv3 0.02944 -0.06263 -0.42160 cv1*uft cv1*tf2 -0.84780 0.29850 standard errors: [1] 0.8029 0.3583 0.3595 1.3090 0.4004 two-sided p-values: cbind(cv[, 1:2], cv3)1 cbind(cv[, 1:2], cv3)2 cv3 0.97 0.86 0.24 cv1*uft cv1*tf2 0.52 0.46 > print(ww <- crr(ssd,ccd,cbind(cv[,1:2],cv3),cbind(cv1,cv1),tf=tf,cengroup=cv3,subset=X == 1)) 3 cases omitted due to missing values convergence: TRUE coefficients: cbind(cv[, 1:2], cv3)1 cbind(cv[, 1:2], cv3)2 cv3 0.9918 0.1967 -0.2967 cv1*uft cv1*tf2 -1.8020 0.4035 standard errors: [1] 1.0290 0.4336 0.4546 1.3700 0.3009 two-sided p-values: cbind(cv[, 1:2], cv3)1 cbind(cv[, 1:2], cv3)2 cv3 0.33 0.65 0.51 cv1*uft cv1*tf2 0.19 0.18 > print(summary(ww)) Competing Risks Regression Call: crr(ftime = ssd, fstatus = ccd, cov1 = cbind(cv[, 1:2], cv3), cov2 = cbind(cv1, cv1), tf = tf, cengroup = cv3, subset = X == 1) coef exp(coef) se(coef) z p-value cbind(cv[, 1:2], cv3)1 0.992 2.696 1.029 0.964 0.33 cbind(cv[, 1:2], cv3)2 0.197 1.217 0.434 0.454 0.65 cv3 -0.297 0.743 0.455 -0.653 0.51 cv1*uft -1.802 0.165 1.370 -1.315 0.19 cv1*tf2 0.403 1.497 0.301 1.341 0.18 exp(coef) exp(-coef) 2.5% 97.5% cbind(cv[, 1:2], cv3)1 2.696 0.371 0.3590 20.25 cbind(cv[, 1:2], cv3)2 1.217 0.821 0.5204 2.85 cv3 0.743 1.345 0.3049 1.81 cv1*uft 0.165 6.064 0.0112 2.42 cv1*tf2 1.497 0.668 0.8300 2.70 Num. cases = 77 (3 cases omitted due to missing values) Pseudo Log-likelihood = -79.2 Pseudo likelihood ratio test = 2.53 on 5 df, > detach(d2) > print(ww <- crr(ss,cc,cv,cov2,tf=tf,cengroup=cv[,3],subset=d2$X==1)) 3 cases omitted due to missing values convergence: TRUE coefficients: cv1 cv2 cv3 cov21*uft cov22*tf2 0.9918 0.1967 -0.2967 -1.8020 0.4035 standard errors: [1] 1.0290 0.4336 0.4546 1.3700 0.3009 two-sided p-values: cv1 cv2 cv3 cov21*uft cov22*tf2 0.33 0.65 0.51 0.19 0.18 > print(ww <- crr(ss,cc,cv,cov2,tf=tf,cengroup=cv[,3],failcode=2)) 3 cases omitted due to missing values convergence: TRUE coefficients: cv1 cv2 cv3 cov21*uft cov22*tf2 -0.05102 -0.43670 0.38270 0.93320 -0.41840 standard errors: [1] 0.7200 0.3379 0.3738 1.2430 0.4037 two-sided p-values: cv1 cv2 cv3 cov21*uft cov22*tf2 0.94 0.20 0.31 0.45 0.30 > print(ww <- crr(ss,cc,cv,cov2,tf=tf,cengroup=cv[,3],cencode=2)) 3 cases omitted due to missing values convergence: TRUE coefficients: cv1 cv2 cv3 cov21*uft cov22*tf2 0.06643 -0.16260 -0.19010 -0.86200 0.32170 standard errors: [1] 0.7965 0.3492 0.3795 1.4070 0.4516 two-sided p-values: cv1 cv2 cv3 cov21*uft cov22*tf2 0.93 0.64 0.62 0.54 0.48 > print(ww <- crr(ss,cc,cv[,1])) 3 cases omitted due to missing values convergence: TRUE coefficients: cv[, 1]1 -0.1753 standard errors: [1] 0.354 two-sided p-values: cv[, 1]1 0.62 > print(ww <- crr(ss,cc,cov2=cv[,1],tf=function(x) x)) 3 cases omitted due to missing values convergence: TRUE coefficients: cv[, 1]1*tf1 0.007688 standard errors: [1] 0.2191 two-sided p-values: cv[, 1]1*tf1 0.97 > print(summary(ww)) Competing Risks Regression Call: crr(ftime = ss, fstatus = cc, cov2 = cv[, 1], tf = function(x) x) coef exp(coef) se(coef) z p-value cv[, 1]1*tf1 0.00769 1.01 0.219 0.0351 0.97 exp(coef) exp(-coef) 2.5% 97.5% cv[, 1]1*tf1 1.01 0.992 0.656 1.55 Num. cases = 97 (3 cases omitted due to missing values) Pseudo Log-likelihood = -125 Pseudo likelihood ratio test = 0 on 1 df, > > proc.time() user system elapsed 1.20 0.12 1.32