【发布时间】:2016-01-28 23:59:33
【问题描述】:
我已经用 MARSS 包为 R 编写了一个模型。
模型背后的主要思想是预测至少 10 个季度的可观察向量,但是我似乎无法使用 MARSSsimulate 函数来做到这一点(我相信这是因为包含了名为季节的外生向量,在估计过程中)。非常感谢您的帮助。
提前致谢!
数据集可以下载here
我使用了以下代码
info <- read.table("series_kalman2.txt",header=T,dec=".")
dat_est_spa <- t(info[,3:6])
Sigma <- sqrt(apply(dat_est_spa, 1, var, na.rm=TRUE))
y.bar <- apply(dat_est_spa, 1, mean, na.rm=TRUE)
dat.z <- (dat_est_spa - y.bar) * (1/Sigma)
rownames(dat.z) = rownames(dat_est_spa)
N.ts <- dim(dat_est_spa)[1]
season <- rbind(rep(c(1,0,0,0),ceiling(dim(dat_est_spa)[2]/4)),
rep(c(0,1,0,0),ceiling(dim(dat_est_spa)[2]/4)),
rep(c(0,0,1,0),ceiling(dim(dat_est_spa)[2]/4)),
rep(c(0,0,0,1),ceiling(dim(dat_est_spa)[2]/4)))
rownames(season) <- c("Q1","Q2","Q3","Q4")
season <- season[,-((dim(dat_est_spa)[2]+1):dim(season)[2])]
### Model
cntl.list = list(minit=200, maxit=60000, allow.degen=FALSE)
mod_est_spa <- list(A="zero", R="diagonal and equal", m=3)
estim_est_spa <- MARSS(dat.z, model=mod_est_spa, control=cntl.list,
form="dfa", covariates=season)
### Forecast
MARSSsimulate(estim_est_spa, tSteps = 10)
【问题讨论】:
标签: r forecasting state-space