Here is my toy time series data:
library(tidyverse); library(tsibble); library(feasts)
df <- tibble::tribble(
~date, ~A, ~B, ~C,
"1/31/2010", NA, 0.017, NA,
"2/28/2010", NA, 0.027, NA,
"3/31/2010", NA, 0.003, 0.003,
"4/30/2010", -0.022, 0.018, 0.018,
"5/31/2010", -0.036, 0.02, 0.02,
"6/30/2010", -0.046, 0.023, 0.023,
"7/31/2010", NA, 0.027, 0.027,
"8/31/2010", -0.022, 0.008, 0.008,
"9/30/2010", 0.059, -0.003, -0.003,
"10/31/2010", 0.024, 0.058, 0.058,
"11/30/2010", NA, 0.023, NA,
"12/31/2010", NA, 0.014, NA
)
I want to calculate autocorrelation (acf) of multiple time series. Ignoring the imputation part, I need to:
- Remove the variables with inbetween NAs (not those at the start and end of the time series) like NA on 7/31/2010 for A. So in this case, remove variable A.
- Calculate the auto correlations potentially using ACF function from feasts package on B and C.
I started here and got stuck:
df %>%
mutate(date = mdy(date)) %>%
pivot_longer(cols = -date) %>%
as_tsibble(key = name, index = date) %>%
ACF()
The expected output would have autocorrelations of every possible series by lag. Like B will have 10-11 values for 10 lags and same for series B