#
# LA BAU 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) (LU-EG-Q) (N+L-CO2-Q)
#
# EN.ATM.CO2E.KT EG.USE.COMM.KT.OE NY.GDP.MKTP.KD
#[1,] 0.412 0.412 0.411
#[2,] -0.190 -0.239 -0.272
#[3,] -0.532 -0.169 -0.252
# SL.TLF.TOTL.IN SP.POP.TOTL SL.UEM.TOTL.ZS
#[1,] 0.413 0.41317 0.388
#[2,] -0.144 -0.00377 0.901
#[3,] 0.497 0.59551 -0.152
#
# Fraction of Variance
#[1] 0.972 0.997 0.999 1.000 1.000 1.000
#
f <- matrix( c( 1.00381064, -0.02146271, 0.08201721, 0.163480774,
-0.01920519, 1.00425865, -0.12263224, -0.009655540,
-0.00456711, 0.04692786, 0.98229614, -0.005545233,
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.99421607; f[3,3]=0.97247318
#
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
LA20 <- SS(F=f,H=h,K=k,z0=c( 0.163480774, -0.009655540, -0.005545233, 1.0000000000),
output.names=c("LA1","LA2","LA3"))
print(LA20)
is.SS(LA20)
stability(LA20)
# tfplot(simulate(LA20,sampleT=100))
LA20.data <- simulate(LA20,sampleT=100,noise=matrix(0,100,3),start=1950)
LA20.f <- forecast(l(LA20,LA20.data),horizon=100)
LA20.fx <- merge.forecast(LA20.f)
#
# BRL20 LA 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.1180893, 0.19118734, 0.5365488, -0.10696791,
-1.4471310, 0.89466649, 1.2842461, -0.33479373,
-0.4352055, 0.02064418, 1.1826515, -0.09927545,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
#
g <- matrix( c(1.1016727, -0.16809068, 0.5864351,
1.4297284, -0.07116385, 1.4475001,
0.4364845, -0.12000957, 0.1571687,
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(-4.392033 ,-5.977488, -1.772060, 1.0000000000),
output.names=c("BR1","BR2","BR3"))
print(BRL20)
is.SS(BRL20)
stability(BRL20)
# tfplot(simulate(BRL20,sampleT=100))
BRL20.data <- simulate(BRL20,sampleT=100,noise=matrix(0,100,3),input=LA20.fx)
tfplot(outputData(BRL20.data))