set.seed(1)
# GMAR model:
params22 <- c(0.9, 0.4, 0.2, 0.5, 0.7, 0.5, -0.2, 0.7, 0.7)
mod22 <- GSMAR(p=2, M=2, params=params22, model="GMAR")
mysim <- simulate(mod22, nsim=500)
ts.plot(mysim$sample)
ts.plot(mysim$component)
ts.plot(mysim$mixing_weights, col=rainbow(2), lty=2)
# G-StMAR model, with initial values:
params42gs <- c(0.04, 1.34, -0.59, 0.54, -0.36, 0.01, 0.06, 1.28, -0.36,
0.2, -0.15, 0.04, 0.19, 9.75)
gstmar42 <- GSMAR(data=M10Y1Y, p=4, M=c(1, 1), params=params42gs,
model="G-StMAR")
sim42gs <- simulate(gstmar42, nsim=500, init_values=1:4)
ts.plot(sim42gs$sample)
ts.plot(sim42gs$component)
ts.plot(sim42gs$mixing_weights, col=rainbow(2), lty=2)
# FORECASTING EXAMPLE:
# GMAR model, 1000 sets of simulations with initial values from the data:
params12 <- c(1.70, 0.85, 0.30, 4.12, 0.73, 1.98, 0.63)
gmar12 <- GSMAR(data=simudata, p=1, M=2, params=params12, model="GMAR")
sim12 <- simulate(gmar12, nsim=5, init_val=gmar12$data, ntimes=1000)
apply(sim12$sample, MARGIN=1, FUN=median) # Point prediction
apply(sim12$sample, MARGIN=1, FUN=quantile, probs=c(0.025, 0.975)) # 95% pi
apply(sim12$mixing_weights, MARGIN=1:2, FUN=median) # mix.weight point pred
apply(sim12$mixing_weights, MARGIN=1:2, FUN=quantile,
probs=c(0.025, 0.975)) # mix.weight 95% prediction intervals
Run the code above in your browser using DataLab