### *
### attach(NULL, name = "CheckExEnv") assign(".CheckExEnv", as.environment(2), pos = length(search())) # base ## add some hooks to label plot pages for base and grid graphics setHook("plot.new", ".newplot.hook") setHook("persp", ".newplot.hook") setHook("grid.newpage", ".gridplot.hook") assign("cleanEx", function(env = .GlobalEnv) { rm(list = ls(envir = env, all.names = TRUE), envir = env) RNGkind("default", "default") set.seed(1) options(warn = 1) assign("T", delay(stop("T used instead of TRUE")), pos = .CheckExEnv) assign("F", delay(stop("F used instead of FALSE")), pos = .CheckExEnv) sch <- search() newitems <- sch[! sch %in% .oldSearch] for(item in rev(newitems)) eval(substitute(detach(item), list(item=item))) missitems <- .oldSearch[! .oldSearch %in% sch] if(length(missitems)) warning("items ", paste(missitems, collapse=", "), " have been removed from the search path") }, env = .CheckExEnv) assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now assign("ptime", proc.time(), env = .CheckExEnv) grDevices::postscript("NPBayes-Examples.ps") assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) library('NPBayes') assign(".oldSearch", search(), env = .CheckExEnv) assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) cleanEx(); ..nameEx <- "Lemma1" ### * Lemma1 flush(stderr()); flush(stdout()) ### Name: Lemma1 ### Title: Conditional expectation with respect to a Dirichlet process ### prior, given right censored data. ### Aliases: Lemma1 ### Keywords: nonparametric survival ### ** Examples uncensored <- c(1,5,9) rightcensored <- c(4,7) NPBayes(B=12, theta=0.2, u=3.2, uncen=uncensored, rightcen=rightcensored) leftpt <- 0 rightpt <- 3 NPBayes(B=12, theta=0.2, u=3.2, uncen=uncensored, rightcen=rightcensored, lefts = leftpt, rights = rightpt) cleanEx(); ..nameEx <- "NPBayes" ### * NPBayes flush(stderr()); flush(stdout()) ### Name: NPBayes ### Title: Nonparametric Bayes estimate of CDF from arbitrary censored data ### Aliases: NPBayes ### Keywords: nonparametric survival ### ** Examples uncensored <- c(1,5,9) rightcensored <- c(4,7) NPBayes(B=12, theta=0.2, u=3.2, uncen=uncensored, rightcen=rightcensored) leftpt <- 0 rightpt <- 3 NPBayes(B=12, theta=0.2, u=3.2, uncen=uncensored, rightcen=rightcensored, lefts = leftpt, rights = rightpt) cleanEx(); ..nameEx <- "NPBayesT" ### * NPBayesT flush(stderr()); flush(stdout()) ### Name: NPBayesT ### Title: Nonparametric Bayes estimate of CDF from left truncated, right ### censored data ### Aliases: NPBayesT ### Keywords: nonparametric survival ### ** Examples trunc <- c(2,4,10) xtime <- c(9,13,15) d <- c(1,0,0) NPBayesT(B=8, theta=0.12, u=3.2, y=trunc, x=xtime, status=d) #you should get 0.6955968 as the Bayes estimator ui <- seq(0.1, 20, 0.1) fui <- ui for(i in 1:200) fui[i] <- NPBayesT(B=8, theta=0.12, u=ui[i],y=trunc, x=xtime, status=d) #plot(ui, fui) ypsy <- c(51, 58, 55, 28, 25, 48, 47, 25, 31, 30, 33, 43, 45, 35, 36) xpsy <- c(52, 59, 57, 50, 57, 59, 61, 61, 62, 67, 68, 69, 69, 65, 76) dpsy <- c(1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1 ) NPBayesT(B=8,theta=0.02,u=56,y=ypsy,x=xpsy,status=dpsy) cleanEx(); ..nameEx <- "NPBayesT2" ### * NPBayesT2 flush(stderr()); flush(stdout()) ### Name: NPBayesT2 ### Title: Nonparametric Bayes estimate of CDF from left truncated, right ### censored data ### Aliases: NPBayesT2 ### Keywords: nonparametric survival ### ** Examples trunc <- c(2,4,10) xtime <- c(9,13,15) d <- c(1,0,0) NPBayesT(B=8, theta=0.12, u=3.2, y=trunc, x=xtime, status=d) ui <- seq(0.1, 20, 0.1) fui <- ui for(i in 1:200) fui[i] <- NPBayesT(B=8, theta=0.12, u=ui[i],y=trunc, x=xtime, status=d) #plot(ui, fui) ypsy <- c(51, 58, 55, 28, 25, 48, 47, 25, 31, 30, 33, 43, 45, 35, 36) xpsy <- c(52, 59, 57, 50, 57, 59, 61, 61, 62, 67, 68, 69, 69, 65, 76) dpsy <- c(1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1 ) NPBayesT(B=8,theta=0.02,u=56,y=ypsy,x=xpsy,status=dpsy) cleanEx(); ..nameEx <- "NewLemma1" ### * NewLemma1 flush(stderr()); flush(stdout()) ### Name: NewLemma1 ### Title: Compute the Conditional Expectation given left truncated and ### right censored observations ### Aliases: NewLemma1 ### Keywords: nonparametric survival ### ** Examples uncensored <- c(1,5,9) rightcensored <- c(4,7) NPBayes(B=12, theta=0.2, u=3.2, uncen=uncensored, rightcen=rightcensored) leftpt <- 0 rightpt <- 3 NPBayes(B=12, theta=0.2, u=3.2, uncen=uncensored, rightcen=rightcensored, lefts = leftpt, rights = rightpt) ### *