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?
Asked
Active
Viewed 5,010 times
7

Alex
- 743
- 1
- 9
- 16
2 Answers
11
I think this does what you want:
library(forecast)
fit <- Arima(x,order=c(1,0,1))
yfiltered <- residuals(Arima(y,model=fit))

Rob Hyndman
- 51,928
- 23
- 126
- 178
-
1could 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 – Alex Nov 12 '12 at 21:03
-
1Yes. 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." – Rob Hyndman Nov 12 '12 at 22:51
-
yes, took a look. was having trouble udnerstanding what was meant by residuals. think i have it now. thanks! – Alex Nov 12 '12 at 23:07
0
I suggest three different functions:
stats:::arima
forecast:::Arima
forecast:::auto.arima
forecast:::auto.arima will automatically seelct the p and q lags for you.

power
- 1,564
- 1
- 16
- 29