The anova function doesn't allow comparison of glmnet models:
data(QuickStartExample)
x <- QuickStartExample$x; y <- QuickStartExample$y
set.seed(11)
fit1 = glmnet(x[,1:10], y, lambda=0.1)
fit2 = glmnet(x[,11:20], y, lambda=0.1)
anova(fit1, fit2)
Error in UseMethod("anova") :
no applicable method for 'anova' applied to an object of class "c('elnet', 'glmnet')"
Is there an alternative?
EDIT: Based on Roland's comment, I should perform cross-validation
For predictors x[,1:10]:
cv.train.fit1 <- cv.glmnet(x[1:70,1:10], y[1:70])
best.lambda <- cv.train.fit1$lambda.min
fit1 <- glmnet(x[71:100,1:10], y[71:100] ,lambda=best.lambda)
For predictors x[,11:20]:
cv.train.fit2 <- cv.glmnet(x[1:70,11:20], y[1:70])
best.lambda <- cv.train.fit2$lambda.min
fit2 <- glmnet(x[71:100,11:20], y[71:100], lambda=best.lambda)
But the question remains, how can I compare the performance of fit1 and fit2?
cv.glmnet(x,y)for f1 predictors and f2 predictors separately? – locus Dec 07 '23 at 08:00cv.glmneton training data and then test it on test data for both set of predictors? But then how do I compare which set has more predictive power? I edited my question with an example – locus Dec 07 '23 at 09:22