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)
if (FALSE) {
# 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::summarise(value = my_features(value),
feature=c("entropy","acf1", "acf2"),
.groups = "drop")
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))}
Run the code above in your browser using DataLab