# Cut-and-Paste code below into Window above and Run
#
# FR_AUST BAU
#
#
merge.forecast <- function (fx,n=1) {
#
# Merges a forecast with the outputdata
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 GEG+MIL-G-GE) (GH+G-GEG-GE) (Growth)
# SH.XPD.GHED.CH.ZS SE.XPD.TOTL.GB.ZS NE.CON.GOVT.ZS SE.XPD.TOTL.GD.ZS
#[1,] 0.164 0.433 -0.4477 -0.393
#[2,] 0.822 -0.357 -0.0291 -0.377
#[3,] 0.490 0.323 0.3823 0.613
# SH.XPD.GHED.GE.ZS MS.MIL.XPND.ZS
#[1,] -0.4701 0.4572
#[2,] 0.2115 -0.0918
#[3,] -0.0572 0.3617
#
# Fraction of Variance
#[1] 0.680 0.871 0.944 0.986 0.995 1.000
#
f <- matrix( c(0.94610447, 0.18841986, -0.04710148, -0.03876814,
-0.03822177, 0.98955261, -0.07109910, 0.03802201,
0.03158142, -0.06157702, 0.86025784, -0.02111634,
0.00000000, 0.00000000, 0.00000000, 1.00000000
),byrow=TRUE,nrow=4,ncol=4)
h <- eye(3,4)
k <- f[1:4,1:3,drop=FALSE]
FR_AUST <- SS(F=f,H=h,K=k,z0=c(-0.03876814, 0.03802201, -0.02111634,1.00000000),
output.names=c("FR_AUST1","FR_AUST2","FR_AUST3"))
print(FR_AUST)
is.SS(FR_AUST)
stability(m1 <- SS(F=f[1:3,1:3,drop=FALSE],H=eye(3),R=eye(3),Q=eye(3)))
FR_AUST.data <- simulate(FR_AUST,sampleT=50,noise=matrix(0,50,3),start=1960)
# tfplot(FR_AUST.data)
FR_AUST.f <- forecast(m <- l(FR_AUST,FR_AUST.data),horizon=50)
shockDecomposition(m1)
tfplot(FR_AUST.f)
FR_AUST.fx <- merge.forecast(FR_AUST.f)
# tfplot(FR_AUST.fx)
#
#
# FR_L20 Model
#
#
# Measurement Matrix
#
# EN.ATM.CO2E.KT EG.USE.COMM.KT.OE NY.GDP.MKTP.KD SL.TLF.TOTL.IN SP.POP.TOTL
#[1,] 0.004201 0.3740 0.3762 0.369 0.3742
#[2,] 0.781330 0.0959 -0.0379 -0.059 -0.0241
#[3,] 0.000453 0.0585 -0.1871 -0.355 -0.2225
# SL.UEM.TOTL.ZS KOF EF HDI
#[1,] 0.3299 0.3643 0.2460 0.3748
#[2,] -0.0912 -0.1994 0.5658 -0.0815
#[3,] 0.8719 0.0366 0.0632 -0.1437
#
#Fraction of Variance
#[1] 0.774 0.947 0.980 0.995 0.998 0.999 1.000 1.000 1.000
#
f <- matrix( c(0.93679424, -0.109061598, -0.1033792, 0.3617278,
-0.02469352, 0.496499890, -0.4262340, 0.1732049,
-0.26084833, -0.005069804, 0.8573141, 0.6471091,
0.000000000, 0.000000000, 0.00000000, 1.000000
),byrow=TRUE,nrow=4,ncol=4)
g <- matrix( c(-0.02128965, 0.2196958, 0.029796882,
0.17987253, 0.3177710, 0.028331071,
-0.26832112, 0.3821658, -0.009828239,
0.00000000, 0.0000000, 0.000000000
),byrow=TRUE,nrow=4,ncol=3)
h <- eye(3,4)
k <- f[1:4,1:3,drop=FALSE]
FRL20 <- SS(F=f,H=h,K=k,G=g,z0=c(.3051262, 0.8995846, -0.3075910,1.00000000),
output.names=c("FR1","FR2","FR3"))
print(FRL20)
is.SS(FRL20)
stability(SS(F=f[1:3,1:3,drop=FALSE],H=eye(3),R=eye(3),Q=eye(3)))
#
FRL20.data <- simulate(FRL20,sampleT=50,input=window(FR_AUST.fx,end=2010),noise=matrix(0,50,3))
# FRL20.data <- simulate(FRL20,sampleT=50,input=window(FR_AUST.fx,end=2010))
#
FRL20.f <- forecast(m <-l(FRL20,FRL20.data),conditioning.inputs=FR_AUST.fx)
shockDecomposition(m)
tfplot(FRL20.f)