Hi!
So here is the deal. I have never been able to get a for loop to run. I have tried a couple of times but given up, mostly because it hasnt been necessary. But this time I really need to understand how to make it work, as otherwise my script will become too long. I have gone through loads of pages that shows examples, but no example that solves my case.
A classical example would be:
for (x in 1:5) {
print(x)
}
And this is exactly what I am trying to achieve, but instead for print, I want the following:
for (i in 1:15) {
grangertest(COL ~ ALL[, i], order = 3, data = ALL)
}
That is, I have a time series object called ALL, which has 15 time series representing 15 columns, and I want to perform a grangertest on all series. Simple as that. But I dont understand why my loop doesn't work. I get the following error message:
"Error in waldtest.lm(fm, 2, ...) :
there are aliased coefficients in the model"
Isn't this a multicollinearity thing? Why doesn't it just loop over each column one at a time?
If I do it for one column at a time, it works properly:
grangertest(COL ~ ALL[, i], order = 3, data = ALL)
Any help appreciated!