# Cut-and-Paste code below into window above and Run
#
# US_E20 Model
#
#Measurement Matrix (Growth-P.CPAPER-OB-IMM)
#. ( P.CPAPER + P.FED.FUNS + P.S.P.EPR + P.WPI + OB + P.FUELS -LU)
# (LU-GPG.G + P.US.TBILL +PFED.FUNDS + V.NYSE + K.US - M1 - P.W.AG - IMM.US)
#(Growth Controller), (Unemployment Controller) (Immigration Controller)
#
# L.US.E. L.U. GNP.US. GNP.C. GNP.I. GNP.X. GNP.G. P.US.TBILL.
#[1,] 0.219255 0.03427 0.218049 0.22007 0.17070 0.19552 0.14036 0.1952
#[2,] -0.017407 -0.27196 0.005253 0.06497 0.21297 0.15989 -0.09423 -0.1388
#[3,] -0.009199 0.42160 -0.145851 -0.05149 -0.02629 -0.06495 -0.25493 0.2428
# P.CPAPER. P.FED.FUNDS. P.CPI. P.GDP. P.SP500. V.NYSE. P.S.P.DPR. P.S.P.EPR.
#[1,] -0.13383 0.02642 0.20701 0.21001 0.14791 0.1021 0.1938 0.07653
#[2,] 0.37032 0.29912 0.16164 0.14392 0.01707 0.1071 -0.1949 0.32595
#[3,] 0.03334 0.38465 0.06851 0.01672 0.09099 0.3312 0.1444 0.03397
# Q.H.Starts. K.US. M1 M2 P.WPI. Q.A. Q.I. O.B. P.FUELS.
#[1,] 0.1406 0.20647 0.20742 0.21574 0.17330 0.21310 0.20412 -0.07726 0.15609
#[2,] 0.1977 -0.06538 -0.03534 -0.02157 0.24171 -0.06952 -0.07594 0.39797 0.26114
#[3,] -0.1238 0.21738 -0.21807 -0.14920 -0.06862 -0.05705 -0.15773 0.16908 0.06664
# P.W.AG. P.W.MFG. Q.OIL. N.US. IMM.US. U.US.
#[1,] 0.2040 0.22165 0.21454 0.21224 -0.1506 0.21075
#[2,] 0.0225 0.02006 -0.12565 -0.08458 0.1433 -0.08879
#[3,] -0.2419 -0.07337 0.02101 0.14950 -0.2477 0.17053
#
# Fraction of Variance
# [1] 0.6369 0.7736 0.8551 0.9038 0.9373 0.9579 0.9697 0.9778 0.9842 0.9896 0.9932 0.9956
#[13] 0.9970 0.9978 0.9985 0.9989 0.9992 0.9995 0.9996 0.9998 0.9999 0.9999 0.9999 1.0000
#[25] 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
#
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)
f <- matrix( c( 1.0276420120, -0.04037731, -0.09367185, 0.324320408,
-0.0008705484, 0.95523103, -0.18831136, 0.059323285,
-0.0038330655, 0.10040247, 0.95814360, 0.009650457,
0.0000000000, 0.00000000, 0.00000000, 1.000000000,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
#
# To Stabilize
# Uncomment next line
# f[1,1] <- 0.944211373; f[2,2] <- 1.00456195; f[3,3] <- 0.2597032
# To add Feedback Control to the Banking Component
# Uncomment next line
# f[1,2] <- -0.50
#
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
US_E20 <- SS(F=f,H=h,K=k,z0=c(0.324320408, 0.059323285, 0.009650457, 1.0000000000),
output.names=c("US1","US2","US3"))
print(US_E20)
is.SS(US_E20)
stability(US_E20)
US_E20.data <-simulate(US_E20,sampleT=50,start=1900)
#US_E20.data <- simulate(US_E20,sampleT=50,noise=matrix(0,50,3),start=1900)
US_E20.f <- forecast(m <- l(US_E20,US_E20.data),horizon=150)
tfplot(US_E20.f)
AIC(m)
US_E20x <- SS(F=f,H=h,Q=eye(4,3),R=eye(3,3),z0=c(0.324320408, 0.059323285, 0.009650457, 1.0000000000),
output.names=c("US1","US2","US3"))
shockDecomposition(US_E20x,horizon=10,shock=rep(-1,10))