# Cut-and-Paste code into Window Above and Run
#
# CN1 World Model Input (requires WL20.fx)
#
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)
#
# WL20 World Model
#
f <- matrix( c(1.000000000, 0.00000000, 0.00000000, 0.00000000,
0.210941578, 1.01169571, -0.02519461, -0.09358484,
-0.003862528, -0.01360718, 0.96330129, -0.05250691,
0.018115378, 0.02303607, -0.03631204, 0.93554760
),byrow=TRUE,nrow=4,ncol=4)
#
# Growth-and-Collapse Model
# To create a high-level steady state, uncomment next line
# f[2,2] <- 0.90
#
h <- matrix(c(0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
),byrow=TRUE,nrow=3,ncol=4)
k <- (f[,2:4,drop=FALSE])
WL20 <- SS(F=f,H=h,K=k,z0=c(1.0000000, -5.3541066, -0.7239263, 0.7703831),
output.names=c("W1","W2","W3"))
WL20.data <- simulate(WL20,sampleT=150,noise=matrix(0,150,3))
WL20.f <- forecast(l(WL20,WL20.data),horizon=50)
WL20.fx <- merge.forecast(WL20.f)
#
# CN1 World Model Input (requires WL20.fx)
#
#
# Measurement Matrix # (Growth) (Q-LU) (LU - KOF)
#
# EN.ATM.CO2E.KT EG.USE.COMM.KT.OE NY.GDP.MKTP.KD
#[1,] 0.339 0.3378 0.3192
#[2,] 0.339 0.3626 0.5457
#[3,] -0.007 0.0608 -0.0215
# SL.TLF.TOTL.IN SP.POP.TOTL SL.UEM.TOTL.ZS EF KOF HDI
#[1,] 0.339 0.340 0.309 0.347 0.320 0.347
#[2,] -0.284 -0.289 -0.358 0.164 -0.331 -0.164
#[3,] -0.165 -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.8753811, 0.003394595,
0.0000000, 1.0000000
),byrow=TRUE,nrow=2,ncol=2)
h <- eye(1,2)
k <- f[1:2,1,drop=FALSE]
g <- matrix(c(0.123362, -0.05385008, -0.1057655,
0.0000000, 0.000000, 0.0000000
),byrow=TRUE,nrow=2,ncol=3)
CN1 <- SS(F=f,H=h,K=k,G=g,z0=c( -0.45684, 1.0000000),
output.names=c("CN1"),input.names=c("W1","W2","W3"))
tfplot(simulate(CN1,sampleT=150,noise=matrix(0,150,1),start=1950,input=WL20.fx))
#