# Cut-and-paste code below into window above and Run
#
# WRE World Model Roman Empire (RE 0-500)
#
# Measurement Matrix (Q+N-T) (Growth) (Q-N)
# Q N T
#[1,] 0.577 0.578 -0.577
#[2,] 0.528 0.274 0.804
#[3,] 0.622 -0.769 -0.147
#
# Fraction of Variance
#[1] 0.998 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(9.990858e-01, 6.700905e-03, 3.284895e+09, 1.173565e-02,
-6.563034e-04, 1.004810e+00, 2.358134e+09, -1.717386e-04,
8.324437e-19, 2.223337e-17, -7.995155e-02 , 1.087672e-15,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
# To stabilize uncomment the following lines
#f[2,2] <- .9
# To clean up the system uncomment the following line
#f[3,1] <- f[3,2] <- 0;
# To disable the Malthusian Controller,
# uncomment the following line
#f[1,3] <- f[2,3] <- 0;
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
WRE <- SS(F=f,H=h,K=k,z0=c(1.173565e-02, -1.717386e-04 , 1.087672e-15, 1.0000000000),
output.names=c("W1","W2","W3"))
print(WRE)
is.SS(WRE)
stability(WRE)
tfplot(WRE.data <- simulate(WRE,sampleT=150,start=1))
#WRE.data <- simulate(WRE,sampleT=20,noise=matrix(0,20,3))
WRE.f <- forecast(m <- l(WRE,WRE.data),horizon=50)
tfplot(WRE.f)
WRE.fx <- merge.forecast(WRE.f)
AIC(m)
WREx <- SS(F=f,H=h,Q=eye(4,3),R=eye(3,3),z0=c(1.173565e-02, -1.717386e-04 , 1.087672e-15, 1.0000000000),
output.names=c("W1","W2","W3"))
shockDecomposition(WREx)
# To run realistic counterfactuals set coefficients to values between LCI and UCI
# LCI Parameter UCI P>=T[1] P< T[1] Std. Dev. Bias Bias-z
# [1,] 9.987e-01 9.991e-01 9.995e-01 0.49 0.51 2.992e-04 2.435e-05 8.137e-02
# [2,] -6.937e-04 -6.563e-04 -6.257e-04 0.54 0.46 2.672e-05 9.997e-01 3.741e+04
# [3,] -1.609e-17 8.324e-19 1.935e-17 0.57 0.43 1.279e-17 9.991e-01 7.811e+16
# [4,] -2.495e-03 6.701e-03 1.452e-02 0.56 0.44 6.727e-03 9.917e-01 1.474e+02
# [5,] 1.004e+00 1.005e+00 1.006e+00 0.49 0.51 8.756e-04 -5.613e-03 -6.410e+00
# [6,] -4.397e-16 2.223e-17 4.464e-16 0.50 0.50 3.416e-16 9.991e-01 2.924e+15
# [7,] -9.021e+11 3.285e+09 7.415e+11 0.48 0.52 5.955e+11 5.679e+10 9.535e-02
# [8,] -9.033e+10 2.358e+09 1.094e+11 0.53 0.47 7.567e+10 -1.268e+10 -1.675e-01
# [9,] -1.294e-01 -7.995e-02 -1.534e-02 1.00 0.00 5.902e-02 6.913e-01 1.171e+01
#[10,] 1.098e-02 1.174e-02 1.270e-02 0.53 0.47 6.230e-04 9.873e-01 1.585e+03
#[11,] -2.988e-04 -1.717e-04 -5.609e-05 0.48 0.52 9.730e-05 9.993e-01 1.027e+04
#[12,] 1.022e-15 1.088e-15 1.146e-15 0.01 0.99 6.343e-17 9.991e-01 1.575e+16
#