Aggregate momentum()
Data Frames Across Parameter Combinations
Source: R/momentum_aggregate.R
momentum_aggregate.Rd
The function momentum()
allows variable importance 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 importance scores for each pair of compared time series and variable, one based on euclidean distances, and another based on manhattan distances.
This function computes importance stats across combinations of parameters.
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
momentum()
,momentum_ls()
, ormomentum_dtw()
. 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 momentum_support:
momentum_boxplot()
,
momentum_model_frame()
,
momentum_spatial()
,
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
)
}
#momentum with multiple parameter combinations
#-------------------------------------
df <- momentum(
tsl = tsl,
distance = c("euclidean", "manhattan"),
lock_step = TRUE
)
df[, c(
"x",
"y",
"distance",
"importance"
)]
#> x y distance importance
#> 1 Germany Spain euclidean 0.241829
#> 2 Germany Spain euclidean 19.051052
#> 3 Germany Spain euclidean -30.814944
#> 4 Germany Sweden euclidean 28.539736
#> 5 Germany Sweden euclidean -4.845232
#> 6 Germany Sweden euclidean -25.011608
#> 7 Spain Sweden euclidean -22.912397
#> 8 Spain Sweden euclidean 9.732110
#> 9 Spain Sweden euclidean 12.501949
#> 10 Germany Spain manhattan 1.900935
#> 11 Germany Spain manhattan 21.154702
#> 12 Germany Spain manhattan -29.727709
#> 13 Germany Sweden manhattan 29.249949
#> 14 Germany Sweden manhattan -3.444891
#> 15 Germany Sweden manhattan -26.684626
#> 16 Spain Sweden manhattan -25.080233
#> 17 Spain Sweden manhattan 10.764640
#> 18 Spain Sweden manhattan 12.742187
#aggregation using means
df <- momentum_aggregate(
df = df,
f = mean
)
df
#> x y psi variable importance effect
#> 1 Germany Spain 1.3061327 evi 0.241829 decreases similarity
#> 2 Germany Spain 1.3061327 rainfall 19.051052 decreases similarity
#> 3 Germany Spain 1.3061327 temperature -30.814944 increases similarity
#> 4 Germany Sweden 0.8576700 evi 28.539736 decreases similarity
#> 5 Germany Sweden 0.8576700 rainfall -4.845232 increases similarity
#> 6 Germany Sweden 0.8576700 temperature -25.011608 increases similarity
#> 7 Spain Sweden 1.4708497 evi -22.912397 increases similarity
#> 8 Spain Sweden 1.4708497 rainfall 9.732110 decreases similarity
#> 9 Spain Sweden 1.4708497 temperature 12.501949 decreases similarity
#> 10 Germany Spain 1.2698922 evi 1.900935 decreases similarity
#> 11 Germany Spain 1.2698922 rainfall 21.154702 decreases similarity
#> 12 Germany Spain 1.2698922 temperature -29.727709 increases similarity
#> 13 Germany Sweden 0.8591195 evi 29.249949 decreases similarity
#> 14 Germany Sweden 0.8591195 rainfall -3.444891 increases similarity
#> 15 Germany Sweden 0.8591195 temperature -26.684626 increases similarity
#> 16 Spain Sweden 1.4890286 evi -25.080233 increases similarity
#> 17 Spain Sweden 1.4890286 rainfall 10.764640 decreases similarity
#> 18 Spain Sweden 1.4890286 temperature 12.742187 decreases similarity
#> psi_difference psi_without psi_only_with
#> 1 0.003158608 1.2848422 1.2880008
#> 2 0.248832026 1.1566276 1.4054596
#> 3 -0.402484076 1.3910532 0.9885691
#> 4 0.244776759 0.7873060 1.0320827
#> 5 -0.041556104 0.8829917 0.8414356
#> 6 -0.214517060 0.9099069 0.6953898
#> 7 -0.337006921 1.5557210 1.2187141
#> 8 0.143144705 1.4286475 1.5717922
#> 9 0.183884884 1.4493101 1.6331950
#> 10 0.024139830 1.2638610 1.2880008
#> 11 0.268641921 1.1368177 1.4054596
#> 12 -0.377509869 1.3660790 0.9885691
#> 13 0.251292009 0.7807907 1.0320827
#> 14 -0.029595727 0.8710313 0.8414356
#> 15 -0.229252821 0.9246426 0.6953898
#> 16 -0.373451830 1.5921659 1.2187141
#> 17 0.160288560 1.4115037 1.5717922
#> 18 0.189734804 1.4434602 1.6331950