set.seed(0)
n = 500
p = 100 #Can be changed to a much larger number say 100000
x = matrix(rnorm(2*n*p),2*n,p)
eta = 1 * x[,1] + 2 * x[,3] + 3*x[,6] + 4*x[,1]*x[,3] + 5*x[,1]*x[,6]
y = eta + rnorm(2*n)
xtr = x[1:n, ]
ytr = y[1:n]
xte = x[(n+1):(2*n), ]
yte = y[(n+1):(2*n)]
fit1 = RAMP(xtr, ytr)
ypred = predict(fit1,xte)
####binary prediction
y = rbinom(2*n, 1, 1/(1+exp(-eta)))
xtr = x[1:n, ]
ytr = y[1:n]
xte = x[(n+1):(2*n), ]
yte = y[(n+1):(2*n)]
fit2 = RAMP(xtr, ytr,family='binomial')
ypred = predict(fit2,xte,type='class')
mean(ypred!=yte) ##classification error on the test set
ypred = predict(fit2,type='class')
mean(ypred!=ytr) ##classification error on the training set
Run the code above in your browser using DataLab