# Cut-and-paste code below into window above and Run
#
# WL17 World Model (1640-1815)
#
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)
#
# Measurement Matrix (Q+N+L-T), Growth, (Q-N)
# Q N L T
#[1,] 0.5003 0.500 0.502 -0.497
#[2,] 0.0236 0.482 0.308 0.820
#[3,] 0.8489 -0.424 -0.146 0.280
#
# Fraction of Variance
#[1] 0.987 0.995 0.999 1.000
#
f <- matrix( c(1.003915900, -0.05394886, 0.04228067, 0.034003648,
0.003124053 , 0.97762596, 0.01350334, -0.002133567,
-0.002277035, -0.02980316, 1.03872708, -0.003510017,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
#
# To stabilize, uncomment next line
# f[1,1] <- f[3,3] <- 0.96
#
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
WL17 <- SS(F=f,H=h,K=k,z0=c(0.034003648, -0.002133567, -0.003510017, 1.0000000000),
output.names=c("W1","W2","W3"))
print(WL17)
is.SS(WL17)
stability(SS(F=f[1:3,1:3,drop=FALSE],H=eye(3),R=eye(3),Q=eye(3)))
# tfplot(simulate(WL17,sampleT=100))
WL17.data <- simulate(WL17,sampleT=150,noise=matrix(0,150,3))
WL17.f <- forecast(l(WL17,WL17.data),horizon=150)
tfplot(WL17.f)
AIC(m <- l(WL17,WL17.data))
WL17x <- SS(F=f,H=h,Q=eye(4,3),R=eye(3,3),z0=c(0.034003648, -0.002133567, -0.003510017, 1.0000000000),
output.names=c("W1","W2","W3"))
shockDecomposition(WL17x)
#
# For realistic counterfactuals, set coefficients between LCI and UCI
#
# LCI Parameter UCI P>=T[1] P< T[1] Std. Dev. Bias Bias-z
# [1,] 1.002347 1.003916 1.005375 0.45 0.55 0.0012153 0.0001149 0.09452
# [2,] 0.002734 0.003124 0.003522 0.49 0.51 0.0003533 1.0007449 2832.81487
# [3,] -0.002826 -0.002277 -0.001722 0.57 0.43 0.0005016 1.0061442 2006.01746
# [4,] -0.068914 -0.053949 -0.039373 0.45 0.55 0.0109027 1.0589296 97.12537
# [5,] 0.971084 0.977626 0.984347 0.46 0.54 0.0063487 0.0278975 4.39422
# [6,] -0.033542 -0.029803 -0.026225 0.50 0.50 0.0028310 1.0339581 365.22343
# [7,] 0.012500 0.042281 0.066436 0.58 0.42 0.0215661 0.9553671 44.29945
# [8,] 0.009458 0.013503 0.017062 0.51 0.49 0.0029709 0.9905356 333.40911
# [9,] 1.026455 1.038727 1.049026 0.33 0.67 0.0105911 -0.0306179 -2.89090
#[10,] 0.032456 0.034004 0.035838 0.58 0.42 0.0013177 0.9695134 735.74468
#[11,] -0.003150 -0.002134 -0.001212 0.46 0.54 0.0007165 1.0060856 1404.21314
#[12,] -0.004265 -0.003510 -0.002713 0.55 0.45 0.0006019 1.0074250 1673.85820
#