0

I tried searching for an answer for this question of mine, however I could not find anything.

I want to build a model that predicts barley prices for that i came up with 11 variables that may have an impact on the prices. What I tried doing was building a loop that chooses every time one extra variable from my pool of variables and tries different combinations of them and the output would be for every (extra/combination) variable a new VAR-model, so in a sense, it is a combinatorics exercise. After that, i want to implement an in/out of sample testing for each of the models that I came up with to decide which one is the most appropriate. Unfortunately, i am not very familiar with loops and i have been told not to use them on R... As I am a beginner on R, my tryouts won't help you out at all, but if you really require them I am happy to provide them to you.

Many thanks in advance!

  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. It's helpful to at least start with the code you tried. It's not that loops should be avoided all together in R (sometimes they are necessary and faster than other alternatives) but many times there are simply more efficient ways to do things. But it's not easy to give specifics without some starting point in your question. – MrFlick Feb 19 '19 at 16:38
  • Dear @MrFlick, i tried formatting the code, couldn't so here you go DATA <- read.csv("main_data.csv", header=T, sep=";", dec=".") ger <- diff(DATA$Hamburg) matif_wheat <- diff(DATA$Matif_Wheat) agri = cbind(ger, matif_wheat) agri2 <- agri[-(176:178),] #to get rid of tha NAs - I know it is not the best solution but i tired na.action in the var model but it did not work agri_var=VAR(agri2, type="const", lag.max=2, ic="AIC") #dependent variable is DATA$Hamburg (prices) and now I want the VAR for all my other variables (and their combinations) – user11085562 Feb 20 '19 at 09:59

0 Answers0