| Title: | Generating Time Series with Diverse and Controllable Characteristics |
|---|---|
| Description: | Generates synthetic time series based on various univariate time series models including MAR and ARIMA processes. Kang, Y., Hyndman, R.J., Li, F.(2020) <doi:10.1002/sam.11461>. |
| Authors: | Yanfei Kang [aut] (ORCID: <https://orcid.org/0000-0001-8769-6650>), Feng Li [aut, cre] (ORCID: <https://orcid.org/0000-0002-4248-9778>), Rob Hyndman [aut] (ORCID: <https://orcid.org/0000-0002-2140-5352>), Mitchell O'Hara-Wild [ctb] (ORCID: <https://orcid.org/0000-0001-6729-7695>), Bocong Zhao [ctb] (ORCID: <https://orcid.org/0000-0001-8434-9047>) |
| Maintainer: | Feng Li <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.8 |
| Built: | 2026-05-14 04:54:27 UTC |
| Source: | https://github.com/ykang/gratis |
Launch a local Shiny application for generating time series with controllable features.
app_gratis()app_gratis()
Called for its side effect of launching a Shiny application. Returns
the value from runApp().
## Not run: app_gratis() ## End(Not run)## Not run: app_gratis() ## End(Not run)
Construct a Gaussian ARIMA model that can be used with
simulate.Arima() or generate.Arima().
Any omitted argument is randomly selected from the supported parameter space.
arima_model( frequency = 1, p = NULL, d = NULL, q = NULL, P = NULL, D = NULL, Q = NULL, constant = NULL, phi = NULL, theta = NULL, Phi = NULL, Theta = NULL, sigma = NULL )arima_model( frequency = 1, p = NULL, d = NULL, q = NULL, P = NULL, D = NULL, Q = NULL, constant = NULL, phi = NULL, theta = NULL, Phi = NULL, Theta = NULL, sigma = NULL )
frequency |
The length of the seasonal period (e.g., 12 for monthly data). |
p |
Non-seasonal autoregressive order. |
d |
Non-seasonal differencing order. |
q |
Non-seasonal moving-average order. |
P |
Seasonal autoregressive order. |
D |
Seasonal differencing order. |
Q |
Seasonal moving-average order. |
constant |
Intercept term. |
phi |
A numeric p-vector containing the AR parameters. |
theta |
A numeric q-vector containing the MA parameters. |
Phi |
A numeric P-vector containing the seasonal AR parameters. |
Theta |
A numeric Q-vector containing the seasonal MA parameters. |
sigma |
The standard deviation of the noise. |
When orders are omitted, p and q are sampled from
, P and Q from ,
d from , and D from , with the
restriction . If constant is omitted, it is sampled
from unless , in which case it is set to zero.
AR and MA parameters are sampled so the stationary and invertible parts of
the process are valid, and sigma is sampled from .
An Arima object compatible with the forecast package's
simulation methods.
Rob J Hyndman
# An AR(2) model with random parameters model1 <- arima_model(p = 2, d = 0, q = 0) # An AR(2) model with specific parameters model2 <- arima_model(p = 2, d = 0, q = 0, phi = c(1.34, -0.64), sigma = 15) # Seasonal ARIMA model with randomly selected parameters model3 <- arima_model(frequency = 4) # Simulate from each model and plot the results plot(simulate(model1, 100)) plot(simulate(model2, 100)) plot(simulate(model3, 100))# An AR(2) model with random parameters model1 <- arima_model(p = 2, d = 0, q = 0) # An AR(2) model with specific parameters model2 <- arima_model(p = 2, d = 0, q = 0, phi = c(1.34, -0.64), sigma = 15) # Seasonal ARIMA model with randomly selected parameters model3 <- arima_model(frequency = 4) # Simulate from each model and plot the results plot(simulate(model1, 100)) plot(simulate(model2, 100)) plot(simulate(model3, 100))
Construct an ETS state space model that can be used with
simulate.ets() or generate.ets().
Any omitted argument is randomly selected from the supported parameter space.
ets_model( frequency = 1, error = NULL, trend = NULL, seasonal = NULL, alpha = NULL, beta = NULL, gamma = NULL, phi = NULL, level = NULL, slope = NULL, season = NULL, damped = NULL, sigma = NULL )ets_model( frequency = 1, error = NULL, trend = NULL, seasonal = NULL, alpha = NULL, beta = NULL, gamma = NULL, phi = NULL, level = NULL, slope = NULL, season = NULL, damped = NULL, sigma = NULL )
frequency |
The length of the seasonal period (e.g., 12 for monthly data). |
error |
Character string specifying the error component: |
trend |
Character string specifying the trend component: |
seasonal |
Character string specifying the seasonal component:
|
alpha |
Smoothing parameter for the level. |
beta |
Smoothing parameter for the trend. |
gamma |
Smoothing parameter for seasonality. |
phi |
Damping parameter. |
level |
Initial level |
slope |
Initial slope |
season |
Numeric vector of initial seasonal states
|
damped |
Logical value indicating whether an additive trend is damped. |
sigma |
The standard deviation of the noise. |
The error component is sampled from "A" and "M", the trend
component from "N" and "A", and the seasonal component from
"N", "A", and "M" when frequency > 1. Smoothing
parameters are sampled until they satisfy the ETS admissibility conditions.
The innovation variance is sampled from for additive errors and
from for multiplicative errors. Initial states are sampled
from ranges appropriate to the selected components.
An ets object compatible with the forecast package's
simulation methods.
Rob J Hyndman
# An ETS(A,A,N) model with random parameters model1 <- ets_model(error = "A", trend = "A", seasonal = "N") # An ETS(A,A,N) model with specific parameters model2 <- ets_model( error = "A", trend = "A", seasonal = "N", alpha = 0.3, beta = 0.2, level = 0, slope = 1, sigma = 2 ) # A quarterly seasonal ETS model with random admissible parameters model3 <- ets_model(error = "A", trend = "N", seasonal = "A", frequency = 4) # Simulate from each model and plot the results plot(simulate(model1, 100)) plot(simulate(model2, 100)) plot(simulate(model3, 100))# An ETS(A,A,N) model with random parameters model1 <- ets_model(error = "A", trend = "A", seasonal = "N") # An ETS(A,A,N) model with specific parameters model2 <- ets_model( error = "A", trend = "A", seasonal = "N", alpha = 0.3, beta = 0.2, level = 0, slope = 1, sigma = 2 ) # A quarterly seasonal ETS model with random admissible parameters model3 <- ets_model(error = "A", trend = "N", seasonal = "A", frequency = 4) # Simulate from each model and plot the results plot(simulate(model1, 100)) plot(simulate(model2, 100)) plot(simulate(model3, 100))
This function is deprecated. Use mar_model() with
generate.mar() or simulate.mar() instead.
generate_msts( seasonal.periods = c(7, 365), n = 800, nComp = NULL, output_format = "list" )generate_msts( seasonal.periods = c(7, 365), n = 800, nComp = NULL, output_format = "list" )
seasonal.periods |
Numeric vector of seasonal periods. |
n |
Length of the generated series. |
nComp |
Number of mixture components. If |
output_format |
Output format: |
A multiple-seasonal time series when output_format = "list",
or a tsibble when output_format = "tsibble".
x <- generate_msts(seasonal.periods = c(7, 365), n = 800, nComp = 2, output_format = "list") forecast::autoplot(x)x <- generate_msts(seasonal.periods = c(7, 365), n = 800, nComp = 2, output_format = "list") forecast::autoplot(x)
This function is deprecated. Use mar_model() with
generate.mar() or simulate.mar() instead.
generate_ts(n.ts = 1, freq = 1, nComp = NULL, n = 120, output_format = "list")generate_ts(n.ts = 1, freq = 1, nComp = NULL, n = 120, output_format = "list")
n.ts |
Number of time series to generate. |
freq |
Seasonal period of the generated series. |
nComp |
Number of mixture components. If |
n |
Length of each generated series. |
output_format |
Output format: |
When output_format = "list", a list containing generated time
series and the parameters used for each series. When
output_format = "tsibble", a list of tsibbles.
Yanfei Kang and Feng Li
Wong, CS & WK Li (2000).
x <- generate_ts(n.ts = 2, freq = 12, nComp = 2, n = 120) x$N1$pars forecast::autoplot(x$N1$x)x <- generate_ts(n.ts = 2, freq = 12, nComp = 2, n = 120) x$N1$pars forecast::autoplot(x$N1$x)
This function is deprecated. Use generate_target() instead.
generate_ts_with_target( n, ts.length, freq, seasonal, features, selected.features, target, parallel = TRUE, output_format = "list" )generate_ts_with_target( n, ts.length, freq, seasonal, features, selected.features, target, parallel = TRUE, output_format = "list" )
n |
Number of time series to generate. |
ts.length |
Length of each generated time series. |
freq |
Seasonal frequency, or seasonal periods for multiple-seasonal data. |
seasonal |
Integer seasonality flag: 0 for non-seasonal data, 1 for single-seasonal data, and 2 for multiple-seasonal data. |
features |
Character vector of feature function names passed to
|
selected.features |
Character vector naming the features to match. |
target |
Numeric vector of target feature values in the same order as
|
parallel |
Logical value or parallel backend specification indicating whether the genetic algorithm should evaluate candidates in parallel. |
output_format |
Output format: |
Generated time series in the requested output_format.
Yanfei Kang
## Not run: library(tsfeatures) x <- generate_ts_with_target( n = 1, ts.length = 60, freq = 1, seasonal = 0, features = c("entropy", "stl_features"), selected.features = c("entropy", "trend"), target = c(0.6, 0.9), parallel = FALSE ) forecast::autoplot(x) ## End(Not run)## Not run: library(tsfeatures) x <- generate_ts_with_target( n = 1, ts.length = 60, freq = 1, seasonal = 0, features = c("entropy", "stl_features"), selected.features = c("entropy", "trend"), target = c(0.6, 0.9), parallel = FALSE ) forecast::autoplot(x) ## End(Not run)
Generate one or more synthetic time series from a fitted or specified model.
Methods are provided for mar_model() objects, ETS objects from
ets_model(), and ARIMA objects from arima_model().
Each series is produced by repeatedly calling the corresponding
simulate() method.
## S3 method for class 'mar' generate(x, length = 100, nseries = 10, ...) ## S3 method for class 'ets' generate(x, length = 100, nseries = 10, ...) ## S3 method for class 'Arima' generate(x, length = 100, nseries = 10, ...)## S3 method for class 'mar' generate(x, length = 100, nseries = 10, ...) ## S3 method for class 'ets' generate(x, length = 100, nseries = 10, ...) ## S3 method for class 'Arima' generate(x, length = 100, nseries = 10, ...)
x |
A model object of class |
length |
Length of each series to generate. |
nseries |
Number of series to generate. |
... |
Other arguments passed to the relevant |
The generated series are returned as a tsibble. The index is inferred from the model frequency or seasonal periods where possible, with special handling for common weekly, hourly, half-hourly, quarter-hourly, and minute data.
A tsibble containing the generated values. For multiple series the
output has length * nseries rows and includes a key column identifying
each series.
Rob J Hyndman
Feng Li, Mattias Villani, and Robert Kohn. (2010). Flexible Modeling of Conditional Distributions using Smooth Mixtures of Asymmetric Student T Densities, Journal of Statistical Planning and Inference, 140(12), pp. 3638-3654.
mar_model, arima_model,
ets_model, simulate.mar
# MAR model with constant variances phi <- cbind(c(0.8, 0), c(0.6, 0.3)) weights <- c(0.8, 0.2) model1 <- mar_model(phi = phi, sigmas = c(1, 2), weights = weights) generate(model1, nseries = 5) # MAR model for hourly data with daily and weekly periods hourly_model <- mar_model(seasonal_periods = c(24, 24*7)) generate(hourly_model, length = 24 * 7, nseries = 2) # ARIMA and ETS models also work generate(arima_model(p = 1, d = 0, q = 0, phi = 0.5), length = 20, nseries = 2) generate(ets_model(error = "A", trend = "N", seasonal = "N"), length = 20, nseries = 2)# MAR model with constant variances phi <- cbind(c(0.8, 0), c(0.6, 0.3)) weights <- c(0.8, 0.2) model1 <- mar_model(phi = phi, sigmas = c(1, 2), weights = weights) generate(model1, nseries = 5) # MAR model for hourly data with daily and weekly periods hourly_model <- mar_model(seasonal_periods = c(24, 24*7)) generate(hourly_model, length = 24 * 7, nseries = 2) # ARIMA and ETS models also work generate(arima_model(p = 1, d = 0, q = 0, phi = 0.5), length = 20, nseries = 2) generate(ets_model(error = "A", trend = "N", seasonal = "N"), length = 20, nseries = 2)
Construct a mixture autoregressive (MAR) model made up of Gaussian
ARIMA components. The resulting mar object can
be passed to simulate.mar() to simulate one series or to
generate.mar() to generate a tsibble of several series.
mar_model( k = NULL, p = NULL, d = NULL, phi = NULL, P = NULL, D = NULL, Phi = NULL, constants = NULL, sigmas = NULL, weights = NULL, seasonal_periods = 1L )mar_model( k = NULL, p = NULL, d = NULL, phi = NULL, P = NULL, D = NULL, Phi = NULL, constants = NULL, sigmas = NULL, weights = NULL, seasonal_periods = 1L )
k |
Number of mixture components. |
p |
Non-negative integer vector giving the non-seasonal AR orders
|
d |
Non-negative integer vector giving the non-seasonal differencing
orders |
phi |
Numeric matrix of non-seasonal AR parameters. Column |
P |
Non-negative integer vector giving the seasonal AR orders
|
D |
Non-negative integer vector giving the seasonal differencing orders
|
Phi |
Numeric matrix of seasonal AR parameters. Column |
constants |
Numeric vector of length |
sigmas |
Numeric vector of length |
weights |
Positive numeric vector of length |
seasonal_periods |
Scalar seasonal period applied to every component, or
a numeric vector of length |
Component has the form
and is selected with probability . Here is the
backshift operator, is the seasonal period, is a
standard normal variate, and and are the
non-seasonal and seasonal autoregressive polynomials.
Any missing model argument is randomly selected. Randomly selected
non-seasonal AR orders are sampled from ,
non-seasonal differences from , seasonal AR orders from
, and seasonal differences from . AR parameters
are sampled from the stationary region, constants from , sigmas
from , and mixture weights from before normalization.
If k is omitted, the number of components is sampled from
, unless it can be inferred from another argument.
An object of class mar. The object stores the component orders,
coefficients, constants, sigmas, normalized weights, seasonal periods, and
the expanded AR recursion coefficients used by simulate.mar().
Rob J Hyndman
# Quarterly MAR model with randomly selected parameters model1 <- mar_model(seasonal_periods = 4) # Daily MAR model with randomly selected parameters model2 <- mar_model(seasonal_periods = c(7, 365)) # MAR model with constant variances and user-specified coefficients phi <- cbind(c(0.8, 0), c(0.6, 0.3)) weights <- c(0.8, 0.2) model3 <- mar_model(phi = phi, d = 0, sigmas = c(1, 2), weights = weights) # MAR model with heteroskedastic errors if (requireNamespace("fGarch", quietly = TRUE)) { sigmas_spec <- list( fGarch::garchSpec(model = list(alpha = c(0.05, 0.06))), fGarch::garchSpec(model = list(alpha = c(0.05, 0.05))) ) model4 <- mar_model(phi = phi, sigmas = sigmas_spec, weights = weights) }# Quarterly MAR model with randomly selected parameters model1 <- mar_model(seasonal_periods = 4) # Daily MAR model with randomly selected parameters model2 <- mar_model(seasonal_periods = c(7, 365)) # MAR model with constant variances and user-specified coefficients phi <- cbind(c(0.8, 0), c(0.6, 0.3)) weights <- c(0.8, 0.2) model3 <- mar_model(phi = phi, d = 0, sigmas = c(1, 2), weights = weights) # MAR model with heteroskedastic errors if (requireNamespace("fGarch", quietly = TRUE)) { sigmas_spec <- list( fGarch::garchSpec(model = list(alpha = c(0.05, 0.06))), fGarch::garchSpec(model = list(alpha = c(0.05, 0.05))) ) model4 <- mar_model(phi = phi, sigmas = sigmas_spec, weights = weights) }
Convert SARIMA coefficients into the equivalent infinite-order AR recursion
coefficients, truncated after the last coefficient whose absolute value is
greater than tol. These coefficients are used internally by
mar_model() and are also exported for users who need the same
conversion.
pi_coefficients( ar = 0, d = 0L, ma = 0, sar = 0, D = 0L, sma = 0, m = 1L, tol = 1e-07 )pi_coefficients( ar = 0, d = 0L, ma = 0, sar = 0, D = 0L, sma = 0, m = 1L, tol = 1e-07 )
ar |
Non-seasonal AR coefficients. |
d |
Number of non-seasonal differences. |
ma |
Non-seasonal MA coefficients. |
sar |
Seasonal AR coefficients. |
D |
Number of seasonal differences. |
sma |
Seasonal MA coefficients. |
m |
Seasonal period. |
tol |
Tolerance used for truncation. Coefficients are returned through
the last position whose absolute value exceeds |
A numeric vector of AR recursion coefficients.
Rob J Hyndman
pi_coefficients(ar = 0.8) pi_coefficients(ar = c(0.4, -0.2), d = 1) pi_coefficients(ar = 0.3, sar = 0.2, D = 1, m = 12)pi_coefficients(ar = 0.8) pi_coefficients(ar = c(0.4, -0.2), d = 1) pi_coefficients(ar = 0.3, sar = 0.2, D = 1, m = 12)
Draw random values from a finite mixture of multivariate normal
distributions, each with dimension . For univariate mixtures,
means and sigmas may be supplied as vectors.
rmixnorm(n, means, sigmas, weights)rmixnorm(n, means, sigmas, weights)
n |
Number of observations to generate. |
means |
A |
sigmas |
A |
weights |
Numeric vector of component probabilities. Values are used as sampling probabilities for the mixture components. |
An matrix of generated data, or a numeric vector
when .
Feng Li, Central University of Finance and Economics.
Villani et al 2009.
out <- rmixnorm( n = 1000, means = c(-5, 0, 5), sigmas = c(1, 1, 3), weights = c(0.3, 0.4, 0.3) ) hist(out, breaks = 100, freq = FALSE)out <- rmixnorm( n = 1000, means = c(-5, 0, 5), sigmas = c(1, 1, 3), weights = c(0.3, 0.4, 0.3) ) hist(out, breaks = 100, freq = FALSE)
Simulate a univariate process whose conditional distribution is a finite mixture of Gaussian distributions. The conditional mean of each component is an autoregressive process with its own parameter vector.
rmixnorm_ts(n, means.ar.par.list, sigmas.list, weights, yinit = 0)rmixnorm_ts(n, means.ar.par.list, sigmas.list, weights, yinit = 0)
n |
Number of observations to generate. |
means.ar.par.list |
List of component AR parameter vectors. The first element of each vector is the intercept, followed by lag coefficients. |
sigmas.list |
List of component variance or volatility vectors, each of
length |
weights |
Numeric vector of component probabilities. |
yinit |
Initial value used to seed the recursion. |
A ts object of length n.
Feng Li, Central University of Finance and Economics.
Feng Li, Mattias Villani, and Robert Kohn. (2010). Flexible Modeling of Conditional Distributions using Smooth Mixtures of Asymmetric Student T Densities, Journal of Statistical Planning and Inference, 140(12), pp. 3638-3654.
if (requireNamespace("fGarch", quietly = TRUE)) { n <- 1000 means.ar.par.list <- list(c(0, 0.8), c(0, 0.6, 0.3)) sigmas.spec <- list( fGarch::garchSpec(model = list(alpha = c(0.05, 0.06)), cond.dist = "norm"), fGarch::garchSpec(model = list(alpha = c(0.05, 0.05)), cond.dist = "norm") ) sigmas.list <- lapply( lapply(sigmas.spec, fGarch::garchSim, extended = TRUE, n = n), function(x) x$sigma ) weights <- c(0.8, 0.2) y <- rmixnorm_ts( n = n, means.ar.par.list = means.ar.par.list, sigmas.list = sigmas.list, weights = weights ) plot(y) }if (requireNamespace("fGarch", quietly = TRUE)) { n <- 1000 means.ar.par.list <- list(c(0, 0.8), c(0, 0.6, 0.3)) sigmas.spec <- list( fGarch::garchSpec(model = list(alpha = c(0.05, 0.06)), cond.dist = "norm"), fGarch::garchSpec(model = list(alpha = c(0.05, 0.05)), cond.dist = "norm") ) sigmas.list <- lapply( lapply(sigmas.spec, fGarch::garchSim, extended = TRUE, n = n), function(x) x$sigma ) weights <- c(0.8, 0.2) y <- rmixnorm_ts( n = n, means.ar.par.list = means.ar.par.list, sigmas.list = sigmas.list, weights = weights ) plot(y) }
Search for MAR model parameters that produce time series with feature values
close to a user-specified target. simulate_target() returns one
generated series, while generate_target() repeats the search to return
several generated series in a tsibble.
simulate_target( length = 100, seasonal_periods = 1, feature_function, target, k = ifelse(length(seasonal_periods) == 1, 3, length(seasonal_periods)), tolerance = 0.05, trace = FALSE, parallel = FALSE ) generate_target( length = 100, nseries = 10, seasonal_periods = 1, feature_function, target, k = ifelse(length(seasonal_periods) == 1, 3, length(seasonal_periods)), tolerance = 0.05, trace = FALSE, parallel = FALSE )simulate_target( length = 100, seasonal_periods = 1, feature_function, target, k = ifelse(length(seasonal_periods) == 1, 3, length(seasonal_periods)), tolerance = 0.05, trace = FALSE, parallel = FALSE ) generate_target( length = 100, nseries = 10, seasonal_periods = 1, feature_function, target, k = ifelse(length(seasonal_periods) == 1, 3, length(seasonal_periods)), tolerance = 0.05, trace = FALSE, parallel = FALSE )
length |
Length of each generated time series. |
seasonal_periods |
Scalar seasonal period, or a numeric vector of seasonal periods for multiple-seasonal data. |
feature_function |
Function that accepts a time series and returns a numeric vector of features. |
target |
Numeric vector of target feature values. It must have the same
length and order as the vector returned by |
k |
Number of MAR components to use. The default is 3 for single-seasonal or non-seasonal data, and the number of seasonal periods for multiple-seasonal data. |
tolerance |
Average absolute feature tolerance. Larger values usually return faster but less precise results. |
trace |
Logical value indicating whether to show genetic algorithm progress. |
parallel |
Logical value or parallel backend specification passed to the
genetic algorithm. Use |
nseries |
Number of series to generate |
A genetic algorithm evaluates candidate MAR parameter vectors by simulating a
series, scaling it, computing feature_function(), and comparing those
features to target. Because each candidate series is scaled before
feature evaluation, the target features should not depend on the absolute
scale of the series.
simulate_target() returns a msts
object of length length. generate_target() returns a tsibble
containing nseries generated series.
Yanfei Kang and Rob J Hyndman
## Not run: set.seed(1) library(tsfeatures) my_features <- function(y) { c(entropy(y), acf = acf(y, plot = FALSE)$acf[2:3, 1, 1]) } # Simulate a ts with specified target features y <- simulate_target( length = 60, feature_function = my_features, target = c(0.5, 0.9, 0.8) ) my_features(y) plot(y) # Generate a tsibble with specified target features df <- generate_target( length = 60, feature_function = my_features, target = c(0.5, 0.9, 0.8) ) df %>% as_tibble() %>% group_by(key) %>% dplyr::reframe( value = my_features(value), feature=c("entropy","acf1", "acf2") ) autoplot(df) # Simulate time series similar to an existing series my_features <- function(y) { c(stl_features(y)[c("trend", "seasonal_strength", "peak", "trough")]) } y <- simulate_target( length = length(USAccDeaths), seasonal_periods = frequency(USAccDeaths), feature_function = my_features, target = my_features(USAccDeaths) ) tsp(y) <- tsp(USAccDeaths) plot(cbind(USAccDeaths, y)) cbind(my_features(USAccDeaths), my_features(y)) ## End(Not run)## Not run: set.seed(1) library(tsfeatures) my_features <- function(y) { c(entropy(y), acf = acf(y, plot = FALSE)$acf[2:3, 1, 1]) } # Simulate a ts with specified target features y <- simulate_target( length = 60, feature_function = my_features, target = c(0.5, 0.9, 0.8) ) my_features(y) plot(y) # Generate a tsibble with specified target features df <- generate_target( length = 60, feature_function = my_features, target = c(0.5, 0.9, 0.8) ) df %>% as_tibble() %>% group_by(key) %>% dplyr::reframe( value = my_features(value), feature=c("entropy","acf1", "acf2") ) autoplot(df) # Simulate time series similar to an existing series my_features <- function(y) { c(stl_features(y)[c("trend", "seasonal_strength", "peak", "trough")]) } y <- simulate_target( length = length(USAccDeaths), seasonal_periods = frequency(USAccDeaths), feature_function = my_features, target = my_features(USAccDeaths) ) tsp(y) <- tsp(USAccDeaths) plot(cbind(USAccDeaths, y)) cbind(my_features(USAccDeaths), my_features(y)) ## End(Not run)
Simulate one random sample path from a mixture of Gaussian autoregressive
components created by mar_model(). At each time point, a
component is sampled according to the model weights, that component's
conditional mean and innovation variance are used, and the resulting series
is returned after discarding a burn-in period.
## S3 method for class 'mar' simulate(object, nsim = 100, seed = NULL, n.start = 100, ...)## S3 method for class 'mar' simulate(object, nsim = 100, seed = NULL, n.start = 100, ...)
object |
A |
nsim |
Length of the generated series. |
seed |
Either |
n.start |
Length of the burn-in period discarded before returning the simulated series. |
... |
Other arguments, not currently used. |
A msts object of length nsim. For
single-seasonal or non-seasonal models this also behaves like a base
ts object.
Rob J Hyndman
Feng Li, Mattias Villani, and Robert Kohn. (2010). Flexible Modeling of Conditional Distributions using Smooth Mixtures of Asymmetric Student T Densities, Journal of Statistical Planning and Inference, 140(12), pp. 3638-3654.
# MAR model with constant variances phi <- cbind(c(0.8, 0), c(0.6, 0.3)) weights <- c(0.8, 0.2) model1 <- mar_model(phi = phi, sigmas = c(1, 2), weights = weights) y <- simulate(model1, 100) plot(y) # MAR model with heteroskedastic errors if (requireNamespace("fGarch", quietly = TRUE)) { sigmas_spec <- list( fGarch::garchSpec(model = list(alpha = c(0.05, 0.06))), fGarch::garchSpec(model = list(alpha = c(0.05, 0.05))) ) model2 <- mar_model(phi = phi, sigmas = sigmas_spec, weights = weights) y <- simulate(model2, 100) plot(y) }# MAR model with constant variances phi <- cbind(c(0.8, 0), c(0.6, 0.3)) weights <- c(0.8, 0.2) model1 <- mar_model(phi = phi, sigmas = c(1, 2), weights = weights) y <- simulate(model1, 100) plot(y) # MAR model with heteroskedastic errors if (requireNamespace("fGarch", quietly = TRUE)) { sigmas_spec <- list( fGarch::garchSpec(model = list(alpha = c(0.05, 0.06))), fGarch::garchSpec(model = list(alpha = c(0.05, 0.05))) ) model2 <- mar_model(phi = phi, sigmas = sigmas_spec, weights = weights) y <- simulate(model2, 100) plot(y) }