Use cross-correlation to estimate the delay between an input time series and (rises in) the corresponding output time series.
estimateDelay(
DATA = data.frame(U = , Q = ),
rises = TRUE,
lag.max = hydromad.getOption("max.delay"),
n.estimates = 1,
negative.ok = FALSE,
na.action = na.exclude,
plot = FALSE,
main = NULL,
...
)
a ts
-like object with named components:
input (forcing) time series.
output (response) time series.
use only rises in the output to estimate delay.
largest delay (in time steps) to consider.
number of estimates of delay to produce.
to allow negative delay times to be considered.
handler for missing values. The default removes leading
and trailing NAs only. Use na.exclude
to remove all NAs, but the
result will not be a valid autocorrelation sequence.
plot the cross-correlation function.
title for plot.
The estimated delay as an integer number of time steps. If
n.estimates > 1
, that number of integer delays, ordered by the CCF.
The estimated delay is the one maximising the cross-correlation function.
set.seed(1)
x <- ts(pmax(0, rgamma(200, shape = 0.1, scale = 20) - 5))
## simulate error as multiplicative uniform random
y <- x * runif(200, min = 0.5, max = 1.5)
## and resample 10 percent of time steps
ii <- sample(seq_along(y), 20)
y[ii] <- rev(y[ii])
## apply recursive filter and lag
y <- filter(y, 0.8, method = "r")
y <- lag(y, -2) # true delay is 2
plot(ts.union(y, x))
## based on cross correlation function:
estimateDelay(ts.union(y, x), rises = FALSE, plot = TRUE)
#> [1] 2
## based on ccf with flow rises only:
estimateDelay(ts.union(y, x), plot = TRUE)
#> [1] 2