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?
2 Answers
I think this does what you want:
library(forecast)
fit <- Arima(x,order=c(1,0,1))
yfiltered <- residuals(Arima(y,model=fit))
-
1$\begingroup$ could you please explain how
Arima
withmodel
parameter works? in particular: if i filterx
with $(1-aL)x_{t} = (1-bL)\varepsilon_{t}$, this can be accomplished byfit <- Arima(x,order=c(1,0,1))
, correct? Then when I runresiduals(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$– AlexNov 12, 2012 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$ Nov 12, 2012 at 22:51
-
$\begingroup$ yes, took a look. was having trouble udnerstanding what was meant by residuals. think i have it now. thanks! $\endgroup$– AlexNov 12, 2012 at 23:07
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.