I have what I think to be a very simple question - I have a dataframe:
a <- c(1,2,3,4,5)
b <- (a/lag(a))-1
combining the two gives me a data frame:
df <- cbind(a,b)
a b
[1,] 1 NA
[2,] 2 1.0000000
[3,] 3 0.5000000
[4,] 4 0.3333333
[5,] 5 0.2500000
Now suppose I want to forecast (or put simply grow a
) by the last growth rate in b
. So for example, df$a[6] = df$a[5]*(1+df$b[5])
, and df$a[7] = df$a[6]*(1+df$b[5])
, up to n
.
This kind of thing is obviously very easy to do in excel, but I can't seem to figure it out in R.
How do functions like predict()
or forecast()
work, especially when the variable is only autoregressive?