# Cut-and-paste code below into window above and Run
#
# Africa (AF) Model (1950-2000)
#
#
# Measurement Matrix (Overall), (XREAL-Q-N), (Q-N) (Malthusian))
#
# Q N XREAL
#[1,] 0.589 0.584 0.5587
#[2,] -0.343 -0.445 0.8271
#[3,] 0.732 -0.679 -0.0614
#
# Fraction of Variance
#[1] 0.940 0.998 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.025381733, -0.016310665, -0.6741595, 0.137157658,
0.007851544, 0.988233026, -1.2077588, 0.029628882,
-0.006312777, 0.009605595, 1.0707305, -0.002758338,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
#
# To stabilize model, uncomment next three lines
# f[1,1] <- 0.984977601
# f[2,2] <- 0.949292702
# f[3,3] <- 1.0285394
#
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
AF_LM <- SS(F=f,H=h,K=k,z0=c(0.137157658, 0.029628882, -0.002758338, 1.0000000000),
output.names=c("AF1","AF2","AF3"))
print(AF_LM)
is.SS(AF_LM)
stability(AF_LM)
AF_LM.data <- simulate(AF_LM,sampleT=100,start=1950)
#AF_LM.data <- simulate(AF_LM,sampleT=100,noise=matrix(0,100,3),start=1950)
AF_LM.f <- forecast(l(AF_LM,AF_LM.data),horizon=150)
AF_LM.fx <- merge.forecast(AF_LM.f)
tfplot(AF_LM.f)
AIC(m <- l(AF_LM,AF_LM.data))
AF_LMx <- SS(F=f,H=h,Q=eye(4,3),R=eye(3,3),z0=c(0.279172909, 0.063317428, -0.0062930188, 1.0000000000),
output.names=c("AF1","AF2","AF3"))
shockDecomposition(AF_LMx)
#
# LCI Parameter UCI P>=T[1] P< T[1] Std. Dev. Bias Bias-z
# [1,] 1.001581 1.025382 1.0541371 0.36 0.64 0.023142 0.002421 0.1046
# [2,] -0.007663 0.007852 0.0284854 0.36 0.64 0.016283 1.017494 62.4867
# [3,] -0.008642 -0.006313 -0.0046471 0.69 0.31 0.002031 1.031633 507.9199
# [4,] -0.095541 -0.016311 0.0365371 0.40 0.60 0.049099 1.060378 21.5965
# [5,] 0.957108 0.988233 1.0252309 0.21 0.79 0.028297 0.057326 2.0259
# [6,] 0.003593 0.009606 0.0141696 0.76 0.24 0.004463 1.013501 227.0968
# [7,] -1.280303 -0.674160 -0.0555197 0.70 0.30 0.608512 1.546150 2.5409
# [8,] -1.724356 -1.207759 -0.8630077 0.72 0.28 0.386870 2.212082 5.7179
# [9,] 1.015755 1.070731 1.1271480 0.26 0.74 0.054468 -0.029064 -0.5336
#[10,] 0.123930 0.137158 0.1528226 0.56 0.44 0.016417 0.883720 53.8291
#[11,] 0.012988 0.029629 0.0449267 0.47 0.53 0.015758 0.996019 63.2089
#[12,] -0.005969 -0.002758 -0.0004332 0.56 0.44 0.002209 1.028213 465.5432
#