# Cut-and-paste code below into window above and Run
#
# Switzerland (CH) Model (1950-2000)
#
#
# Measurement Matrix (Growth), (X-HOURS), (U-HOURS-X)
#
# Q N U HOURS XREAL X L
#[1,] 0.389 0.388 0.388 0.354 0.387 0.345 0.3906
#[2,] -0.145 -0.199 0.180 -0.618 0.210 0.687 -0.0917
#[3,] 0.212 0.275 0.547 -0.566 -0.224 -0.446 0.1031
#
# Fraction of Variance
#[1] 0.933 1.000 1.000 1.000 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( 0.986091451, -0.02842443, 0.4585358, 0.165226628,
0.034833406, 1.02993562, -0.5527579, 0.014032953,
-0.001291216, 0.01073976, 0.8885394, 0.003541658,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
#
# To stabilize model, uncomment next line
# f[2,2] <- .90
#
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
CH_LM <- SS(F=f,H=h,K=k,z0=c(0.165226628, 0.014032953 , 0.003541658, 1.0000000000),
output.names=c("CH1","CH2","CH3"))
print(CH_LM)
is.SS(CH_LM)
stability(CH_LM)
#CH_LM.data <- simulate(CH_LM,sampleT=100,start=1950)
CH_LM.data <- simulate(CH_LM,sampleT=100,noise=matrix(0,100,3),start=1950)
CH_LM.f <- forecast(l(CH_LM,CH_LM.data),horizon=150)
CH_LM.fx <- merge.forecast(CH_LM.f)
tfplot(CH_LM.f)
AIC(m <- l(CH_LM,CH_LM.data))
CH_LMx <- SS(F=f,H=h,Q=eye(4,3),R=eye(3,3),z0=c(00.165226628, 0.014032953 , 0.003541658, 1.0000000000),
output.names=c("CH1","CH2","CH3"))
shockDecomposition(CH_LMx)
#
# RANDOM WALK
#
CH_LM_RW <- SS(F=eye(4,4),H=h,Q=eye(4,3),R=eye(3,3),z0=c(0.165226628, 0.014032953 , 0.003541658, 1.0000000000),
output.names=c("CH1","CH2","CH3"))
for (i in 1:5) {
CH_LM_RW.data <- simulate(CH_LM_RW,sampleT=100,start=1950)
AIC(m <- l(CH_LM_RW,CH_LM_RW.data))
tfplot(m)
}