# Cut-and-paste code below into window above and Run
#
# North America (NA) Model (1950-2000)
#
# Measurement Matrix (Growth), (N-XREAL-X-L), (XREAL-X-L+N)
#
# Q N XREAL X L
#[1,] 0.4544 0.443 0.441 0.445 0.453
#[2,] 0.2183 0.555 -0.574 -0.487 0.276
#[3,] -0.0995 0.412 0.623 -0.530 -0.389
#
# Fraction of Variance
#[1] 0.960 0.996 1.000 1.000 1.000
#
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)
f <- matrix( c(1.034221555, -0.00410808, -0.02808741, 0.16057008,
-0.033299694, 1.05703398, 0.07032517, -0.01391041,
0.003681037, -0.06723139, 0.99583196, 0.01197887,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
#
# To stabilize model, uncomment next line
# f[1,1] <- 0.993469099; f[2,2] <- 1.01538263; f[3,3] <- 0.95659221
#
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
NA_LM <- SS(F=f,H=h,K=k,z0=c(0.16057008, -0.01391041, 0.01197887, 1.0000000000),
output.names=c("NA1","NA2","NA3"))
print(NA_LM)
is.SS(NA_LM)
stability(NA_LM)
NA_LM.data <- simulate(NA_LM,sampleT=100,start=1950)
#NA_LM.data <- simulate(NA_LM,sampleT=20,noise=matrix(0,20,3))
NA_LM.f <- forecast(l(NA_LM,NA_LM.data),horizon=150)
MA_LM.fx <- merge.forecast(NA_LM.f)
tfplot(NA_LM.f)
AIC(m <- l(NA_LM,NA_LM.data))
NA_LMx <- SS(F=f,H=h,Q=eye(4,3),R=eye(3,3),z0=c(0.16057008, -0.01391041, 0.01197887, 1.0000000000),
output.names=c("NA1","NA2","NA3"))
shockDecomposition(NA_LMx)