# NOT RUN {
###################################################
# Generate a sample dataset.
###################################################
# set the random seed
set.seed(20)
# set the number of observations
n <- 200
# set the number of covariates
p <- 20
# generate covariates data
Xdat <- matrix(runif((n*p), -5,5), nrow = n, ncol = p)
colnames(Xdat) <- paste("x", c(1:p), sep = "")
# generate random coefficients
betaVec <- rnorm(6)
# calculate the linear predictor data
lindat <- 3 * (Xdat[,1] < 2 & Xdat[,1] > -2) + -3 * (Xdat[,1] > 2 | Xdat[,1] < -2) +
0.5 * (Xdat[,2] + Xdat[, 3] + Xdat[,4] + Xdat[, 5])
# calculate the probabilities
pdat <- 1/(1 + exp(-lindat))
# generate the response data
ydat <- sapply(pdat, function(x) rbinom(1, 1, x))
# generate the dataset
dat <- data.frame(y = ydat, Xdat)
###################################################
# Obtain the testing result
###################################################
# 50 percent training set
testRes1 <- BAGofT(testModel = testGlmnet(formula = y~., alpha = 1),
data = dat,
ne = n*0.5,
nsplits = 20,
nsim = 40)
# 75 percent training set
testRes2 <- BAGofT(testModel = testGlmnet(formula = y~., alpha = 1),
data = dat,
ne = n*0.75,
nsplits = 20,
nsim = 40)
# 90 percent training set
testRes3 <- BAGofT(testModel = testGlmnet(formula = y~., alpha = 1),
data = dat,
ne = n*0.9,
nsplits = 20,
nsim = 40)
# print the testing result.
print(c(testRes1$p.value, testRes2$p.value, testRes3$p.value))
# }
Run the code above in your browser using DataLab