| ts.sim | R Documentation |
This is a function to simulate time series with changepoint effects. See details below.
ts.sim(
beta,
XMat,
sigma,
phi = NULL,
theta = NULL,
Delta = NULL,
CpLoc = NULL,
seed = NULL
)
beta |
A parameter vector contains other mean function parameters without changepoint parameters. |
XMat |
The covairates for time series mean function without changepoint indicators. |
sigma |
The standard deviation for time series residuals |
phi |
A vector for the autoregressive (AR) parameters for AR part. |
theta |
A vector for the moving average (MA) parameters for MA part. |
Delta |
The parameter vector contains the changepoint parameters for time series mean function. |
CpLoc |
A vector contains the changepoint locations range from |
seed |
The random seed for simulation reproducibility. |
The simulated time series Z_{t}, t=1,\ldots,T_{s} is from a class of models,
Z_{t}=\mu_{t}+e_{t}.
Time series observations are IID
\mu_{t} is a constant
and e_{t}'s are independent and identically distributed as N(0,\sigma).
ARMA(p,q) model with constant mean
\mu_{t} is a constant,
and e_{t} follows an ARMA(p,q) process.
ARMA(p,q) model with seasonality
\mu_{t} is not a constant,
\mu_{t} = ASin(\frac{2\pi t}{S})+BSin(\frac{2\pi t}{S}),
and e_{t} follows an ARMA(p,q) process.
ARMA(p,q) model with seasonality and trend
\mu_{t} is not a constant,
\mu_{t} = ASin(\frac{2\pi t}{S})+BSin(\frac{2\pi t}{S}) + \alpha t,
and e_{t} follows an ARMA(p,q) process.
The changepoint effects could be introduced through the \mu_{t} as
\mu_{t} = \Delta_{1}I_{t>\tau_{1}} + \ldots + \Delta_{m}I_{t>\tau_{m}},
where 1\leq\tau_{1}<\ldots<\tau_{m}\leq T_{s} are the changepoint locations and
\Delta_{1},\ldots,\Delta_{m} are the changepoint parameter that need to be estimated.
The simulated time series with attributes:
Z |
The simulated time series. |
Attributes |
|
##### M1: Time series observations are IID
Ts <- 1000
betaT <- c(0.5) # intercept
XMatT <- matrix(1, nrow = Ts, ncol = 1)
colnames(XMatT) <- "intercept"
sigmaT <- 1
DeltaT <- c(2, -2)
Cp.prop <- c(1 / 4, 3 / 4)
CpLocT <- floor(Ts * Cp.prop)
myts <- ts.sim(
beta = betaT, XMat = XMatT, sigma = sigmaT,
Delta = DeltaT, CpLoc = CpLocT, seed = 1234
)
##### M2: ARMA(2,1) model with constant mean
Ts <- 1000
betaT <- c(0.5) # intercept
XMatT <- matrix(1, nrow = Ts, ncol = 1)
colnames(XMatT) <- "intercept"
sigmaT <- 1
phiT <- c(0.5, -0.5)
thetaT <- c(0.8)
DeltaT <- c(2, -2)
Cp.prop <- c(1 / 4, 3 / 4)
CpLocT <- floor(Ts * Cp.prop)
myts <- ts.sim(
beta = betaT, XMat = XMatT, sigma = sigmaT,
phi = phiT, theta = thetaT, Delta = DeltaT, CpLoc = CpLocT, seed = 1234
)
##### M3: ARMA(2,1) model with seasonality
Ts <- 1000
betaT <- c(0.5, -0.5, 0.3) # intercept, B, D
period <- 30
XMatT <- cbind(rep(1, Ts), cos(2 * pi * (1:Ts) / period), sin(2 * pi * (1:Ts) / period))
colnames(XMatT) <- c("intercept", "Bvalue", "DValue")
sigmaT <- 1
phiT <- c(0.5, -0.5)
thetaT <- c(0.8)
DeltaT <- c(2, -2)
Cp.prop <- c(1 / 4, 3 / 4)
CpLocT <- floor(Ts * Cp.prop)
myts <- ts.sim(
beta = betaT, XMat = XMatT, sigma = sigmaT,
phi = phiT, theta = thetaT, Delta = DeltaT, CpLoc = CpLocT, seed = 1234
)
##### M4: ARMA(2,1) model with seasonality and trend
# scaled trend if large number of sample size
Ts <- 1000
betaT <- c(0.5, -0.5, 0.3, 0.01) # intercept, B, D, alpha
period <- 30
XMatT <- cbind(rep(1, Ts), cos(2 * pi * (1:Ts) / period), sin(2 * pi * (1:Ts) / period), 1:Ts)
colnames(XMatT) <- c("intercept", "Bvalue", "DValue", "trend")
sigmaT <- 1
phiT <- c(0.5, -0.5)
thetaT <- c(0.8)
DeltaT <- c(2, -2)
Cp.prop <- c(1 / 4, 3 / 4)
CpLocT <- floor(Ts * Cp.prop)
myts <- ts.sim(
beta = betaT, XMat = XMatT, sigma = sigmaT,
phi = phiT, theta = thetaT, Delta = DeltaT, CpLoc = CpLocT, seed = 1234
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.