# NOT RUN {
#--- Simulate a time warped version of a time series x
set.seed(123)
x <- cumsum(rnorm(100))
x_warp <- simulate_timewarp(x, stretch = 0.1, compress = 0.2, seed = 123)
plot(x, type = "l")
lines(x_warp, col = "red")
#--- Simulate a time warp of a multivariate time series
y <- matrix(cumsum(rnorm(10^3)), ncol = 2)
y_warp <- simulate_timewarp(y, stretch = 0.1, compress = 0.2, seed = 123)
plot(y[,1], type = "l")
lines(y_warp[,1], col = "red")
#--- Stretchings means to insert at new values at randomly
# selected points of time. Next the new values are set as constant NA,
# and the points of time simulated uniformly:
y_warp <- simulate_timewarp(y, stretch = 0.2, p_number = "runif", p_index = "runif",
stretch_method = insert_const,
const = NA)
matplot(y_warp, type = "l")
# insert NA and simulate the points of time by log normal
y_warp <- simulate_timewarp(y, stretch = 0.2, p_number = "rlnorm",
p_number_list = list(meanlog = 0, sdlog = 1),
stretch_method = insert_const,
const = NA)
matplot(y_warp, type = "l")
# insert linear interpolation
y_warp <- simulate_timewarp(y, stretch = 0.2, p_number = "rlnorm",
stretch_method = insert_linear_interp)
matplot(y_warp, type = "l")
# insert random walk with gaussian noise
y_warp <- simulate_timewarp(y, stretch = 0.2, p_number = "rlnorm",
stretch_method = insert_norm,
sd = 1, mean = 0)
matplot(y_warp, type = "l")
# insert constant, only 1 observation per random index
y_warp <- simulate_timewarp(y, stretch = 0.2, p_number = "runif", p_index = "runif",
p_number_list = list(min = 1, max = 1),
stretch_method = insert_const)
matplot(y_warp, type = "l")
# insert by customized insert function
my_stretch_method <- function(x, ix, N, from, to){
c(x[1:ix],
sin(seq(from = from, to = to, length.out = N)) + x[ix],
x[(ix + 1):length(x)])
}
y_warp <- simulate_timewarp(y, stretch = 0.5, p_number = "rlnorm",
stretch_method = my_stretch_method,
from = 0, to = 4 * pi)
matplot(y_warp, type = "l")
# }
Run the code above in your browser using DataLab