[R] combining arima and ar function
Samir Benzerfa
benzerfa at gmx.ch
Thu Dec 1 10:57:20 CET 2011
Hi everyone
I've got a problem regarding the arima() and the ar() function for
autoregressive series. I would simply like to combine them.
To better understand my question, I first show you how I'm using these two
functions individually (see file in the attachement).
1) apply(TSX,2, function(x) ar(na.omit(x),method="mle")$order
# this function finds the optimal (autoregressive) order for each series
(briefly speaking: for each series I get a specific number)
2) apply(TSX,2,function(x)arima(x,order=c(1,0,0))$residuals
# this function puts an autoregressive model of order 1 on each series
What I'd like to do, is to combine them, such that the resulting orders
(numbers) from the first function are used as orders in the second function.
So in the specific example attached the results from the first function are
6,5,1 and these numbers should be used as the order in function two. I tried
to simply put the two functions together as follows:
apply(TSX,2,function(x) arima(x,order=c((apply(TSX,2,
function(x)ar(na.omit(x),method="mle")$order))),0,0))
However, I get the error message " 'order' must be a non-negative numeric
vector of length 3".
Any hints? I hope you can help me with this issue.
Many thanks and best regards, S.B.
More information about the R-help
mailing list