r - 通过向量自回归模型预测多元数据
问题描述
我正在使用多元时间序列数据(每小时时间序列数据)处理功能时间序列。我使用的 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
}
请指导我如何解决我的问题或我做的错误。谢谢
解决方案
推荐阅读
- file - 批处理脚本不使用此代码输出文件
- php - woocomerce:状态完成后获取自定义产品输入字段的单个值
- javascript - 如何将参数从一个html页面传递到另一个页面
- c++ - 为什么我的 iFFT 图像带有镜像副本?
- matlab - 文件路径 MATLAB
- c++ - 如何从库路径自动编译源文件而不生成 .o、.a 和 .so 文件?
- python - 如何在不使用 Pandas 的情况下在 Python 中找到 52 周的高点
- amazon-web-services - 为什么我的 S3 生命周期策略没有生效?
- c# - 使用 Embeddinator-4000 在 Android 中无法访问函数
- c# - 如何使用自动 if 语句将数据插入数据库?