# Cut-and-Paste Code Below into Window Above and Run
#
# WL20 World Input Model
#
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 (Growth-Living Planet) (Living Planet+P.Wheat-TEMP) (P.WHeat.+P.OIL.-EF)
#
# N OIL QA GWP P.Wheat. P.Oil. TEMP CO2 Carbon
#[1,] 0.2845 0.271 0.2821 0.2824 0.236 0.243 0.251 0.2837 0.2833
#[2,] -0.0161 0.241 0.0985 -0.1413 0.411 0.066 -0.235 -0.0983 0.0925
#[3,] -0.1112 -0.241 -0.0883 0.0213 0.461 0.712 0.190 -0.0201 -0.0955
# TotalFootprint Earths WorldGlobal LivingPlanet URBAN
#[1,] 0.275 0.279 0.2819 -0.1839 0.2840
#[2,] 0.182 0.148 -0.0926 0.7705 -0.0868
#[3,] -0.293 -0.231 -0.0943 -0.0576 -0.0707
#
# Fraction of Variance
# [1] 0.874 0.941 0.973 0.986 0.995 0.998 0.999 0.999 1.000 1.000 1.000 1.000
#[13] 1.000 1.000
#
f <- matrix( c(1.01169571, -0.02519461, -0.09358484, 0.210941578,
-0.01360718, 0.96330129, -0.05250691,-0.003862528,
0.02303607, -0.03631204, 0.93554760, 0.018115378,
0,0,0,1
),byrow=TRUE,nrow=4,ncol=4)
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
WL20 <- SS(F=f,H=h,K=k,z0=c( -5.3541066, -0.7239263, 0.7703831,1.0000000),
output.names=c("W1","W2","W3"))
print(WL20)
is.SS(WL20)
stability(WL20)
# tfplot(simulate(WL20,sampleT=100))
WL20.data <- simulate(WL20,sampleT=100,noise=matrix(0,100,3),start=1950)
WL20.f <- forecast(l(WL20,WL20.data),horizon=100)
tfplot(WL20.f)
WL20.fx <- merge.forecast(WL20.f)
AIC(l(WL20,WL20.data))
#
#
# WL20W India Model
#
AIC <- function(model) {informationTestsCalculations(model)[3]}
require(dse)
require(matlab)
#
# measurementModel(IN_SYS.index) # (Growth) (LU-GDP) (Q+KOF+CO2-N-L-HDI-EF)
# Measurement Matrix
# EN.ATM.CO2E.KT EG.USE.COMM.KT.OE NY.GDP.MKTP.KD SL.TLF.TOTL.IN SP.POP.TOTL SL.UEM.TOTL.ZS KOF EF HDI
#[1,] 0.341 0.343 0.330 0.3402 0.3400 0.281 0.3382 0.3421 0.3407
#[2,] -0.153 -0.137 -0.320 -0.0435 -0.0151 0.919 0.0296 -0.0474 -0.0781
#[3,] 0.239 0.115 0.527 -0.4072 -0.4230 0.164 0.3551 -0.1642 -0.3575
#
# Fraction of Variance
#[1] 0.936 0.980 0.995 0.998 0.999 1.000 1.000 1.000 1.000
#
f <- matrix( c(0.99104762, -0.4937587, -0.3581045, 0.15114290,
-0.09282845, -0.6451188, -0.9352256, -0.17233670,
0.04874386, -0.2839311, 0.8027249, 0.03701673,
0.00000000, 0.0000000, 0.0000000, 1.0000000000
),byrow=TRUE,nrow=4,ncol=4)
#
#
h <- eye(3,4)
k <- (f[,1:3,drop=FALSE])
g <- matrix(c(0.04515727, -0.2166347, -0.4918245,
0.14290808, -0.6056161, -1.7373918,
-0.01775976, -0.1025947, -0.2726349,
0.00000000, 0.0000000, 0.0000000
),byrow=TRUE,nrow=4,ncol=3)
INL20 <- SS(F=f,H=h,K=k,z0=c( 0.03717543, -0.60879738, 0.12882240, 1.0000000000),
output.names=c("IN1","IN2","IN3"))
print(INL20)
is.SS(INL20)
stability(INL20)
# tfplot(simulate(INL20,sampleT=100))
INL20.data <- simulate(INL20,sampleT=150,noise=matrix(0,150,3),start=1950,input=WL20.fx)
INL20.f <- forecast(l(INL20,INL20.data),conditioning.inputs=WL20.fx)
tfplot(INL20.f)
AIC(l(INL20,INL20.data))
INL20x <- SS(F=f,H=h,Q=eye(4,3),R=eye(3,3),z0=c( 0.198687580, -0.019392476, 0.003969969, 1.0000000000),
output.names=c("IN1","IN2","IN3"))
shockDecomposition(INL20x)
#
# Random Walk Model
#
INL20r <- SS(F=eye(4),H=h,Q=eye(4,3),R=eye(3,3),z0=c( 0.198687580, -0.019392476, 0.003969969, 1.0000000000),
output.names=c("IN1","IN2","IN3"))
INL20r.data <- simulate(INL20r,sampleT=50,start=1950)
INL20r.model <- l(INL20r,INL20r.data)
tfplot(INL20r.model)