# NOT RUN {
#===================================================
# Loading the library and its dependencies
#===================================================
library("PRIMsrc")
# }
# NOT RUN {
#===================================================
# PRIMsrc Package news
#===================================================
PRIMsrc.news()
#===================================================
# PRIMsrc Package citation
#===================================================
citation("PRIMsrc")
#===================================================
# Demo with a synthetic dataset
# Use help for descriptions
#===================================================
data("Synthetic.1", package="PRIMsrc")
?Synthetic.1
# }
# NOT RUN {
#===================================================
# Simulated dataset #1 (n=250, p=3)
# Peeling criterion = LRT
# Cross-Validation criterion = LRT
# With Combined Cross-Validation (RCCV)
# Without Replications (B = 1)
# Without variable screening (pre-selection)
# Without computation of log-rank \eqn{p}-values
# Without parallelization
#===================================================
synt1 <- sbh(X = Synthetic.1[ , -c(1,2), drop=FALSE],
y = Synthetic.1[ ,1, drop=TRUE],
delta = Synthetic.1[ ,2, drop=TRUE],
B = 1,
K = 3,
vs = FALSE,
cv = TRUE,
cvtype = "combined",
cvarg = "alpha=0.10,
beta=0.10,
peelcriterion=\"lrt\",
cvcriterion=\"lrt\"",
groups = NULL,
pv = FALSE,
decimals = 2,
onese = FALSE,
probval = 0.5,
timeval = NULL,
parallel.vs = FALSE,
parallel.rep = FALSE,
parallel.pv = FALSE,
conf = NULL,
verbose = FALSE,
seed = 123)
summary(object = synt1)
print(x = synt1)
n <- 100
p <- length(synt1$cvfit$cv.used)
x <- matrix(data = runif(n = n*p, min = 0, max = 1),
nrow = n, ncol = p, byrow = FALSE,
dimnames = list(1:n, paste("X", 1:p, sep="")))
synt1.pred <- predict(object = synt1,
newdata = x,
steps = synt1$cvfit$cv.nsteps)
plot(x = synt1,
main = paste("Scatter plot for model #1", sep=""),
proj = c(1,2),
steps = synt1$cvfit$cv.nsteps,
pch = 16, cex = 0.5, col = c(1,2),
boxes = TRUE,
col.box = 2, lty.box = 2, lwd.box = 1,
add.caption.box = TRUE,
text.caption.box = paste("Step: ", synt1$cvfit$cv.nsteps, sep=""),
device = NULL)
plot_profile(object = synt1,
main = "Cross-validated tuning profiles for model #1",
pch = 20, col = 1, lty = 1, lwd = 0.5, cex = 0.5,
add.sd = TRUE,
add.profiles = TRUE,
add.caption = TRUE,
text.caption = c("Mean","Std. Error"),
device = NULL)
plot_traj(object = synt1,
main = paste("Cross-validated peeling trajectories for model #1", sep=""),
col = 1, lty = 1, lwd = 0.5, cex = 0.5,
toplot = synt1$cvfit$cv.used,
device = NULL)
plot_trace(object = synt1,
main = paste("Cross-validated trace plots for model #1", sep=""),
xlab = "Box Mass", ylab = "Covariate Range (centered)",
col = 1, lty = 1, lwd = 0.5, cex = 0.5,
toplot = synt1$cvfit$cv.used,
center = TRUE, scale = FALSE,
device = NULL)
plot_km(object = synt1,
main = paste("Cross-validated probability curves for model #1", sep=""),
xlab = "Time", ylab = "Probability",
ci = TRUE,
steps = 1:synt1$cvfit$cv.nsteps,
col = c(1,2), lty = 1, lwd = 0.5, cex = 0.5,
add.caption = TRUE,
text.caption = c("outbox","inbox"),
device = NULL)
# }
# NOT RUN {
#===================================================
# Examples of parallel backend parametrization
#===================================================
if (require("parallel")) {
cat("'parallel' is attached correctly \n")
} else {
stop("'parallel' must be attached first \n")
}
#===================================================
# Ex. #1 - Multicore PC
# Running WINDOWS
# SOCKET communication cluster
# Shared memory parallelization
#===================================================
cpus <- parallel::detectCores(logical = TRUE)
conf <- list("spec" = rep("localhost", cpus),
"type" = "SOCKET",
"homo" = TRUE,
"verbose" = TRUE,
"outfile" = "")
#===================================================
# Ex. #2 - Master node + 3 Worker nodes cluster
# All nodes equipped with identical setups of multicores
# (8 core CPUs per machine for a total of 32)
# SOCKET communication cluster
# Distributed memory parallelization
#===================================================
masterhost <- Sys.getenv("HOSTNAME")
slavehosts <- c("compute-0-0", "compute-0-1", "compute-0-2")
nodes <- length(slavehosts) + 1
cpus <- 8
conf <- list("spec" = c(rep(masterhost, cpus),
rep(slavehosts, cpus)),
"type" = "SOCKET",
"homo" = TRUE,
"verbose" = TRUE,
"outfile" = "")
#===================================================
# Ex. #3 - Enterprise Multinode Cluster w/ multicore/node
# Running LINUX with SLURM scheduler
# MPI communication cluster
# Distributed memory parallelization
#==================================================
if (require("Rmpi")) {
cat("'Rmpi' is attached correctly \n")
} else {
stop("'Rmpi' must be attached first \n")
}
# Below, variable 'cpus' is the total number of requested
# taks (threads/CPUs), which is specified from within a
# SLURM script.
cpus <- as.numeric(Sys.getenv("SLURM_NTASKS"))
conf <- list("spec" = cpus,
"type" = "MPI",
"homo" = TRUE,
"verbose" = TRUE,
"outfile" = "")
#===================================================
# Simulated dataset #1 (n=250, p=3)
# Peeling criterion = LRT
# Cross-Validation criterion = LRT
# With Combined Cross-Validation (RCCV)
# With Replications (B = 30)
# With PPL variable screening (pre-selection)
# With computation of log-rank \eqn{p}-values
# With parallelization
#===================================================
synt1 <- sbh(X = Synthetic.1[ , -c(1,2), drop=FALSE],
y = Synthetic.1[ ,1, drop=TRUE],
delta = Synthetic.1[ ,2, drop=TRUE],
B = 30,
K = 5,
A = 1000,
vs = TRUE,
vstype = "ppl",
vsarg = "alpha=1,
nalpha=1,
nlambda=100",
vscons = 0.5,
cv = TRUE,
cvtype = "combined",
cvarg = "alpha=0.01,
beta=0.10,
peelcriterion=\"lrt\",
cvcriterion=\"lrt\"",
groups = NULL,
pv = TRUE,
decimals = 2,
onese = FALSE,
probval = 0.5,
timeval = NULL,
parallel.vs = FALSE,
parallel.rep = TRUE,
parallel.pv = TRUE,
conf = conf,
verbose = TRUE,
seed = 123)
#===================================================
# Simulated dataset #4 (n=100, p=1000)
# Peeling criterion = LRT
# Cross-Validation criterion = CER
# With Combined Cross-Validation (RCCV)
# With Replications (B = 30)
# With PRSP variable screening (pre-selection)
# With computation of log-rank \eqn{p}-values
# With parallelization
#===================================================
synt4 <- sbh(X = Synthetic.4[ , -c(1,2), drop=FALSE],
y = Synthetic.4[ ,1, drop=TRUE],
delta = Synthetic.4[ ,2, drop=TRUE],
B = 30,
K = 5,
A = 1000,
vs = TRUE,
vstype = "prsp",
vsarg = "alpha=0.01,
beta=0.10,
msize=NULL,
peelcriterion=\"lrt\",
cvcriterion=\"cer\"",
vscons = 0.5,
cv = TRUE,
cvtype = "combined",
cvarg = "alpha=0.01,
beta=0.10,
peelcriterion=\"lrt\",
cvcriterion=\"cer\"",
groups = NULL,
pv = TRUE,
decimals = 2,
onese = FALSE,
probval = 0.5,
timeval = NULL,
parallel.vs = FALSE,
parallel.rep = TRUE,
parallel.pv = TRUE,
conf = conf,
verbose = TRUE,
seed = 123)
# }
Run the code above in your browser using DataLab