[R] Import ARIMA coefficients

Gavin Simpson gavin.simpson at ucl.ac.uk
Fri Jun 5 11:28:18 CEST 2009


On Thu, 2009-06-04 at 15:21 +0100, Daniel Mail wrote:
<snip />
> Hello,
>   
> I need to know how to import ARIMA coefficients. I already determined
> the coefficients of the model with other software, but now i need to
> do the forecast in R.
<snip/>
>  
> 
> > fit <- arima(x, order=c(1, 0, 1), fixed=c(-.172295, .960043, 0)) 
> > fit
> 
> Call:
> arima(x = x, order = c(1, 0, 1), fixed = c(-0.172295, 0.960043, 0))
> 
> Coefficients:
> Error in se && nrow(x$var.coef) : invalid 'y' type in 'x && y'

Looks like this is a bug in print.Arima, as it assumes that x$var.coef
is a matrix or similar. In this case, it is actually

> mod2$var.coef
numeric(0)
> nrow(mod2$var.coef)
NULL

And the NULL is causing the error: [note 'se' is TRUE here]

> TRUE && NULL
Error in TRUE && NULL : invalid 'y' type in 'x && y'

The simple work around is just to call the print method explicitly and
set argument 'se' to be FALSE. This only seems to affect the print
method - you can use the predict method (?predict.Arima) to do your
forecasts.

Here is an example using dummy data so it is reproducible:

> set.seed(123)
> x <- cumsum(rnorm(1000))
> x <- as.ts(x)
> mod <- arima(x, order=c(1, 1, 1))
> mod

Call:
arima(x = x, order = c(1, 1, 1))

Coefficients:
         ar1      ma1
      0.6000  -0.6362
s.e.  0.2963   0.2855

sigma^2 estimated as 0.9814:  log likelihood = -1408.14,  aic = 2822.28
> ## note coefs - use them in a new fit as you were doing
> mod2 <- arima(x, order=c(1, 1, 1), fixed = c(0.6000,-0.6362))
> print(mod2, se = FALSE)

Call:
arima(x = x, order = c(1, 1, 1), fixed = c(0.6, -0.6362))

Coefficients:
    ar1      ma1  
 0.6000  -0.6362  

sigma^2 estimated as 0.9814:  log likelihood = -1408.14,  aic = 2818.28
> ## Now do a prediction - default is the 1-step ahead forecast:
> predict(mod2)
$pred
Time Series:
Start = 1001 
End = 1001 
Frequency = 1 
[1] 16.15804

$se
Time Series:
Start = 1001 
End = 1001 
Frequency = 1 
[1] 0.9906526

Although, you'd probably be better off doing the fit in R directly...

G

>  
> 
> 
> 
> I will be very pleased if someone help me.

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090605/53689240/attachment-0002.bin>


More information about the R-help mailing list