0

I have written an predictor function on R and I tried several combinations of inputs in the function to see how the output would change.

The problem is that my function takes 4 numeric parameters and I want to test my function by plugging all possible combinations of elements obtained from specified vectors ( vectors have different lengths)

I've tried using replicate, apply and sapply functions but I couldn't get the output that I wanted to see. I can do for loops for each parameter but when it comes to several parameters i need several loops and I don't know how to store the values after this many loops.

So my function looks like this;

predictVAR(Dataset, ColumnNumber, Correlation, Lags, FcastHorizon)

And while keeping the Dataset constant ( or i can just remove it from parameter list and assign it as the default data frame in function)

  • ColumnNumber takes values between 1 and 20 ( each of these are the corresponding variables from Dataset)
  • Correlation will take values in seq(0.15,0.9,by=0.15)
  • Lags will take values in c(10, 20, 30, 50, 80, 100)
  • and finally FcastHorizon will take values from list c(20,252)

So if I started doing this manually and evaluate each combination from these specified vectors, it would look like

  • predictVAR(1, 0.1, 10, 20) => predictVAR(1, 0.1, 10, 252) => predictVAR(1, 0.1, 20, 20) => predictVAR(1, 0.1, 20, 252) . . . . and finally;=> predictVAR(20, 0.9,100 ,252)

By the end of process, I should obtain 20*6*6*2=1440 different outputs and the corresponding input specifications.

Could you help me about what function would help me to obtain the results? I have read topics about the family of apply functions but I need to evaluate the model with all cross combinations and I couldn't find a solution so far.

Regards

yahsin
  • 21
  • 4
  • 1
    Use `expand.grid` to create a matrix with all combinations of your vectors, then use `mapply` to use your `predictVAR` function on each row. If you need more specific help, you need to turn this into a [reproducible example](http://stackoverflow.com/q/5963269/903061). – Gregor Thomas Nov 08 '14 at 02:22
  • Hey Gregor , as you suggested I obtained all possible combinations using "expand.grid" function to evaluate each line of parameter matrix in my function using "mapply". Thank you very much! I will edit my original post soon and add the results soon, so everyone else can benefit from this. Regards. – yahsin Nov 08 '14 at 20:25
  • If you have a working solution, just post it as an answer. (Answering your own question is just fine.) Do read the reproducible example link from my previous comment for your next question though :) – Gregor Thomas Nov 08 '14 at 23:07

0 Answers0