View source: R/8-calculate_lagged_correlation.R
calculate_lagged_correlation | R Documentation |
This function calculates the lagged correlation between two time series data sets over specified time windows, with the capability to adjust for time tolerance, step size, and the minimum number of matched samples. The function also allows for the use of different correlation methods and parallel processing.
calculate_lagged_correlation(
x,
y,
time1,
time2,
time_tol = 1,
step = 1/60,
min_matched_sample = 10,
progressbar = TRUE,
all_idx = NULL,
threads = 10,
cor_method = c("spearman", "pearson")
)
x |
A numeric vector for the first time series. |
y |
A numeric vector for the second time series. |
time1 |
A numeric vector of timestamps corresponding to |
time2 |
A numeric vector of timestamps corresponding to |
time_tol |
Tolerance for the lag time, in hours (default is 1 hour). |
step |
The step size for the lag window, in hours (default is 1/60 hour, namely 1 min). |
min_matched_sample |
The minimum number of matched samples to consider a valid correlation (default is 10). |
progressbar |
Logical indicating whether to show a progress bar (default is TRUE). |
all_idx |
An optional precomputed index list to speed up calculations. |
threads |
The number of threads to use for parallel processing (default is 10). |
cor_method |
The method for computing correlation: "spearman" or "pearson" (default is "spearman"). |
The function scales the input time series and computes correlations over a range of time lags, handling mismatches in time series lengths by a tolerance window. Parallel processing is implemented to improve performance for large datasets.
An object of class "lagged_cor_result" containing the lagged correlation results, indices, and other relevant data.
Xiaotao Shen shenxt1990@stanford.edu
## Not run:
data("heart_data", package = "laggedcor")
data("step_data", package = "laggedcor")
dim(heart_data)
dim(step_data)
x = step_data$step
time1 = step_data$time
y = heart_data$heart
time2 = heart_data$time
object =
calculate_lagged_correlation(
x = x,
y = y,
time1 = time1,
time2 = time2,
time_tol = 0.1,
step = 1 / 60,
min_matched_sample = 10,
progressbar = TRUE,
threads = 5,
cor_method = "spearman"
)
object
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.