Aggregate Dissimilarity Data Frames Across Parameter Combinations
Source:R/distantia_aggregate.R
distantia_aggregate.Rd
The functions distantia()
and momentum()
allow dissimilarity assessments based on several combinations of arguments at once. For example, when the argument distance
is set to c("euclidean", "manhattan")
, the output data frame will show two dissimilarity scores for each pair of compared time series, one based on euclidean distances, and another based on manhattan distances.
The functions distantia_aggregate()
and momentum_aggregate()
compute the stats of dissimilarity metrics across combinations of parameters.
When df
is the result of distantia()
, the input data is grouped by pairs of time series, and the function f
is applied to the column "psi" by group
When df
is the result of momentum()
, the input data is grouped by pairs of time series and variables, and the function f
is applied to the columns "importance", "psi_only_with" and "psi_without" by group. However, if the values TRUE and FALSE appear in the column "robust" (which is not allowed by default in momentum()
), then the aggregation is cancelled with an error, as the results of both methods should not be aggregated together.
If psi scores smaller than zero occur in the aggregated output, then the the smaller psi value is added to the column psi
to start dissimilarity scores at zero.
If there are no different combinations of arguments in the input data frame, no aggregation happens, but all parameter columns are removed.
Arguments
- df
(required, data frame) Output of
distantia()
ormomentum()
. Default: NULL- f
(optional, function) Function to summarize psi scores (for example,
mean
) when there are several combinations of parameters indf
. Ignored when there is a single combination of arguments in the input. Default:mean
- ...
(optional, arguments of
f
) Further arguments to pass to the functionf
.
See also
Other dissimilarity_analysis:
distantia_boxplot()
,
distantia_cluster_hclust()
,
distantia_cluster_kmeans()
,
distantia_matrix()
,
distantia_plot()
,
distantia_spatial_network()
,
distantia_stats()
,
distantia_time_shift()
,
momentum_boxplot()
,
momentum_stats()
,
momentum_to_wide()
Examples
#three time series
#climate and ndvi in Fagus sylvatica stands in Spain, Germany, and Sweden
tsl <- tsl_initialize(
x = fagus_dynamics,
name_column = "name",
time_column = "time"
) |>
tsl_transform(
f = f_scale_global
)
if(interactive()){
tsl_plot(
tsl = tsl,
guide_columns = 3
)
}
#distantia with multiple parameter combinations
#-------------------------------------
df <- distantia(
tsl = tsl,
distance = c("euclidean", "manhattan"),
lock_step = TRUE
)
df[, c(
"x",
"y",
"distance",
"psi"
)]
#> x y distance psi
#> 2 Germany Sweden euclidean 0.8576700
#> 5 Germany Sweden manhattan 0.8591195
#> 4 Germany Spain manhattan 1.2698922
#> 1 Germany Spain euclidean 1.3061327
#> 3 Spain Sweden euclidean 1.4708497
#> 6 Spain Sweden manhattan 1.4890286
#aggregation using means
df <- distantia_aggregate(
df = df,
f = mean
)
df
#> x y psi
#> 1 Germany Spain 1.2880125
#> 2 Germany Sweden 0.8583947
#> 3 Spain Sweden 1.4799391
#momentum with multiple parameter combinations
#-------------------------------------
df <- momentum(
tsl = tsl,
distance = c("euclidean", "manhattan"),
lock_step = TRUE
)
df[, c(
"x",
"y",
"variable",
"distance",
"importance"
)]
#> x y variable distance importance
#> 1 Germany Spain evi euclidean 0.241829
#> 2 Germany Spain rainfall euclidean 19.051052
#> 3 Germany Spain temperature euclidean -30.814944
#> 4 Germany Sweden evi euclidean 28.539736
#> 5 Germany Sweden rainfall euclidean -4.845232
#> 6 Germany Sweden temperature euclidean -25.011608
#> 7 Spain Sweden evi euclidean -22.912397
#> 8 Spain Sweden rainfall euclidean 9.732110
#> 9 Spain Sweden temperature euclidean 12.501949
#> 10 Germany Spain evi manhattan 1.900935
#> 11 Germany Spain rainfall manhattan 21.154702
#> 12 Germany Spain temperature manhattan -29.727709
#> 13 Germany Sweden evi manhattan 29.249949
#> 14 Germany Sweden rainfall manhattan -3.444891
#> 15 Germany Sweden temperature manhattan -26.684626
#> 16 Spain Sweden evi manhattan -25.080233
#> 17 Spain Sweden rainfall manhattan 10.764640
#> 18 Spain Sweden temperature manhattan 12.742187
#aggregation using means
df <- momentum_aggregate(
df = df,
f = mean
)
df[, c(
"x",
"y",
"variable",
"importance"
)]
#> x y variable importance
#> 1 Germany Spain evi 1.071382
#> 2 Germany Sweden evi 28.894843
#> 3 Spain Sweden evi -23.996315
#> 4 Germany Spain rainfall 20.102877
#> 5 Germany Sweden rainfall -4.145061
#> 6 Spain Sweden rainfall 10.248375
#> 7 Germany Spain temperature -30.271327
#> 8 Germany Sweden temperature -25.848117
#> 9 Spain Sweden temperature 12.622068