# Cut-and-Paste Code Below into Window Above and Run
#
# LA US_LM Model for Input BRL20 BAU 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 (Growth), (X-N), (L+XREAL-X-N)
#
# Q N HOURS XREAL X L
#[1,] 0.4124 0.403 0.413 0.410 0.399 0.412
#[2,] -0.1464 -0.580 -0.122 0.310 0.711 -0.160
#[3,] -0.0825 -0.546 0.137 0.358 -0.466 0.575
#
# Fraction of Variance
#[1] 0.977 0.999 1.000 1.000 1.000 1.000
#
f <- matrix( c( 1.026261160, -0.04873236, 0.04995449, 0.166789178,
0.023195483, 1.01292512, 0.06694359, 0.004293523,
-0.002685722, -0.04074830, 1.04458649, -0.006797188,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
#
# To stabilize, Uncomment Next Line
# f[1,1] <- 0.99377254; f[2,2] <- 0.97301183; f[3,3] <- 1.00342561
#
#
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
US_LM <- SS(F=f,H=h,K=k,z0=c( 0.33740965, 0.01205627, -0.01452034, 1.0000000000),
output.names=c("US1","US2","US3"))
print(US_LM)
is.SS(US_LM)
stability(m <- SS(F=f[1:3,1:3,drop=FALSE],R=eye(3),Q=eye(3),H=eye(3)))
US_LM.data <- simulate(US_LM,sampleT=100,noise=matrix(0,100,3),start=1950)
US_LM.f <- forecast(l(US_LM,US_LM.data),horizon=100)
US_LM.fx <- merge.forecast(US_LM.f)
#
# BRL20 US INPUT MODEL
#
#
# Growth, (Q-N-LU), (LU - KOF)
# (Growth) (LU+KOF-Q-HDI), (EF+HDI-CO2-Q)
#
# Measurement Matrix
# EN.ATM.CO2E.KT EG.USE.COMM.KT.OE NY.GDP.MKTP.KD SL.TLF.TOTL.IN
#[1,] 0.339 0.3378 0.3192 0.339
#[2,] 0.339 0.3626 0.5457 -0.284
#[3,] -0.007 0.0608 -0.0215 -0.165
# SP.POP.TOTL SL.UEM.TOTL.ZS EF KOF HDI
#[1,] 0.340 0.309 0.347 0.320 0.347
#[2,] -0.289 -0.358 0.164 -0.331 -0.164
#[3,] -0.120 0.824 0.111 -0.492 -0.145
#
# Fraction of Variance
#[1] 0.899 0.961 0.985 0.997 0.999 1.000 1.000 1.000 1.000
#
f <- matrix( c(0.70998520, 0.06732559, 0.3739030, -0.45967560,
-0.07192436, 0.77530391, 0.3339674, -0.07029750,
0.03288135, 0.06686724, 0.6243203, 0.06344443,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
#
g <- matrix( c(0.268964151, -0.1254371, -0.1892538,
-0.001369193, 0.5459352, 0.6504920,
0.019246353, -0.2472605, 0.1165281,
0.0000000, 0.00000000, 0.0000000
),byrow=TRUE,nrow=4,ncol=3)
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
BRL20 <- SS(F=f,H=h,K=k,G=g,z0=c(-1.09807103, -0.00319798, -0.01897999 , 1.0000000000),
output.names=c("BR1","BR2","BR3"))
print(BRL20)
is.SS(BRL20)
stability(SS(F=f[1:3,1:3,drop=FALSE],R=eye(3),Q=eye(3),H=eye(3)))
# tfplot(simulate(BRL20,sampleT=100))
BRL20.data <- simulate(BRL20,sampleT=100,noise=matrix(0,100,3),input=US_LM.fx)
tfplot(outputData(BRL20.data))