首页 > 解决方案 > 通过向量自回归模型预测多元数据

问题描述

我正在使用多元时间序列数据(每小时时间序列数据)处理功能时间序列。我使用的 FAR 模型不止一个订单,R 中没有可用的统计包,因此我将数据转换为函数形式并获得函数原理组件,并从这些 FPCA 中提取它们相应的** FPCscores**。知道我在这些FPCscores上使用 VAR 模型通过 VAR 模型预测每 24 小时,但是当我输入 phat=23 时,VAR 给了我所有 23 小时的预测值,但是每当我输入 phat=24 时,例如想要每 24 小时预测一次,它以 NA 的形式给出结果。代码如下

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
  
}

请指导我如何解决我的问题或我做的错误。谢谢

标签: rtime-seriesvarvector-auto-regression

解决方案


推荐阅读