z_sim {hystar} | R Documentation |
Simulate the threshold/control variable Z
Description
This is a function you can use to simulate time series data
for a threshold variable of the HysTAR model. The time series is a (co)sine
wave, such that thresholds are crossed in a predictable way.
This function is designed to be used in combination with hystar_sim()
.
Usage
z_sim(n_t, n_switches, start_regime = 0, start_hyst = FALSE, range = c(-1, 1))
Arguments
n_t |
The desired length of the simulated time series of |
n_switches |
A scalar indicating the desired number of regime switches.
Basically, it is the number of times the variable moves to (and reaches) its
minimum or to its maximum. If the thresholds are within the range of |
start_regime |
The starting regime of the HysTAR model, 0 (default) or 1. |
start_hyst |
Logical, should |
range |
A numeric vector of length 2 indicating the desired range (min, max) of |
Details
The first value of y
that can be predicted in the HysTAR model is
at time point \max\{d, p\} + 1
, where p = \max\{p_0, p_1\}
.
This is because we need to observe y_{t - p}
and z_{t - d}
.
So the first observed value of z
that determines a regime
is at time point \max\{d, p\} + 1 - d
.
To make sure that this time point corresponds to the start that you request,
z_sim()
starts with 10 extra time points. In this way, hystar_sim
can
select the appropriate time points, based on d
and p0
, p1
.
Value
A numeric vector of length n_t
. This vector has two attributes
"start_regime"
and "start_hyst"
corresponding to the values you provided.
These attributes are used by hystar_sim()
.
The HysTAR model
The HysTAR model is defined as:
y_t = \begin{cases} \phi_{00} + \phi_{01} y_{t-1} + \cdots +
\phi_{0 p_0} y_{t-p_0} + \sigma_{0} \epsilon_{t} \quad \mathrm{if}~R_{t} = 0 \\
\phi_{10} + \phi_{11} y_{t-1} + \cdots + \phi_{1 p_1} y_{t-p_1} + \sigma_{1} \epsilon_{t}
\quad \mathrm{if}~R_{t} = 1, \\ \end{cases}
with R_t = \begin{cases} 0 \quad \quad \mathrm{if} \, z_{t-d} \in (-\infty, r_{0}] \\
R_{t-1} \quad \mathrm{if} \, z_{t-d} \in (r_0, r_1] \\ 1 \quad \quad \mathrm{if} \, z_{t-d}
\in (r_1, \infty), \\ \end{cases}
where p_j
denotes the order of regime j \in \{0,1\}
with
coefficients \phi_{j0}, \dots, \phi_{j p_j \in (-1, 1)}
,
\sigma_{j}
is the standard deviation of the residuals, and d \in
\{0, 1, 2, \dots\}
is a delay parameter. The parameters of primary interest are
the thresholds r_0 \le r_1
. We let t = 0, 1, 2, ..., T
, where T
is the number of observations.
Examples
z <- z_sim(n_t = 200, n_switches = 5, start_regime = 1)
sim <- hystar_sim(z = z, r = c(-.5, .5), d = 2, phi_R0 = c(0, .6), phi_R1 = 1)
plot(sim)
fit <- hystar_fit(sim$data)
summary(fit)