#
# W_EM Model
#
merge.forecast <- function (fx,n=1) {
x <- splice(fx$pred,fx$forecast[[n]])
colnames(x) <- seriesNames(fx$data$output)
return(x)
}
AIC <- function(model) {informationTestsCalculations(model)[3]}
require(dse)
require(matlab)
# measurementModel(W_EM.index2) # overall-T, T+L+Q, N-L, Q-N-L
# Measurement Matrix
# Q N L T
#[1,] 0.5103 0.5132 0.502 -0.4735
#[2,] 0.2690 0.0616 0.460 0.8441
#[3,] 0.0928 0.7414 -0.615 0.2514
#[4,] 0.8115 -0.4280 -0.398 -0.0108
#
# Fraction of Variance
#[1] 0.942 0.996 0.999 1.000
#
f <- matrix( c(1.007403e+00, -0.001415646, -0.07925152, 0.0235527600,
4.110835e-03, 0.997379912, -0.04192458, -0.0007495893,
7.329395e-05, 0.006009439, 0.99057854, 0.0011411586,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
#
# To Stabilize Model, Uncomment Following Line
# f[1,1] <- 0.99
#
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
W_EM <- SS(F=f,H=h,K=k,z0=c(0.0235527600, -0.0007495893, 0.0011411586, 1.0000000000),
output.names=c("W1","W2","W3"))
print(W_EM)
is.SS(W_EM)
stability( SS(F=f[1:3,1:3,drop=FALSE],H=eye(3),Q=eye(3),R=eye(3)))
# tfplot(simulate(W_EM,sampleT=300,start=1500))
W_EM.data <- simulate(W_EM,sampleT=300,noise=matrix(0,300,3),start=1500)
W_EM.f <- forecast(l(W_EM,W_EM.data),horizon=250)
tfplot(W_EM.f)
AIC(m <- l(W_EM,W_EM.data))
shockDecomposition(m)