View source: R/9-evaluate_lagged_cor.R
evaluate_lagged_cor | R Documentation |
This function takes a lagged correlation object, fits a loess curve to the correlation data, normalizes the data to ensure all correlations are on the same side of zero, fits peaks to the normalized correlation data, computes a score based on the Spearman correlation between the fitted peaks and the actual data, and optionally generates a plot.
evaluate_lagged_cor(object, plot = TRUE)
object |
An object of class |
plot |
Logical; if |
The function starts by checking if the input object is NULL
. If it is, it returns a score
of 0 and NULL
for the plot. If the object is not NULL
, the function proceeds to clean
and prepare the shift times using stringr
and purrr
. Then, it fits a loess model to
the correlation data and uses this to normalize the data and identify peaks using a custom
fitpeaks
function. It calculates the score of the fit using Spearman's method. The peak with
the highest absolute correlation determines the score, and the function distinguishes between
positive and negative correlations. The function uses ggplot2
for plotting if required.
A list containing the following components:
score
: A numeric value representing the Spearman correlation score
of the fit, where higher values indicate a better fit.
plot
: A ggplot object showing the actual versus fitted correlation data
if plot
is TRUE
, otherwise NULL
.
This function depends on several external packages (ggplot2
, dplyr
, stringr
, purrr
) as
well as a custom fitpeaks
function that must be defined elsewhere in the user's environment.
data("object", package = "laggedcor")
result =
evaluate_lagged_cor(object = object, plot = TRUE)
result$score
result$plot
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.