mpiktas / midasr

R package for mixed frequency time series data analysis.
http://mpiktas.github.io/midasr/
Other
73 stars 34 forks source link

oos_prec {midasr} example code #62

Closed kazimsanlav closed 6 years ago

kazimsanlav commented 6 years ago

Hi, I am trying to run the sample code supplied for the function 'oob_prec', but I get the following error message: 'Error in forecast(mod, newdata = outdt) - outdt$y : non-numeric argument to binary operator Called from: mean((forecast(mod, newdata = outdt) - outdt$y)^2)'

R version 3.4.3

vzemlys commented 6 years ago

Which function is that? It is not exported from midasr. Which midasr version are you using?

kazimsanlav commented 6 years ago

I am using midas version 0.6 and trying to run the sample code given in oos_prec. In the issue, there was a typo ( oob_prec ) but sample code is still not working.

vzemlys commented 6 years ago

Change the function rep1 code to this one and it will work:

rep1 <- function(n) {
     dt <- gendata(round(1.25*n))
     ni <- n    
     ind <- 1:ni
     mind <- 1:(ni*12)
     indt<-list(y=dt$y[ind],z=dt$z[mind],trend=dt$trend[ind])
     outdt <- list(y=dt$y[-ind],z=dt$z[-mind],trend=dt$trend[-ind])
     um <- midas_r(y~trend+mls(z,0:16,12),data=indt,start=NULL)
     nm <- midas_r(y~trend+mls(z,0:16,12,nealmon),data=indt,start=list(z=c(1,-1,0)))
     am <- midas_r(y~trend+mls(z,0:16,12,almonp),data=indt,start=list(z=c(1,0,0,0)))
     modl <- list(um,nm,am)
     names(modl) <- c("um","nm","am")
     list(norms=sapply(modl,bnorm),
          mse=sapply(modl,function(mod)mean((forecast(mod,newdata=outdt)$mean-outdt$y)^2)))
 }

The code was written for older version of midasr. Forecast method now returns a forecast object for compatibility with forecast package.

kazimsanlav commented 6 years ago

Thanks.