how do i format data before applying cross-correlation?

You might find it easier to use tsibble objects like this.

library(tidyverse)
library(lubridate)
library(tsibble)
library(feasts)

link420 <- tibble(
    time = seq(as.POSIXct("2018-01-01 08:00:00"), length=100, by="5 min"),
    diff420 = rnorm(100)
  ) %>%
  as_tsibble(index=time)
link423 <- tibble(
    time = seq(as.POSIXct("2018-01-01 08:00:00"),length=100, by="5 min"),
    diff423 = rnorm(100)
  ) %>%
  as_tsibble(index=time)

inner_join(link420, link423, by = "time") %>%
  CCF(diff420, diff423)
#> # A tsibble: 33 x 2 [5m]
#>      lag     ccf
#>    <lag>   <dbl>
#>  1  -80m  0.0648
#>  2  -75m -0.0651
#>  3  -70m -0.0316
#>  4  -65m  0.0679
#>  5  -60m  0.0635
#>  6  -55m -0.158 
#>  7  -50m  0.0444
#>  8  -45m  0.0497
#>  9  -40m  0.0267
#> 10  -35m -0.0503
#> # … with 23 more rows

Created on 2020-11-02 by the reprex package (v0.3.0)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top