This function computes an approximation to the time-shift between pairs of time series as the absolute time difference between pairs of observations connected by the time warping path. It returns a data frame with the mean, median, minimum, maximum, quantiles 0.25 and 0.75, and standard deviation of the time shift.
This function requires scaled and detrended time series. Still, it might yield non-sensical results.
Arguments
- tsl
(required, time series list) list of zoo time series. Default: NULL
- distance
(optional, character vector) name or abbreviation of the distance method. Valid values are in the columns "names" and "abbreviation" of the dataset distances. Default: "euclidean".
- bandwidth
(optional, numeric) Proportion of space at each side of the cost matrix diagonal (aka Itakura parallelogram) defining a valid region for dynamic time warping, used to control the flexibility of the warping path. This method prevents degenerate alignments due to differences in magnitude between time series when the data is not properly scaled. If
1
(default), DTW is unconstrained. If0
, DTW is fully constrained and the warping path follows the matrix diagonal. Recommended values may vary depending on the nature of the data. Ignored iflock_step = TRUE
. Default: 1.
See also
Other dissimilarity_analysis:
distantia_aggregate()
,
distantia_boxplot()
,
distantia_cluster_hclust()
,
distantia_cluster_kmeans()
,
distantia_matrix()
,
distantia_plot()
,
distantia_spatial_network()
,
distantia_stats()
,
momentum_boxplot()
,
momentum_stats()
,
momentum_to_wide()
Examples
#load three time series
tsl <- tsl_init(
x = cities_temperature,
name = "name",
time = "time"
) |>
tsl_subset(
names = c("London", "Kinshasa"),
time = c("2000-01-01", "2010-01-01")
) |>
tsl_transform(
f = f_scale_local
)
#the data has a polynomial trend
tsl_trend <- tsl_transform(
tsl = tsl,
f = f_trend_poly
)
if(interactive()){
tsl_plot(
tsl = tsl_trend
)
}
#polynomial detrending
tsl <- tsl_transform(
tsl = tsl,
f = f_detrend_poly
)
if(interactive()){
tsl_plot(
tsl = tsl
)
}
#compute shifts
df_shift <- distantia_time_shift(
tsl = tsl,
distance = "euclidean"
)
df_shift
#> x y distance mean min q1 median q3
#> 1 London Kinshasa euclidean 179.8864 days 0 days 153 days 184 days 213 days
#> max sd
#> 1 334 days 66.29288
#check alignment
distantia_plot(
tsl = tsl[c("Kinshasa", "London")]
)