ts.sim: Time series simulation with changepoint effects

View source: R/datasimulation.R

ts.simR Documentation

Time series simulation with changepoint effects

Description

This is a function to simulate time series with changepoint effects. See details below.

Usage

ts.sim(
  beta,
  XMat,
  sigma,
  phi = NULL,
  theta = NULL,
  Delta = NULL,
  CpLoc = NULL,
  seed = NULL
)

Arguments

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 \epsilon_{t}.

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 1\leq\tau\leq T_{s}.

seed

The random seed for simulation reproducibility.

Details

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.

Value

The simulated time series with attributes:

Z

The simulated time series.

Attributes
  • DesignX The covariates include all changepoint indicators.

  • mu A vector includes the mean values for simulated time series sequences.

  • theta The true parameter vector (including changepoint effects).

  • CpEff The true changepoint magnitudes.

  • CpLoc The true changepoint locations where we introduce the mean changing effects.

  • arEff A vector givies the AR coefficients.

  • maEff A vector givies the MA coefficients.

  • seed The random seed used for this simulation.

Examples

##### 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)
TsPlotCheck(Y=myts, tau=CpLocT)

##### 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)
TsPlotCheck(Y=myts, tau=CpLocT)

##### 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)
TsPlotCheck(Y=myts, tau=CpLocT)


##### 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)
TsPlotCheck(Y=myts, tau=CpLocT)

changepointGA documentation built on April 4, 2025, 4:39 a.m.