# Cut-and-Paste Code Below into Window above and Run
#
# DE18 Small Country Model Germany
#
# 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)
#
# DE18 Small Country Model
#
#
#
# Measurement Matrix # overall-U, N+U, Q-N
# Q N U
#[1,] 0.7160 0.673 -0.185
#[2,] -0.0762 0.338 0.938
#[3,] 0.6939 -0.657 0.294
#
# Fraction of Variance
#[1] 0.646 1.000 1.000
#
#
f <- matrix( c( 0, 0 , 0, -1.093570e-15,
0, 0, 0, 1.565761e-15,
0, 0, 0, -1.377289e-16,
0, 0, 0, 1.000000e+00
),byrow=TRUE,nrow=4,ncol=4)
g <- matrix(c(0.6871537980, 2.02243715, 0.4145507,
0.0868797376, -8.59176157, 2.9982998,
0.0001965475, -0.01193918, -0.3367590,
0.0000000000, 0.00000000, 0.0000000
),byrow=TRUE,nrow=4,ncol=3)
h <- matrix(c( 1 , 0, 0 , 0,
0 , 1, 0, 0,
0, 0, 1, 0
),byrow=TRUE,nrow=3,ncol=4)
k <- matrix(0,4,3)
DE18 <- SS(F=f,H=h,K=k,G=g,z0=c(-2.48848303, 1.11502505, -0.03974815, 1.0),
output.names=c("DE1","DE2","DE3"),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)))
DE18.data <- simulate(DE18,sampleT=100,noise=matrix(0,100,3),start=1700,input=W18.fx)
DE18.f <- forecast(l(DE18,DE18.data),conditioning.inputs=W18.fx)
tfplot(DE18.f)