With every iteration of the loop, I'd like to fit a linear model using more historical data and see how, for example, the one-step ahead prediction compares to the actual. The code should be self-explanatory. The problem seems to be that Dependent and Independent are fixed in size after the first iteration (which I'd like to start at 10 data points, as shown in the code), whereas I'd like them to be dynamically sized.
output1 <- rep(0, 127)
output2 <- rep(0, 127)
ret <- function(x, y)
{
for (i in 1:127)
{
Dependent <- y[1:(9+i)]
Independent <- x[1:(9+i)]
fit <- lm(Dependent ~ Independent)
nextInput <- data.frame(Independent = x[(10+i)])
prediction <- predict(fit, nextInput, interval="prediction")
output1[i] <- prediction[2]
output2[i] <- prediction[3]
}
}