# Cut-and-Paste Code Below into Window above and Run
require(dse)
require(matlab)
#
# AEGY Model (Ancient Egypt 31000BCE - 1AD)
# Measurement Matrix
#
# N Q
#[1,] 0.707 0.707
#[2,] -0.707 0.707
#
# Fraction of Variance
#[1] 0.996 1.000
#
AIC <- function(model) {informationTestsCalculations(model)[3]}
f <- matrix( c( 0.952957168, 0.9157134, 1.816266e-01,
-0.006214844, 0.8089116, -5.893046e-05,
0.0000000, 0.0000000, 1.0000000
),byrow=TRUE,nrow=3,ncol=3)
#
# To Stabilize, Uncomment Next Line
#
# f[1,1] <- 0.943427596
#
# To create a Random Walk, Uncomment Next Line
# f[1,1] <- f[2,2] <- 1
#
h <- eye(2,3)
k <- f[1:3,1:2,drop=FALSE]
AEGY <- SS(F=f,H=h,K=k,z0=c( 0.354655070, -0.001235381, 1.0000000),
output.names=c("Growth","Q-N"))
#
stability(SS(F=f[1:2,1:2,drop=FALSE],R=eye(2),Q=eye(2),H=eye(2))
shockDecomposition(toSSChol(AEGY))
#tfplot(simulate(AEGY,sampleT=50,noise=matrix(0,50,2),start=1))
AEGY.data <- simulate(AEGY,sampleT=50,start=1)
m <- l(AEGY,AEGY.data)
#tfplot(m)
AEGY.f <- forecast(m,horizon=50)
tfplot(AEGY.f)
AIC(m)