What is the process to obtain the number of local extreme points in a time-series dataset using R?
add a comment
Example code:
# Load packages
library(stats)
# Import and convert data to a time-series object
ts_data <- ts(data, start = c(2010, 1), end = c(2020, 12), frequency = 12)
# Smooth the data
smooth_data <- loess(ts_data ~ time(ts_data))
# Calculate first derivative and change in sign
diff_data <- diff(sign(diff(smooth_data)))
# Count local extreme points
num_extreme_points <- length(which(diff_data < 0))
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-08-21 11:00:00 +0000
Seen: 14 times
Last updated: Oct 15 '22