# Cut-and-Paste Code Below
#
# LA19 Model US Input
#
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)
#
# US19 BAU Model
#
f <- matrix( c(1.029955791, -0.07367613, 0.0322730, 0.081953161,
0.012337159, 1.03101395, -0.0189414, 0.005562881,
0.001150714, 0.02690949, 0.9900611, 0.004165105,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
US19 <- SS(F=f,H=h,K=k,z0=c(0.081953161, 0.005562881, 0.004165105, 1.0000000000),
output.names=c("US1","US2","US3"))
stability(m <- SS(F=f[1:3,1:3,drop=FALSE],Q=eye(3),R=eye(3),H=eye(3)))
US19.data <- simulate(US19,sampleT=100,noise=matrix(0,100,3),start=1800)
US19.f <- forecast(m1<-l(US19,US19.data),horizon=150)
US19.fx <- merge.forecast(US19.f)
#
# LA19 US input
#
# Measurement Matrix (Growth), (Q-N), X+Q-N-XREAL), (X+Q - XREAL-N), (N+Q-XREAL)
#
# Q N XREAL X
#[1,] 0.491 0.504 0.508 0.497
#[2,] 0.746 -0.344 0.158 -0.548
#[3,] 0.346 -0.492 -0.475 0.642
#
#[4,] 0.289 0.621 -0.701 -0.199
#
# Fraction of Variance
#[1] 0.959 0.991 0.999 1.000
#
f <- matrix( c( 0.87228096, -0.003732179, 0.13630066, 0.06246020,
-0.08228022, 0.983759924, -0.07970886, -0.01506414,
0.00509755, -0.022112861, 0.94415560, 0.00712117,
0.00000000, 0.000000000, 0.00000000, 1.00000000
),byrow=TRUE,nrow=4,ncol=4)
#
# To Stabilize, Uncomment next line
# f[1,1] <- 0.84 ; f[2,2] <- 0.95 ; f[3,3] <- 0.91
#
g <- matrix(c(0.128620512, -0.04455699, 0.02618161,
0.064936883, -0.01738539, 0.02931320,
0.002977154, 0.09261271, 0.01585145,
0.000000000, 0.00000000, 0.00000000
),byrow=TRUE,nrow=4,ncol=3)
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
LA19 <- SS(F=f,H=h,K=k,G=g,z0=c(-0.20946706, -0.15411473, 0.03308617, 1.0000000000),
output.names=c("LA1","LA2","LA3"))
print(LA19)
is.SS(LA19)
stability(m <- SS(F=f[1:3,1:3,drop=FALSE],Q=eye(3,3),R=eye(3),H=eye(3)))
# tfplot(simulate(LA19,sampleT=100))
LA19.data <- simulate(LA19,input=US19.fx)
LA19.f <- forecast(m1<-l(LA19,LA19.data),conditioning.inputs=US19.fx)
tfplot(LA19.f)
AIC(m1)