Forecasting of multivariate data through Vector Autoregression model

171 views Asked by At

I am working in the functional time series using the multivariate time series data(hourly time series data). I am using FAR model more than one order for which no statistical package is available in R, so for this I convert my data into functional form and obtained the functional principle component and from those FPCA I extract their corresponding** FPCscores**. Know I use the VAR model on those FPCscores for the forecasting of each 24 hours through the VAR model, but the VAR give me the forecasted value for all 23hours when I put phat=23, but whenever I put phat=24 for example want to predict each 24 hours its give the results in the form of NA. the code is given below

library(vars)
library(fda)

fdata<- function(mat){
  nb = 27 # number of basis functions for the data
  fbf = create.fourier.basis(rangeval=c(0,1), nbasis=nb) # basis for data
  args=seq(0,1,length=24)
  fdata1=Data2fd(args,y=t(mat),fbf) # functions generated from discretized y
  return(fdata1)
}
prediction.ffpe = function(fdata1){
  n = ncol(fdata1$coef)
  D = nrow(fdata1$coef)
  #center the data
  #mu = mean.fd(fdata1)
  data = center.fd(fdata1)
  #ffpe = fFPE(fdata1, Pmax=10)
  #p.hat = ffpe[2] #order of the model
  d.hat=23
  p.hat=6
  #fPCA
  fpca = pca.fd(data,nharm=D, centerfns=TRUE)
  scores = fpca$scores[,0:d.hat]
  # to avoid warnings from vars predict function below
  colnames(scores) <- as.character(seq(1:d.hat))
  VAR.pre= predict(VAR(scores, p.hat), n.ahead=1, type="const")$fcst
  
}

kindly guide me that how can I solve out my problem or what error I doing. THANKS

0

There are 0 answers