knitr::opts_chunk$set( collapse = TRUE, comment = "#>", warning = FALSE, message = TRUE, out.width = "100%" )
laggedcor
needs two time-series data and their corresponding time.
x: time-series 1. numeric vector.
y: time-series 2. numeric vector.
time1: time for x.
time2: time for y.
The demo data can be from laggedcor
.
library(laggedcor) data("step_data", package = "laggedcor") data("heart_data", package = "laggedcor") head(step_data) head(heart_data)
time_plot(x = step_data$step, time = step_data$time)
time_plot(x = heart_data$heart, time = heart_data$time)
Then we calculate the lagged correlations between step and heart rate.
dim(step_data) dim(heart_data)
The time-series data with less number of time point should be set as x
.
x = step_data$step time1 = step_data$time y = heart_data$heart time2 = heart_data$time
result = calculate_lagged_correlation(x = x, y = y, time1 = time1, time2 = time2, time_tol = 0.2, step = 2 / 60, min_matched_sample = 10, threads = 5, cor_method = "spearman")
The parameters of calculate_lagged_correlation
;
x
: time-series data 1.
y
: time-series data 2.
time1
: time-series data time 1.
time2
: time-series data time 2.
time_tol
: time tolerance for time shift. Unit is hour. 0.2 means ± 0.2 hour.
step
: step means the matching window, unit is hour.
min_matched_sample
: Minimum for match sample number.
threads
: thread number.
cor_method
: spearman or pearson.
result
We can see that the index of max correlation is 11 and index of global correlation is 12, means that the max correlation is achieved from a shifted time.
extract_max_cor(object = result) extract_global_cor(object = result)
We can see that when the shift time is "(-1.5,-0.5]", we get the max correaltion: 0.58. This means x (step) changes before y (heart rate).
extract_all_cor(result)
extract_all_cor_p(result)
extract_shift_time(result, numeric = TRUE) extract_shift_time(result, numeric = FALSE)
evaluate_lagged_cor(object = result, plot = TRUE)
lagged_scatter_plot(object = result, hex = TRUE, which = "global") lagged_scatter_plot(object = result, hex = TRUE, which = "max")
lagged_alignment_plot(object = result, which = "global", x_limit = c(1,50000))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.