0

I have to analyze data and find instances that have higher values repeating through same intervals. Example:

enter image description here

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:

enter image description here

How to find peaks repeating intervals (60 minutes in my example)?

Maxim
  • 301
  • 1
  • 9
  • You might take a look at `tsmp` pkg as an approach. As to your plot, isn't length(Values) something like 50k while you plot 100? – Chris Aug 05 '21 at 15:16
  • Thanks. I corrected my code. But result is still weird: x axis is only 0 to 2. I expected to see 60+ there. – Maxim Aug 05 '21 at 15:26

0 Answers0