# NOT RUN {
#--------------------------------------------------------------------------
# Example: ElasticBoost simulation
# Compare l2boost and elasticNetBoosting using 10-fold CV
#
# Elastic net simulation, see Zou H. and Hastie T. Regularization and
# variable selection via the elastic net. J. Royal Statist. Soc. B,
# 67(2):301-320, 2005
set.seed(1025)
dta <- elasticNetSim(n=100)
# The default values set up the signal on 3 groups of 5 variables,
# Color the signal variables red, others are grey.
sig <- c(rep("red", 15), rep("grey", 40-15))
# Set the boosting parameters
Mtarget = 1000
nuTarget = 1.e-2
# For CRAN, only use 2 cores in the CV method
cvCores=2
# 10 fold l2boost CV
cv.obj <- cv.l2boost(dta$x,dta$y,M=Mtarget, nu=nuTarget, cores=cvCores)
# Plot the results
par(mfrow=c(2,3))
plot(cv.obj)
abline(v=cv.obj$opt.step, lty=2, col="grey")
plot(cv.obj$fit, type="coef", ylab=expression(beta[i]))
abline(v=cv.obj$opt.step, lty=2, col="grey")
plot(coef(cv.obj$fit, m=cv.obj$opt.step), cex=.5,
ylab=expression(beta[i]), xlab="Column Index", ylim=c(0,140), col=sig)
# elasticBoost l1-regularization parameter lambda=0.1
# 5 fold elasticNet CV
cv.eBoost <- cv.l2boost(dta$x,dta$y,M=Mtarget, K=5, nu=nuTarget, lambda=.1, cores=cvCores)
# plot the results
plot(cv.eBoost)
abline(v=cv.eBoost$opt.step, lty=2, col="grey")
plot(cv.eBoost$fit, type="coef", ylab=expression(beta[i]))
abline(v=cv.eBoost$opt.step, lty=2, col="grey")
plot(coef(cv.eBoost$fit, m=cv.obj$opt.step), cex=.5,
ylab=expression(beta[i]), xlab="Column Index", ylim=c(0,140), col=sig)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab