El 28/09/11 02:06, Allin Cottrell escribió:
>
> Now, here is my issue. I would like to write a library to
> basically take time series data as input, try various ARIMA models
> and pick the most appropriate one "automatically" without human
> input or intervention. I understand this is fairly novice way to
> looking at the forecasting, but my application's use-case is
> simple enough to do it this way.
>
> Now, has anyone tried this using GRETL where multiple models are
> tried and results (fstats output) are compared to pick one over
> the other? If so is there a GRETL script out there that can be
> shared?
I'm not aware of any such script, although that doesn't mean that
such a script doesn't exist somewhere.
However, my understanding is that TRAMO -- which is available in a
form compatible with gretl, see for example
http://gretl.sourceforge.net/win32/ -- does this sort of thing
(automatic ARIMA model selection). But (I may be wrong) TRAMO
probably does not handle intra-day "seasonality"; I think it's
mostly oriented to monthly or quarterly data.
Maybe Ignacio Diaz-Emparanza, our resident expert on ARIMA models,
could comment?
Allin Cottrell
I have worked on replicating the automatic modelling method of TRAMO
natively in gretl(hansl) and also on the procedure of Mélard and
Pasteels [International journal of Forecasting 16 (2000) 497-508] but
they are not mature enough for publishing yet.
As already mentioned by Remigius, in R you may use the package
'forecast'. And remember that most of the R code may be run from inside
a hansl script. In this case this could be: (fist of all you have to
install.packages("forecast") from inside R)
<hansl>
#This function calls to the function auto.arima()
#in the library "forecast" of R, to automatically identify
#an arima model for the indicated series.
#
function matrix Rautoarima(series myseries, series *uhat[null])
catch smpl myseries --contiguous
if $error
print "Error: May be NAs inside the series"
endif
sx = argname(myseries)
##### Begining of R code
foreign language=R --send-data --quiet
library(forecast)
y <- gretldata[, "myseries"]
arimafit <- auto.arima(as.ts(y))
summary(arimafit)
orders <- as.matrix(arimafit$arma)
mbic<-as.matrix(arimafit$bic)
uhat <- as.ts(arimafit$residuals)
gretl.export(orders)
gretl.export(uhat)
gretl.export(mbic)
end foreign
###### End of R code
outfile --write null
append @dotdir/uhat.csv
orders = mread("(a)dotdir/orders.mat")
mmbic = mread("(a)dotdir/mbic.mat")
scalar p = orders[1]
scalar d = orders[6]
scalar q = orders[2]
scalar P = orders[3]
scalar D = orders[7]
scalar Q = orders[4]
matrix morder = { p, d, q, P, D, Q, mmbic }
outfile --close
print "+++++++++++++++++++++++++++++++++++++++++++++"
printf "The model identified for the series %s is:\n", sx
printf "ARIMA(%1.0f, %1.0f, %1.0f)X(%1.0f, %1.0f, %1.0f) with
BIC=%f\n", p, d, q, P, D, Q, mmbic
print "+++++++++++++++++++++++++++++++++++++++++++++"
return morder
end function
# ------------ main -------------------------
open bjg.gdt
Y=diff(lg)
Y=sdiff(Y)
series ruhat
matrix X = Rautoarima(Y, &ruhat)
</hansl>
--
Ignacio Diaz-Emparanza
DEPARTAMENTO DE ECONOMÍA APLICADA III (ECONOMETRÍA Y ESTADÍSTICA)
UPV/EHU Avda. Lehendakari Aguirre, 83 | 48015 BILBAO
T.: +34 946013732 | F.: +34 946013754
www.ea3.ehu.es