R : Copyright 2004, The R Foundation for Statistical Computing Version 2.0.1 (2004-11-15), ISBN 3-900051-07-0 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 a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > 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) [1] 0.6075005 > > leftpt <- 0 > rightpt <- 3 > NPBayes(B=12, theta=0.2, u=3.2, uncen=uncensored, rightcen=rightcensored, + lefts = leftpt, rights = rightpt) [1] 0.5737505 > > > > 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) [1] 0.6075005 > > leftpt <- 0 > rightpt <- 3 > NPBayes(B=12, theta=0.2, u=3.2, uncen=uncensored, rightcen=rightcensored, + lefts = leftpt, rights = rightpt) [1] 0.5737505 > > > > 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) [1] 0.6955968 > #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) [1] 0.4242773 > > > > 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) [1] 0.6955968 > > 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) [1] 0.4242773 > > > > 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) [1] 0.6075005 > > leftpt <- 0 > rightpt <- 3 > NPBayes(B=12, theta=0.2, u=3.2, uncen=uncensored, rightcen=rightcensored, + lefts = leftpt, rights = rightpt) [1] 0.5737505 > > > > ### *