[R] arima crashes too
Alberto Monteiro
albmont at centroin.com.br
Fri Oct 23 18:09:47 CEST 2009
Barry Rowlingson wrote:
>
> If you're doing anything in a loop that has the potential to fail
> because of singularities or other conditions when your model can't be
> fitted, you need to stick what you are doing in a 'try' clause. This
> lets you trap errors and do something with them.
>
> Plenty of examples in help(try) or this from me:
>
> for(i in 1:10){
> print(solve(matrix(c(3,3,3,i),2,2)))
> }
>
> This stops the loop at i=3. Now stick it in a try() clause:
>
> for(i in 1:10){
> print(try(solve(matrix(c(3,3,3,i),2,2))))
> }
>
> and it gives a warning and carries on. If you want your code to do
> something with the failure cases then the help for try() tells you
> what to look for.
>
I will try try. # irreristible pun
But...
> I'm not sure why your arima produces an error, but I'm assuming the
> numbers are such that the model can't be fitted. I don't really know
> what arima is doing.
>
That's a problem. In this case, I'm fitting an AR(1) time series
using arima and arma. The documentation does not mention that we
should be careful about what numbers are passed to it; on contrary,
it's perfectly possible (in theory) that an AR(1) time series was
created using an "evil" phi in
x[i+1] <- phi * x[i] + sigma * n01[i]
and the regression should return the "evil" phi.
As in this reproducible example:
phi <- 1.5
sigma <- 0.5
n01 <- c(-1, 0.3, -0.3, 0.2, -0.7)
x <- rep(0, 6)
for (i in 1:5) x[i+1] <- phi * x[i] + sigma * n01[i]
arma(x, order=c(1,0))
arima(x, order=c(1,0,0))
It seems like arma does not force phi to be in the -1:1 range, because
it correctly returns "evil" phi's, but arima kind of bayesianises
the output, forcing the time series to be stationary.
Probably a longer example may <s>crash</s> stop arima but not arma.
Non-reproducible example (almost surely <s>crashes</s> stops arima but
plays safely in arma):
phi <- 1.05
sigma <- 0.5
n <- 100
n01 <- rnorm(n)
x <- rep(0, n)
for (i in 1:n) x[i+1] <- phi * x[i] + sigma * n01[i]
arma(x, order=c(1,0))
arima(x, order=c(1,0,0))
Increasing phi (or n) will <s>crash</s> stop both arma and arima:
phi <- 1.1
sigma <- 0.5
n <- 100
n01 <- rnorm(n)
x <- rep(0, n)
for (i in 1:n) x[i+1] <- phi * x[i] + sigma * n01[i]
arma(x, order=c(1,0))
arima(x, order=c(1,0,0))
Alberto 'Darth Albmont' Monteiro
More information about the R-help
mailing list