# Cut-and-Paste Code below into Window Above and Run
#
# WL20 India Model
#
AIC <- function(model) {informationTestsCalculations(model)[3]}
require(dse)
require(matlab)
#
# measurementModel(IN_SYS.index) # (Growth) (LU-GDP) (Q+KOF+CO2-N-L-HDI-EF)
# Measurement Matrix
# EN.ATM.CO2E.KT EG.USE.COMM.KT.OE NY.GDP.MKTP.KD SL.TLF.TOTL.IN SP.POP.TOTL SL.UEM.TOTL.ZS KOF EF HDI
#[1,] 0.341 0.343 0.330 0.3402 0.3400 0.281 0.3382 0.3421 0.3407
#[2,] -0.153 -0.137 -0.320 -0.0435 -0.0151 0.919 0.0296 -0.0474 -0.0781
#[3,] 0.239 0.115 0.527 -0.4072 -0.4230 0.164 0.3551 -0.1642 -0.3575
#
# Fraction of Variance
#[1] 0.936 0.980 0.995 0.998 0.999 1.000 1.000 1.000 1.000
#
f <- matrix( c(1.02384306, -0.06151759, -0.06191305, 0.198687580,
-0.02578163, 0.86097140, -0.17375573, -0.019392476,
0.01654841, -0.03236747, 0.99086564, 0.003969969,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
#
# To stabilize model, uncomment following line
# f[1,1] <- .93 ; f[3,3]<- .93
#
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
INL20 <- SS(F=f,H=h,K=k,z0=c( 0.198687580, -0.019392476, 0.003969969, 1.0000000000),
output.names=c("IN1","IN2","IN3"))
print(INL20)
#is.SS(INL20)
stability(SS(F=f[1:3,1:3,drop=FALSE],H=eye(3),Q=eye(3),R=eye(3)) )
# tfplot(simulate(INL20,sampleT=100))
INL20.data <- simulate(INL20,sampleT=150,noise=matrix(0,150,3),start=1950)
INL20.f <- forecast(l(INL20,INL20.data),horizon=150)
tfplot(INL20.f)
AIC(l(INL20,INL20.data))
INL20x <- SS(F=f,H=h,Q=eye(4,3),R=eye(3,3),z0=c( 0.198687580, -0.019392476, 0.003969969, 1.0000000000),
output.names=c("IN1","IN2","IN3"))
shockDecomposition(INL20x)
#
# Random Walk Model
#
INL20r <- SS(F=eye(4),H=h,Q=eye(4,3),R=eye(3,3),z0=c( 0.198687580, -0.019392476, 0.003969969, 1.0000000000),
output.names=c("IN1","IN2","IN3"))
INL20r.data <- simulate(INL20r,sampleT=50,start=1950)
INL20r.model <- l(INL20r,INL20r.data)
tfplot(INL20r.model)