# Cut-and-Paste Code Below into Window Above and Run
#
# LA_E20 Model
#
# US_E20 Model
#
# Measurement Matrix (Growth) (Hours+XREAL-X-Q) (Q+HOURS-XREAL-X)
# Q N HOURS XREAL X L
#[1,] 0.4041 0.414833 0.3981 0.4123 0.4053 0.41454
#[2,] -0.4774 0.009769 0.7037 0.2063 -0.4818 0.04558
#[3,] 0.7410 0.035540 0.2377 -0.2841 -0.5259 -0.18943
#
# Fraction of Variance
#[1] 0.9684 0.9939 0.9988 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.008952716, -0.04339303, 0.01050584, 0.17033656,
-0.016091116, 0.93613443, 0.17244557, 0.01340404,
0.009518643, -0.08083774, 1.13854519, 0.01724704,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
#
# To Stabilize
# Uncomment next line
# f[1,1] <- 0.959503994; f[2,2] <- 0.89025453; f[3,3] <- 1.08274514
#
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
US_E20 <- SS(F=f,H=h,K=k,z0=c(0.17033656, 0.01340404, 0.01724704, 1.0000000000),
output.names=c("US1","US2","US3"))
stability(m0 <- SS(F=f[1:3,1:3,drop=FALSE],Q=eye(3),R=eye(3),H=eye(3)))
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)
US_E20.fx <- merge.forecast(US_E20.f)
#
# LA_E20 Model US Input
#
# Measurement Matrix (Growth), (Q-XREAL-X), (N-XREAL-Q)
#
# Q N XREAL X
#[1,] 0.486 0.5062 0.501 0.50591
#[2,] 0.839 -0.0625 -0.453 -0.29580
#[3,] -0.244 0.7872 -0.566 0.00801
#
# Fraction of Variance
#[1] 0.966 0.996 1.000 1.000
#
AIC <- function(model) {informationTestsCalculations(model)[3]}
require(dse)
require(matlab)
f <- matrix( c( 12.806063, -1.632839, 6.243523, 0.3746286,
-2.358584, 1.133719, -4.946093, -0.3171895,
-1.424776, 0.754239, -3.075545, -0.1909391,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
#
# To Stabilize Uncomment Next Line
# f[1,1] <- 2.778002; f[2,2] <- 1.122382; f[3,3] <- -3.044790;
#
g <- matrix(c(-1.461323, 0.6871879, 1.572632,
1.856476, -2.0264082, 1.577816,
1.147264, -0.8470857, -0.276423,
0.000000, 0.0000000 , 0.000000
),byrow=TRUE,nrow=4,ncol=3)
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
LA_E20 <- SS(F=f,H=h,K=k,G=g,z0=c(5.299885, -5.977458, -3.899165, 1.0000000000),
output.names=c("LA1","LA2","LA3"))
stability(m0 <- SS(F=f[1:3,1:3,drop=FALSE],Q=eye(3),R=eye(3),H=eye(3)))
print(LA_E20)
is.SS(LA_E20)
LA_E20.data <- simulate(LA_E20,input=US_E20.fx)
tfplot(outputData(LA_E20.data))
AIC(l(LA_E20,LA_E20.data))
shockDecomposition(m0,horizon=10,shock=rep(-1,10))