# Cut-and-Paste Code Below into Window Above and Run
#
# ES_M Model (1900-2000)
#
# Measurement Matrix
# Q N U HOURS XREAL X L
#[1,] 0.398 0.415 0.4145 0.348 0.344 0.335 0.383
#[2,] 0.192 -0.134 -0.1512 -0.503 0.512 0.529 -0.357
#[3,] 0.769 0.250 -0.0857 -0.102 -0.190 -0.399 -0.364
#
# Fraction of Variance
#[1] 0.807 0.985 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(1.013556897, 0.005104802, 0.01837777, 0.08768135,
0.037664684, 1.027637926, 0.06084375, 0.01656348,
-0.002244742, -0.024811661, 0.99699055, -0.01097830,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
#
# To stabilize, uncomment the following code
# f[1,1] <- f[2,2] <- f[3,3] <- .97
#
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
ES_M <- SS(F=f,H=h,K=k,z0=c( 0.08768135, 0.01656348, -0.01097830, 1.0000000000),
output.names=c("ES1","ES2","ES3"))
print(ES_M)
is.SS(ES_M)
stability(ES_M)
#tfplot(ES_M.data <- simulate(ES_M,sampleT=150,start=1900))
ES_M.data <- simulate(ES_M,sampleT=150,noise=matrix(0,150,3),start=1900)
ES_M.f <- forecast(m <- l(ES_M,ES_M.data),horizon=150)
tfplot(ES_M.f)
AIC(m)
ES_Mx <- SS(F=f,H=h,Q=eye(4,3),R=eye(3),z0=c( 0.08768135, 0.01656348, -0.01097830, 1.0000000000),
output.names=c("ES1","ES2","ES3"))
shockDecomposition(ES_Mx)
# To explore Negative Shocks, Uncomment the next line for a -1 sd shock
#shockDecomposition(ES_Mx,shock=rep(-1,10))
#
# To create probable counterfactuals, set coefficients between LCI and UCI
#
# LCI Parameter UCI P>=T[1] P< T[1] Std. Dev.
# [1,] 1.006786 1.013557 1.020e+00 0.42 0.58 0.005617
# [2,] 0.029896 0.037665 4.570e-02 0.47 0.53 0.006560
# [3,] -0.005248 -0.002245 8.335e-05 0.58 0.42 0.002430
# [4,] -0.011115 0.005105 1.988e-02 0.42 0.58 0.012039
# [5,] 1.012311 1.027638 1.049e+00 0.30 0.70 0.014714
# [6,] -0.031370 -0.024812 -2.056e-02 0.65 0.35 0.004394
# [7,] -0.021849 0.018378 5.822e-02 0.63 0.37 0.031928
# [8,] 0.020385 0.060844 9.115e-02 0.67 0.33 0.028659
# [9,] 0.985099 0.996991 1.010e+00 0.23 0.77 0.010130
#[10,] 0.082851 0.087681 9.462e-02 0.67 0.33 0.005206
#[11,] 0.002617 0.016563 3.140e-02 0.51 0.49 0.011509
#[12,] -0.014866 -0.010978 -7.217e-03 0.44 0.56 0.003230
#