I have two time-series, x and y. I would like to prewhiten x by fitting an ARMA(p,q) (or in my case ARMA(1,1)) process and then use the coefficients to filter y. This seems like a pretty standard thing to want to do. However, the stats:::filter function does only MA or AR filtering it looks like. What is the appropriate way to do this? Also, should one use the arima function in R to do this or are there other ways?


I think this does what you want:

fit <- Arima(x,order=c(1,0,1))
yfiltered <- residuals(Arima(y,model=fit))
  • 1
    $\begingroup$ could you please explain how Arima with model parameter works? in particular: if i filter x with $(1-aL)x_{t} = (1-bL)\varepsilon_{t}$, this can be accomplished by fit <- Arima(x,order=c(1,0,1)), correct? Then when I run residuals(Arima(y,model=fit)), does this produce $y_{t}-[(1-aL)y_{t} - (1-bL)u_{t}]$ where $u_{t}$ are residuals of $(1-aL)y_{t})$? $\endgroup$ – Alex Nov 12 '12 at 21:03
  • 1
    $\begingroup$ Yes. See help file: "model: Output from a previous call to Arima. If model is passed, this same model is fitted to x without re-estimating any parameters." $\endgroup$ – Rob Hyndman Nov 12 '12 at 22:51
  • $\begingroup$ yes, took a look. was having trouble udnerstanding what was meant by residuals. think i have it now. thanks! $\endgroup$ – Alex Nov 12 '12 at 23:07

I suggest three different functions:




forecast:::auto.arima will automatically seelct the p and q lags for you.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.