Solved – Search for interactions using carets rfe function

caretmultiple regressionr

it is straight forward to search for purely additive models using the rfe function in caret. Is it possible to include all interactions as part of the search?
In the train method, we can simply say train(Y~.^2, data) to include interactions, but I have not found a way to do this in rfe.

I could probably just make a data frame where all interactions are included and use that in rfe, but I'm hoping that there is a more elegant solution.

Thanks.

Best Answer

Try using model.matrix function to construct the interactions, e.g. model.matrix(Y~.^2, data), and then pass the resulting matrix to rfe. You might want to strip off the intercept first.