################################################### ### chunk number 1: ################################################### options(prompt = "R> ", continue = "+ ") ################################################### ### chunk number 2: ################################################### ## set output line size options(width = 65) library("interval") library("coin") ################################################### ### chunk number 3: ################################################### library("interval") data("bcos", package = "interval") head(bcos) ################################################### ### chunk number 4: ################################################### fit1<-icfit(Surv(left, right, type = "interval2")~treatment, data = bcos) summary(fit1) ################################################### ### chunk number 5: ################################################### plot(fit1) ################################################### ### chunk number 6: ################################################### icout<-ictest(Surv(left, right, type = "interval2")~treatment, data = bcos) icout ################################################### ### chunk number 7: ################################################### plot(fit1, dtype = "link") ################################################### ### chunk number 8: ################################################### ictest(Surv(left, right, type = "interval2")~treatment, data = bcos, initfit = icout$fit, scores = "logrank2") ################################################### ### chunk number 9: ################################################### L<-with(bcos, left) R<-with(bcos, right) trt<-with(bcos, treatment) ictest(L, R, trt, scores = "wmw", initfit = icout$fit) ################################################### ### chunk number 10: ################################################### set.seed(1232) ################################################### ### chunk number 11: ################################################### fakeTrtGrps<-sample(letters[1:4], nrow(bcos), replace = TRUE) ictest(L, R, fakeTrtGrps) ################################################### ### chunk number 12: ################################################### set.seed(931) ################################################### ### chunk number 13: ################################################### fakeZ<-rnorm(nrow(bcos)) ictest(L, R, fakeZ, alternative = "less") ################################################### ### chunk number 14: ################################################### ictest(Surv(left, right, type = "interval2")~treatment, data = bcos, exact = TRUE, scores = "logrank1") ################################################### ### chunk number 15: ################################################### ictest(Surv(left, right, type = "interval2")~treatment, data = bcos, initfit = icout$fit, method = "scoretest", scores = "logrank2") ################################################### ### chunk number 16: ################################################### icoutHLY<-ictest(Surv(left, right, type = "interval2")~treatment, data = bcos, initfit = icout$fit, method = "wsr.HLY", mcontrol = mControl(nwsr = 99), scores = "logrank1") icoutHLY ################################################### ### chunk number 17: ################################################### icoutHLY$fit$anypzero ################################################### ### chunk number 18: ################################################### data("ChickWeight", package = "datasets") head(ChickWeight) ################################################### ### chunk number 19: ################################################### permTS(weight~Diet, data = ChickWeight, subset = Diet %in% c(3, 4) & Time == 21) ################################################### ### chunk number 20: ################################################### y3<-with(subset(ChickWeight, Time == 21 & Diet == 3), weight) y4<-with(subset(ChickWeight, Time == 21 & Diet == 4), weight) permTS(y3, y4) ################################################### ### chunk number 21: ################################################### permTS(y3[1:5], y4[1:5]) ################################################### ### chunk number 22: ################################################### permKS(weight~Diet, data = ChickWeight, subset = Time == 21) ################################################### ### chunk number 23: ################################################### y<-ChickWeight[ChickWeight$Time == 21, "weight"] g<-ChickWeight[ChickWeight$Time == 21, "Diet"] permKS(y, g) ################################################### ### chunk number 24: ################################################### permTREND(y, as.numeric(g)) ################################################### ### chunk number 25: ################################################### ## set output line size options(width = 65) ################################################### ### chunk number 26: ################################################### system.time(cm19c10<-chooseMatrix(length(y3)+length(y4), length(y3))) system.time(PC<-permControl(cm = cm19c10)) system.time(permTS(y3, y4, method = "exact.ce", control = PC)) system.time(permTS(y3, y4, method = "exact.network")) ################################################### ### chunk number 27: ################################################### icout<-ictest(Surv(left, right, type = "interval2")~treatment, data = bcos, scores = "wmw") wmw.scores<-icout$scores logistic.scores<-ictest(Surv(left, right, type = "interval2")~treatment, data = bcos, icFIT = icout$fit, scores = "general", dqfunc = function(x){ dlogis(qlogis(x))})$scores max(abs(wmw.scores-logistic.scores)) ################################################### ### chunk number 28: ################################################### library("coin") independence_test(Surv(left, right, type = "interval2")~treatment, data = bcos, ytrafo = wlr_trafo) ################################################### ### chunk number 29: ################################################### SUBSET<-c(1:5, 50:65) independence_test(Surv(left, right, type = "interval2")~treatment, data = bcos, subset = SUBSET, ytrafo = wlr_trafo, distribution = exact()) ictest(Surv(left, right, type = "interval2")~treatment, data = bcos, subset = SUBSET, method = "exact.network") ################################################### ### chunk number 30: ################################################### ictest(Surv(left, right, type = "interval2")~treatment, data = bcos, subset = SUBSET, method = "exact.network", mcontrol = mControl(tsmethod = "abs")) ################################################### ### chunk number 31: ################################################### SUBSET2<-c(1:12, 47:58) system.time( independence_test(Surv(left, right, type = "interval2")~treatment, data = bcos, subset = SUBSET2, ytrafo = wlr_trafo, distribution = exact()) ) system.time( ictest(Surv(left, right, type = "interval2")~treatment, data = bcos, subset = SUBSET2, method = "exact.network", mcontrol = mControl(tsmethod = "abs")) ) ################################################### ### chunk number 32: ################################################### L<-c(2, 5, 1, 1, 9, 8, 10) R<-c(3, 6, 7, 7, 12, 10, 13) group<-c(0, 0, 1, 1, 0, 1, 0) example1<-data.frame(L, R, group) example1 ################################################### ### chunk number 33: ################################################### summary(icfit(L, R), digits = 12) ################################################### ### chunk number 34: ################################################### print(3/14, digits = 12) ################################################### ### chunk number 35: ################################################### score1<-wlr_trafo(Surv(L, R, type = "interval2")) cm<-chooseMatrix(7, 3) T<- ( (1-cm) %*% score1 )/4 - ( cm %*% score1 )/3 cbind(cm, T)[order(T), ][1:9, ]