simulate.gsmar: Simulate obsercations from GMAR, StMAR, and G-StMAR processes

Description Usage Arguments Details Value References See Also Examples

View source: R/simulateGSMAR.R

Description

simulate.gsmar simulates observations from the specified GMAR, StMAR, or G-StMAR process. Can be utilized for forecasting future values of the process.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## S3 method for class 'gsmar'
simulate(
  object,
  nsim = 1,
  seed = NULL,
  ...,
  init_values = NULL,
  ntimes = 1,
  drop = TRUE
)

Arguments

object

object of class 'gsmar', typically created with the function fitGSMAR or GSMAR.

nsim

a positive integer specifying how many values (ahead from init_values) will be simulated.

seed

an integer that specifies the seed for the random number generator. Ignored if NULL.

...

currently not in use.

init_values

a numeric vector with length >=p specifying the initial values for the simulation. The last element will be used as the initial value for the first lag, the second last element will be initial value for the second lag, etc. If NULL, initial values will be simulated from the process's stationary distribution.

ntimes

a positive integer specifying how many sets of simulations should be performed.

drop

if TRUE (default) then the components of the returned list are coerced to lower dimension if ntimes==1, i.e., $sample and $component will be vectors and $mixing_weights will be matrix.

Details

The argument ntimes is intended for forecasting: a GSMAR process can be forecasted by simulating its possible future values. One can perform a large number of sets of simulations and calculate the sample quantiles from the simulated values to obtain prediction intervals. See the forecasting example below for a hand-on demonstration.

Value

If drop==TRUE and ntimes==1 (default): $sample and $component are vectors and $mixing_weights is a (nsimxM) matrix. Otherwise, returns a list with...

$sample

a size (nsimxntimes) matrix containing the simulated values.

$component

a size (nsimxntimes) matrix containing the information from which mixture component each value was generated from.

$mixing_weights

a size (nsimxMxntimes) array containing the mixing weights corresponding to the sample: the dimension [i, , ] is the time index, the dimension [, i, ] indicates the regime, and the dimension [, , i] indicates the i:th set of simulations.

References

See Also

fitGSMAR, GSMAR, predict.gsmar, add_data, cond_moments, mixing_weights

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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

uGMAR documentation built on Jan. 24, 2022, 5:10 p.m.