I'd like to compare performance between two models that use different sets of predictors. I'm trying to implement what Roland suggested I did in his answer:
set.seed(42)
data(QuickStartExample)
x <- QuickStartExample$x; y <- QuickStartExample$y
errors <- data.frame(err1=rep(NA,10), err2=rep(NA,10))
for (i in 1:10) {
f <- split(sample(1:80), rep(c(1,2), times=c(64,16)))
train <- f<span class="math-container">$`1`
test <- f$2
cv.train.fit1 <- cv.glmnet(x[train,1:10], y[train])
best.lambda <- cv.train.fit1$lambda.min
fit1 <- glmnet(x[train,1:10], y[train] ,lambda=best.lambda)
cv.train.fit2 <- cv.glmnet(x[train,11:20], y[train])
best.lambda <- cv.train.fit2$lambda.min
fit2 <- glmnet(x[train,11:20], y[train], lambda=best.lambda)
#assess performance on testing fold
errors<span class="math-container">$err1[i] <- sqrt(mean((y[test] - predict(fit1, newx = x[test,1:10]))^2))
errors$err2[i] <- sqrt(mean((y[test] - predict(fit2, newx = x[test,11:20]))^2))
}
holdout.x <- x[81:100]
holdout.y <- y[81:100]
1 - Is it correct to sample the same data multiple times? In my example, different training folds (f$1) could contain identical elements, eg, fold1=[1,4,17,2,...], fold2=[14,1,84,2,...], etc. Is this valid, or do training (and test) folds always need different elements?
2 - How can I evaluate the performance of fit1 vs fit2? Should I run a t-test between errors$err1 and errors$err2?
3 - Roland suggested assessing the final performance of the selected model on holdout data. I reserved the last 20 cases (holdout.x and holdout.y) for that purpose, but I'm unsure what to do with them...