I am using caret package for R to select variables for my model. When using rfe command, one should pass rfeControl object, which has a method parameter. Options for this parameter are boot, cv, LOOCV and LGOCV. Since I am dealing with time series data I need to use special bootstrapping/cross-validation techniques as normal ones do not apply for time series data (otherwise distributions get corrupted etc.).
My question is how would I plug-in my own implementation of bootstrapping but still use caret rfe method, which has every other thing I need.
There isn’t an easy way. If you study the code for
rfe.default()you will note that in cases wheremethod = "boot"thecreateResample()function is used. This is the function that generates the bootstrap samples. Similar functions are used for the other CV methods.There is a hard way; overtake the
create*()function that is most appropriate; say you want to do a block bootstrap or ME bootstrap, take over thecreateResample()function and usemethod = "boot", or if you want a special form of CV, usemethod = "cv"and take overcreateFolds().You will need to write your own
create*()function and replace the one in the caret NAMESPACE with your version. Not easy but eminently doable. Say you write your owncreateResample()function; first you need to note that this function creates n =timesbootstrap samples returning this in a matrix withtimescolumns and as many rows as your have samples. You need to write a customcreateResample()function that returns the same object but which performs the time series bootstrapping you want to employ.Once you have written that function you then need to get it into the caret namespace so that it is used by functions in the caret package. For this you use
assignInNamespace(). Say your new bootstrapping function is calledcreateMyResample()and it is your workspace, to insert this into the caret namespace do:Sorry I can’t be more specific but you don’t say how you want the bootstrap/CV to be performed nor what R code you want to use to do the resampling. If you provide further details on how you would do the resampling I will take another look and see if I can help you write your
create*()function.Failing all of this, contact Max Kuhn, the author and maintainer of caret; he may be able to advice further or at least you can suggest this feature as a wish-list for a future version.