Reputation: 281
I have to analyze data and find instances that have higher values repeating through same intervals. Example:
I am trying to use spectrum function but it gives me weird result.
Here is my example data, I inserted outliers every 1 hour into it.
library(dplyr)
library(lubridate)
library(ggplot2)
set.seed(900)
data1 <-
data.frame(
datetime = seq.POSIXt(as.POSIXct("2020-12-26 10:00:00"), as.POSIXct("2020-12-26 10:00:00") + 15*50001, "15 sec"),
Value = sample(1:10, 50002, replace = T),
Instance = "A"
)
data1.1 <- data.frame(
datetime= seq.POSIXt(as.POSIXct("2020-12-26 10:00:00"), as.POSIXct("2020-12-26 10:00:00") + 15*50001, "hour"),
Value = sample(10:100, 209, replace = T),
Instance = "A"
)
data1 <- rbind(data1, data1.1) %>% group_by(datetime, Instance) %>% summarise(Value = max(Value)) %>% ungroup()
ggplot(data1, aes(x=datetime, y=Value, color = Instance)) +
geom_point()
spect <- spectrum(data1$Value, log="no", spans=c(5,5), plot=FALSE)
delta <- 1/4
specx <- spect$freq/delta
specy <- 2*spect$spec
plot(specx, specy, xlab="Period (minutes)", ylab="Spectral Density", type="l")
I expected to get spectral graph where spectral density will show me 60 minutes. But that's what I got:
How to find peaks repeating intervals (60 minutes in my example)?
Upvotes: 0
Views: 216