#
# Cut-and-Paste Code Below into Window Above and Run
#
# AFL20 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)
#measurementModel(AF_SYS.index) # (Growth-Q) (EG+EF-CO2) (CO2+EG-EF)
#
# EN.ATM.CO2E.KT EG.USE.COMM.KT.OE NY.GDP.MKTP.KD SL.TLF.TOTL.IN SP.POP.TOTL SL.UEM.TOTL.ZS
#[1,] -0.128 0.0769 -0.296 0.42915 0.4243 0.353
#[2,] -0.412 0.5785 0.350 -0.11453 -0.1126 0.335
#[3,] 0.624 0.4836 0.378 0.00915 -0.0163 0.163
# KOF EF HDI
#[1,] 0.418 0.232 0.416
#[2,] -0.132 0.442 -0.149
#[3,] 0.205 -0.339 0.223
#
# Fraction of Variance
#[1] 0.559 0.773 0.899 0.955 0.980 0.992 0.998 1.000 1.000
#
f <- matrix( c(1.00000000, 0.00000000, 0.00000000, 0.000000000,
0.20868631, 1.06713077, 0.07168718, 0.009686743,
-0.05030444, -0.01693492, 0.73834599, -0.227031411,
-0.03200948, -0.08154583, -0.20562653, 0.719186457
),byrow=TRUE,nrow=4,ncol=4)
#
# To Stabilize Model, Uncomment Next Line
# f[2,2] <- 0.96
#
h <- matrix(c(0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
),byrow=TRUE,nrow=3,ncol=4)
h;
k <- (f[1:4,2:4,drop=FALSE])
k;
AF <- SS(F=f,H=h,K=k,z0=c( 1.000000, -3.354772, 1.961430, -1.129931
),
output.names=c("AF1","AF2","AF3"))
print(AF)
is.SS(AF)
stability(AF)
# tfplot(simulate(AF,sampleT=100))
AF.data <- simulate(AF,sampleT=150,noise=matrix(0,150,3))
AF.f <- forecast(m <- l(AF,AF.data),horizon=150)
# tfplot(AF.f)
AIC(m)
AF.fx <- merge.forecast(AF.f)
tfplot(AF.fx)