pkpkPPkafa - 1 year ago 147

R Question

I am working on doing a recursive ARIMA regression. I think I am one the right track (see the code below), but have a problem when I put out the coefficients into vectors. Simply put, the coefficient are all the same, whereas the should have been different.

`rolling.arima <- lapply(seq(72,nrow(udb)),`

function(x) arima(udb.train,

order = c(1,1,0), seasonal = list(order = c(1,0,0), period = 12)))

all_slopes1 <- unlist(sapply(1:42, function(j) rolling.arima[[j]]$coef[1]))

all_slopes2 <- unlist(sapply(1:42, function(j) rolling.arima[[j]]$coef[2]))

plot.ts(all_slopes1)

plot.ts(all_slopes2)

Anyone who can spot the problem?

Answer Source

As stated in the comments, you need to update your data in every window. Try something like this:

```
rolling.arima <- lapply(seq(72,length(udb.train)),
function(x) arima(udb.train[1:x],
order = c(1,1,0), seasonal = list(order = c(1,0,0), period = 12)))
lrest<-length(rolling.arima)
all_slopes1 <- unlist(sapply(1:lrest, function(j) rolling.arima[[j]]$coef[1]))
all_slopes2 <- unlist(sapply(1:lrest, function(j) rolling.arima[[j]]$coef[2]))
plot.ts(all_slopes1)
plot.ts(all_slopes2)
```