# Cut-and-Paste Code Below into Window above and Run
#
# RU18 Small Country Model Russia
#
# W18 World Input 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)
#
# Measurement Matrix # overall, Q-N, N-L
# Q N L T
#[1,] 0.499 0.500 0.501 -0.501
#[2,] 0.837 -0.491 -0.171 0.171
#[3,] 0.227 0.713 -0.469 0.469
#
# Fraction of Variance
#[1] 0.996 1.000 1.000 1.000
f <- matrix( c( 0.9990146949, 0.04503518, -0.05464643, 0.065548536,
-0.0042486908, 1.04226953, -0.04676536, -0.002528148,
0.0004986095, 0.03266194, 0.95871578, -0.001858812,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
#
#
# To Stabilize, Uncomment next line
# f[2,2] <- 0.90
#
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
W18 <- SS(F=f,H=h,K=k,z0=c(0.065548536, -0.002528148, -0.001858812, 1.0000000000),
output.names=c("W1","W2","W3"))
stability(m <- SS(F=f[1:3,1:3,drop=FALSE],Q=eye(3),R=eye(3),H=eye(3)))
W18.data <- simulate(W18,sampleT=100,noise=matrix(0,100,3),start=1700)
W18.f <- forecast(l(W18,W18.data),horizon=150)
W18.fx <- merge.forecast(W18.f)
#
# RU18 Small Country Model
#
# Measurement Matrix # overall-XREAL, Q-N, N+XREAL-L
#
# Q N XREAL L
#[1,] 0.496 0.500 -0.502 0.502
#[2,] 0.830 -0.512 0.155 -0.155
#[3,] 0.254 0.698 0.473 -0.473
# Fraction of Variance
#[1] 0.99 1.00 1.00 1.00
#
f <- matrix( c( 0 , 0, 0, -8.271162e-16,
0, 0, 0, -2.365729e-16,
0, 0, 0, -6.241095e-16,
0, 0, 0, 1.000000e+00
),byrow=TRUE,nrow=4,ncol=4)
g <- matrix(c(9.970491e-01, 0.1772112,0 -0.2348331,
-1.029856e-03, 1.64145182, -0.2282411,
6.346538e-05, 0.01210398, 0.8167547,
0.000000e+00, 0.00000000, 0.0000000
),byrow=TRUE,nrow=4,ncol=3)
h <- eye(3,4)
k <- matrix(0,4,3)
RU18 <- SS(F=f,H=h,K=k,G=g,z0=c(-3.37641548, -0.22348361, 0.09664816, 1.000),
output.names=c("RU1","RU2","RU3"),input.names= c("W1","W2","W3"))
stability(m <- SS(F=f[1:3,1:3,drop=FALSE],Q=eye(3),R=eye(3),H=eye(3)))
RU18.data <- simulate(RU18,sampleT=100,noise=matrix(0,100,3),start=1700,input=W18.fx)
RU18.f <- forecast(l(RU18,RU18.data),conditioning.inputs=W18.fx)
tfplot(W18.f)