Skip to contents

Uses one station to predict another at the optimal lag. Particularly useful for M6 (offshore) predicting coastal stations.

Usage

predict_station_lagged(
  data,
  predictor_station,
  target_station,
  variable = "wave_height",
  lag_hours = NULL
)

Arguments

data

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

predictor_station

Station to use as predictor (e.g., "M6")

target_station

Station to predict (e.g., "M2")

variable

Variable to predict (default: "wave_height")

lag_hours

Lag in hours (positive = predictor leads target)

Value

List with:

  • model: lm object

  • r_squared: R-squared of prediction

  • rmse: Root mean squared error

  • predictions: data frame with actual and predicted values

Examples

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