Skip to contents

Computes cross-correlation function (CCF) between two stations for a given variable, identifying the optimal lag for prediction.

Usage

cross_correlation_stations(
  data,
  station1,
  station2,
  variable = "wave_height",
  max_lag = 48
)

Arguments

data

Data frame with columns: time, station_id, and the variable

station1, station2

Station IDs to compare

variable

Variable to analyze (default: "wave_height")

max_lag

Maximum lag in hours to test (default: 48)

Value

List with:

  • ccf: cross-correlation values at each lag

  • optimal_lag: lag (hours) with maximum correlation

  • max_correlation: correlation at optimal lag

  • lag_hours: vector of lag values

Examples

if (FALSE) { # \dontrun{
data <- data.frame(
  time = rep(seq(as.POSIXct("2024-01-01"), by = "hour", length.out = 100), 2),
  station_id = rep(c("M2", "M3"), each = 100),
  wave_height = c(rnorm(100, 3, 1), rnorm(100, 2.5, 0.8))
)
cross_correlation_stations(data, "M2", "M3")
} # }