Skip to contents

This function simulates a time series from the distribution estimated by the given covlmc object.

Usage

# S3 method for covlmc
simulate(object, nsim = 1, seed = NULL, covariate, init = NULL, ...)

Arguments

object

a fitted covlmc object.

nsim

length of the simulated time series (defaults to 1).

seed

an optional random seed (see the dedicated section).

covariate

values of the covariates.

init

an optional initial sequence for the time series.

...

additional arguments.

Value

a simulated discrete time series of the same type as the one used to build the covlmc with a seed attribute (see the Random seed section). The results has also the dts class to hide the seed attribute when using print or similar function.

Details

A VLMC with covariates model needs covariates to compute its transition probabilities. The covariates must be submitted as a data frame using the covariate argument. In addition, the time series can be initiated by a fixed sequence specified via the init parameter.

Extended contexts

As explained in details in loglikelihood.covlmc() documentation and in the dedicated vignette("likelihood", package = "mixvlmc"), the first initial values of a time series do not in general have a proper context for a COVLMC with a non zero order. In order to simulate something meaningful for those values, we rely on the notion of extended context defined in the documents mentioned above. This follows the same logic as using loglikelihood.covlmc() with the parameter initial="extended". All covlmc functions that need to manipulate initial values with no proper context use the same approach.

Random seed

This function reproduce the behaviour of stats::simulate(). If seed is NULL the function does not change the random generator state and returns the value of .Random.seed as a seed attribute in the return value. This can be used to reproduce exactly the simulation results by setting .Random.seed to this value. Notice that if the random seed has not be initialised by R so far, the function issues a call to runif(1) to perform this initialisation (as is done in stats::simulate()).

It seed is an integer, it is used in a call to set.seed() before the simulation takes place. The integer is saved as a seed attribute in the return value. The integer seed is completed by an attribute kind which contains the value as.list([RNGkind()]) exactly as with stats::simulate(). The random generator state is reset to its original value at the end of the call.

See also

stats::simulate() for details and examples on the random number generator setting

Examples

pc <- powerconsumption[powerconsumption$week == 5, ]
dts <- cut(pc$active_power, breaks = c(0, quantile(pc$active_power, probs = c(0.5, 1))))
dts_cov <- data.frame(day_night = (pc$hour >= 7 & pc$hour <= 17))
m_cov <- covlmc(dts, dts_cov, min_size = 5)
# new week with day light from 6:00 to 18:00
new_cov <- data.frame(day_night = rep(c(rep(FALSE, 59), rep(TRUE, 121), rep(FALSE, 60)), times = 7))
new_dts <- simulate(m_cov, nrow(new_cov), seed = 0, covariate = new_cov)
new_dts_2 <- simulate(m_cov, nrow(new_cov), seed = 0, covariate = new_cov, init = dts[1:10])