time_series1: A numeric vector which stores the time series of interest in the log scale.
time_series2: A numeric vector which stores the trend proxy time series in the log scale. The length of trend_proxy must be the same as that of time_series1.
possible_lags: A numeric vector specifying all the candidate lags for trend_proxy. The default option is -36:36.
method: A character vector specifying the method used to obtain the lag estimate. "polynomial" uses polynomial approximation, while "cross-correlation" uses cross-correlation.
leave_off: A positive integer specifying the number of observations to be left off when estimating the lag.
estimated_change: A numeric specifying the estimated change in the visitation trend. The default option is 0, implying no change in the trend.
order_of_polynomial_approximation: A numeric specifying the order of the polynomial approximation of the difference between time series used in estimate_lag. The default option is 7, the seventh-degree polynomial.
order_of_derivative: A numeric specifying the order of derivative for the approximated difference between time_series1 and lagged time_series2. The default option is 1, the first derivative.
spline: A Boolean specifying whether or not to use a smoothing spline for the lag estimation.
...: Additional arguments to be passed onto the smooth.spline function, if method is "polynomial".
Returns
cc_lag: A numeric indicating the estimated lag with the cross-correlation criterion.
mse_criterion: A numeric indicating the estimated lag with the MSE criterion.
rank_criterion: A numeric indicating the estimate lag with the rank criterion.
Examples
# Generate dataset with known lag and recover this lag --------------#'lag <-3n <-156start_year <-2005frequency <-12trend_function <-function(x) x^2x <- seq(-3,3, length.out = n)y1 <- ts(trend_function(x),start = start_year, freq = frequency)y2 <- stats::lag(y1, k = lag)# Recover lagestimate_lag(y1,y2, possible_lags =-36:36, method ="rank",leave_off =0, spline =FALSE)