Dear all,
The function below is
a simplified interface to ets{forecast}{R}
The forecast R package should be
installed to run the function
<R
install.packages("forecast")
R>
The question is below the script
<hansl
function bundle ets_f (series y "series to forecast",
int h[0] "forecasting horizon, 0 = $pd",
scalar cl[0] "confidence level, 0 -> 0.95")
if cl=0
cl = 0.95
endif
series hh = 0
if h = 0
hh[1] = $pd
else
hh[1] = h
endif
hh[2] = 100*cl
list Rlist = y hh
foreign language=R --send-data=Rlist
library(forecast)
mts2frame2 <- function(x)
{
ddd <- data.frame(x);
if (length(class(x)) > 1)
{
m <-
ncol(x);for (i in 1:m)
ddd[,i] <- ts(ddd[,i],start = start(x),frequency = frequency(x))
}
else
ddd[,1] <- ts(ddd[,1],start = start(x),frequency = frequency(x));
ddd
};
gretldata <- mts2frame2(gretldata)
attach(gretldata)
et = ets(y)
print(et)
f <- forecast(et,h = hh[1],level = hh[2])
print(f)
gg = as.matrix(et$fitted)
gretl.export(gg)
forecst <- cbind(f$mean,f$lower,f$upper)
ggg <-
cbind(as.numeric(forecst[,1]),as.numeric(forecst[,2]),as.numeric(forecst[,3]))
gretl.export(ggg)
end foreign
vars = mread("gg.mat",1)
fors = mread("ggg.mat",1)
bundle b
b["yhat"] = vars
b["fcst"] = fors
b["level"] = cl*100
return b
end function
open denmark.gdt
b = ets_f(LRM)
hansl>
Among other things output contains
wrote /home/oleh/.gretl/gg.mat
wrote /home/oleh/.gretl/ggg.mat
How I can delete these files from within the function
provided shell command is switched off by default?
Oleh