Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extract ARIMA specificaiton

Tags:

r

time-series

Printing a fitted model object from auto.arima() includes a line such as
"ARIMA(2,1,0) with drift,"
which would be a nice item to include in sweave (or other) output illustrating the fitted model. Is it possible to extract that line as a block? At this point the best I am doing is to extract the appropriate order from the arma component (possibly coupled with verbiage from the names of the coefficients of the fitted model, e.g., "with drift" or "with non-zero mean.")

# R 3.0.2 x64 on Windows, forecast 5.3 
library(forecast)  
y <- ts(data = c(-4.389, -3.891, -4.435, -5.403, -2.501, -1.858, -4.735, -1.085, -2.701, -3.908, -2.520, -2.009, -6.961, -2.891, -0.6791, -1.459, -3.210, -2.178, -1.972, -1.207, -1.376, -1.355, -1.950, -2.862, -3.475, -1.027, -2.673, -3.116, -1.290, -1.510, -1.736, -2.565, -1.932, -0.8247, -2.067, -2.148, -1.236, -2.207, -1.120, -0.6152), start = 1971, end = 2010)  
fm <- auto.arima(y)  
fm  

# what I want is the line: "ARIMA(2,1,0) with drift`"  

str(fm)  
paste("ARIMA(", fm$arma[1], ",", fm$arma[length(fm$arma)-1], ",", fm$arma[2], ") with ",intersect("drift", names(fm$coef)), sep = "")
like image 316
Kristian Omland Avatar asked Oct 16 '25 11:10

Kristian Omland


2 Answers

Checking the auto.arima function, I noticed it internally calls another function which is named arima.string.

Then I did:

getAnywhere(arima.string)

and the output was:

A single object matching ‘arima.string’ was found
It was found in the following places
namespace:forecast
with value

function (object) 
{
order <- object$arma[c(1, 6, 2, 3, 7, 4, 5)]
result <- paste("ARIMA(", order[1], ",", order[2], ",", order[3], 
    ")", sep = "")
if (order[7] > 1 & sum(order[4:6]) > 0) 
    result <- paste(result, "(", order[4], ",", order[5], 
        ",", order[6], ")[", order[7], "]", sep = "")
if (is.element("constant", names(object$coef)) | is.element("intercept", 
    names(object$coef))) 
    result <- paste(result, "with non-zero mean")
else if (is.element("drift", names(object$coef))) 
    result <- paste(result, "with drift        ")
else if (order[2] == 0 & order[5] == 0) 
    result <- paste(result, "with zero mean    ")
else result <- paste(result, "                  ")
return(result)

}

Then I copied the function code and pasted it in a new function which I named arima.string1

arima.string1(fm)

# [1] "ARIMA(2,1,0) with drift        "
like image 189
Davide Passaretti Avatar answered Oct 19 '25 00:10

Davide Passaretti


Today I discovered the block of text I sought is also stored in the forecast from the fitted model object:

forecast(fm)$method  

Thanks to Fernando for properly markup-ing my question and to Davide for providing a pair of useful insights - getAnywhere() and arima.string() ready for modification.

like image 22
Kristian Omland Avatar answered Oct 18 '25 23:10

Kristian Omland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!