# NOT RUN {
# }
# NOT RUN {
# Start the graphics device driver to save all plots in a pdf format
pdf(file = "BSWiMS.model.Example.pdf",width = 8, height = 6)
# Get the stage C prostate cancer data from the rpart package
data(stagec,package = "rpart")
options(na.action = 'na.pass')
stagec_mat <- cbind(pgstat = stagec$pgstat,
pgtime = stagec$pgtime,
as.data.frame(model.matrix(Surv(pgtime,pgstat) ~ .*.,stagec))[-1])
fnames <- colnames(stagec_mat)
fnames <- str_replace_all(fnames,":","__")
colnames(stagec_mat) <- fnames
dataCancerImputed <- nearestNeighborImpute(stagec_mat)
# Get a Cox proportional hazards model using:
# - The default parameters
md <- BSWiMS.model(formula = Surv(pgtime, pgstat) ~ 1,
data = dataCancerImputed)
#Plot the bootstrap validation
pt <- plot(md$BSWiMS.model$bootCV)
#Get the coefficients summary
sm <- summary(md)
print(sm$coefficients)
#Plot the bagged model
pl <- plotModels.ROC(cbind(dataCancerImputed$pgstat,
predict(md,dataCancerImputed)),
main = "Bagging Predictions")
# Get a Cox proportional hazards model using:
# - The default parameters but repeated 10 times
md <- BSWiMS.model(formula = Surv(pgtime, pgstat) ~ 1,
data = dataCancerImputed,
NumberofRepeats = 10)
#Get the coefficients summary
sm <- summary(md)
print(sm$coefficients)
#Check all the formulas
print(md$formula.list)
#Plot the bagged model
pl <- plotModels.ROC(cbind(dataCancerImputed$pgstat,
predict(md,dataCancerImputed)),
main = "Bagging Predictions")
# Get a regression of the survival time
timeSubjects <- dataCancerImputed
timeSubjects$pgtime <- log(timeSubjects$pgtime)
md <- BSWiMS.model(formula = pgtime ~ 1,
data = timeSubjects,
)
pt <- plot(md$BSWiMS.model$bootCV)
sm <- summary(md)
print(sm$coefficients)
# Get a logistic regression model using
# - The default parameters and removing time as possible predictor
data(stagec,package = "rpart")
stagec$pgtime <- NULL
stagec_mat <- cbind(pgstat = stagec$pgstat,
as.data.frame(model.matrix(pgstat ~ .*.,stagec))[-1])
fnames <- colnames(stagec_mat)
fnames <- str_replace_all(fnames,":","__")
colnames(stagec_mat) <- fnames
dataCancerImputed <- nearestNeighborImpute(stagec_mat)
md <- BSWiMS.model(formula = pgstat ~ 1,
data = dataCancerImputed)
pt <- plot(md$BSWiMS.model$bootCV)
sm <- summary(md)
print(sm$coefficients)
# Get a ordinal regression of grade model using GBSG2 data
# - The default parameters and removing the
# time and status as possible predictor
data("GBSG2", package = "TH.data")
# Prepare the model frame for prediction
GBSG2$time <- NULL;
GBSG2$cens <- NULL;
GBSG2_mat <- cbind(tgrade = as.numeric(GBSG2$tgrade),
as.data.frame(model.matrix(tgrade~.*.,GBSG2))[-1])
fnames <- colnames(GBSG2_mat)
fnames <- str_replace_all(fnames,":","__")
colnames(GBSG2_mat) <- fnames
md <- BSWiMS.model(formula = tgrade ~ 1,
data = GBSG2_mat)
sm <- summary(md$oridinalModels$theBaggedModels[[1]]$bagged.model)
print(sm$coefficients)
sm <- summary(md$oridinalModels$theBaggedModels[[2]]$bagged.model)
print(sm$coefficients)
print(table(GBSG2_mat$tgrade,predict(md,GBSG2_mat)))
# Shut down the graphics device driver
dev.off()
# }
Run the code above in your browser using DataLab