
Last chance! 50% off unlimited learning
Sale ends in
Function generates data using ETS with Single Source of Error as a data generating process.
sim.es(model = "ANN", obs = 10, nsim = 1, frequency = 1,
persistence = NULL, phi = 1, initial = NULL, initialSeason = NULL,
bounds = c("usual", "admissible", "restricted"), randomizer = c("rnorm",
"rlnorm", "rt", "rlaplace", "rs"), iprob = 1, ...)
Type of ETS model according to [Hyndman et. al., 2008]
taxonomy. Can consist of 3 or 4 chars: ANN
, AAN
, AAdN
,
AAA
, AAdA
, MAdM
etc.
Number of observations in each generated time series.
Number of series to generate (number of simulations to do).
Frequency of generated data. In cases of seasonal models must be greater than 1.
Persistence vector, which includes all the smoothing
parameters. Must correspond to the chosen model. The maximum length is 3:
level, trend and seasonal smoothing parameters. If NULL
, values are
generated.
Value of damping parameter. If trend is not chosen in the model, the parameter is ignored.
Vector of initial states of level and trend. The maximum
length is 2. If NULL
, values are generated.
Vector of initial states for seasonal coefficients.
Should have length equal to frequency
parameter. If NULL
,
values are generated.
Type of bounds to use for persistence vector if values are
generated. "usual"
- bounds from p.156 by Hyndman et. al., 2008.
"restricted"
- similar to "usual"
but with upper bound equal
to 0.3. "admissible"
- bounds from tables 10.1 and 10.2 of Hyndman
et. al., 2008. Using first letter of the type of bounds also works. These
bounds are also used for multiplicative models, but the models are much
more restrictive, so weird results might be obtained. Be careful!
Type of random number generator function used for error
term. Defaults are: rnorm
, rt
, rlaplace
and rs
.
rlnorm
should be used for multiplicative models (e.g. ETS(M,N,N)).
But any function from Distributions will do the trick if the
appropriate parameters are passed. For example rpois
with
lambda=2
can be used as well, but might result in weird values.
Probability of occurrence, used for intermittent data generation. This can be a vector, implying that probability varies in time (in TSB or Croston style).
Additional parameters passed to the chosen randomizer. All the
parameters should be passed in the order they are used in chosen randomizer.
For example, passing just sd=0.5
to rnorm
function will lead
to the call rnorm(obs, mean=0.5, sd=1)
. ATTENTION! When generating
the multiplicative errors some tuning might be needed to obtain meaningful
data. sd=0.1
is usually already a high value for such models.
List of the following values is returned:
model
- Name of ETS model.
data
- Time series vector (or matrix if nsim>1
) of the generated
series.
states
- Matrix (or array if nsim>1
) of states. States are in
columns, time is in rows.
persistence
- Vector (or matrix if nsim>1
) of smoothing
parameters used in the simulation.
phi
- Value of damping parameter used in time series generation.
initial
- Vector (or matrix) of initial values.
initialSeason
- Vector (or matrix) of initial seasonal coefficients.
iprob
- vector of probabilities used in the simulation.
intermittent
- type of the intermittent model used.
residuals
- Error terms used in the simulation. Either vector or matrix,
depending on nsim
.
occurrence
- Values of occurrence variable. Once again, can be either
a vector or a matrix...
logLik
- Log-likelihood of the constructed model.
For the information about the function, see the vignette:
vignette("simulate","smooth")
Snyder, R. D., 1985. Recursive Estimation of Dynamic Linear Models. Journal of the Royal Statistical Society, Series B (Methodological) 47 (2), 272-276.
Hyndman, R.J., Koehler, A.B., Ord, J.K., and Snyder, R.D. (2008) Forecasting with exponential smoothing: the state space approach, Springer-Verlag. http://dx.doi.org/10.1007/978-3-540-71918-2.
es, ets,
forecast, ts, Distributions
# NOT RUN {
# Create 40 observations of quarterly data using AAA model with errors from normal distribution
ETS.AAA <- sim.es(model="AAA",frequency=4,obs=40,randomizer="rnorm",mean=0,sd=100)
# Create 50 series of quarterly data using AAA model
# with 40 observations each with errors from normal distribution
ETS.AAA <- sim.es(model="AAA",frequency=4,obs=40,randomizer="rnorm",mean=0,sd=100,nsim=50)
# Create 50 series of quarterly data using AAdA model
# with 40 observations each with errors from normal distribution
# and smoothing parameters lying in the "admissible" range.
ETS.AAA <- sim.es(model="AAA",phi=0.9,frequency=4,obs=40,bounds="admissible",
randomizer="rnorm",mean=0,sd=100,nsim=50)
# Create 60 observations of monthly data using ANN model
# with errors from beta distribution
ETS.ANN <- sim.es(model="ANN",persistence=c(1.5),frequency=12,obs=60,
randomizer="rbeta",sshape1=1.5,sshape2=1.5)
plot(ETS.ANN$states)
# Create 60 observations of monthly data using MAM model
# with errors from uniform distribution
ETS.MAM <- sim.es(model="MAM",persistence=c(0.3,0.2,0.1),initial=c(2000,50),
phi=0.8,frequency=12,obs=60,randomizer="runif",min=-0.5,max=0.5)
# Create 80 observations of quarterly data using MMM model
# with predefined initial values and errors from the normal distribution
ETS.MMM <- sim.es(model="MMM",persistence=c(0.1,0.1,0.1),initial=c(2000,1),
initialSeason=c(1.1,1.05,0.9,.95),frequency=4,obs=80,mean=0,sd=0.01)
# Generate intermittent data using AAdN
iETS.AAdN <- sim.es("AAdN",frequency=1,obs=30,iprob=0.1,initial=c(3,0),phi=0.8)
# Generate iETS(MNN) with TSB style probabilities
pt <- sim.es("MNN",persistence=0.2,initial=0.5,obs=50,mean=0,sd=0.3)
iprob <- mean(rbeta(50,shape1=pt$states,shape2=1-pt$states))
iETS.MNN <- sim.es("MNN",frequency=12,persistence=0.2,initial=4,iprob=iprob,obs=50)
# }
Run the code above in your browser using DataLab