Data Frame with Contribution of Individual Variables to Dissimilarity to Wide Format
Source:R/utils_importance_df_to_wide.R
utils_importance_df_to_wide.Rd
Takes as input a data frame returned by distantia_importance()
to return a data frame with one pair of time series per row, and the following columns:
most_similar
: name of the variable with the highest contribution to similarity (most negative value in theimportance
column) for each pair of time series.most_dissimilar
: name of the variable with the highest contribution to dissimilarity (most positive value in theimportance
column) for each pair of time series.importance__variable_name
: contribution to similarity (negative values) or dissimilarity (positive values) of the given variable.psi_only_with__variable_name
: dissimilarity of the two time series when only using the given variable.psi_without__variable_name
: dissimilarity of the two time series when removing the given variable.
Arguments
- df
(required, data frame) Output of
distantia_importance()
. Default: NULL- sep
(required, character string) Separator between the name of the importance metric and the time series variable. Default: "__".
See also
Other internal_dissimilarity_analysis:
utils_block_size()
,
utils_cluster_hclust_optimizer()
,
utils_cluster_kmeans_optimizer()
,
utils_cluster_silhouette()
Examples
#prepare time series
data("fagus_dynamics")
tsl <- tsl_initialize(
x = fagus_dynamics,
name_column = "name",
time_column = "time"
) |>
tsl_transform(
f = f_scale
)
#importance data frame
df <- distantia_importance(
tsl = tsl
)
df
#> x y psi variable importance effect
#> 1 Germany Spain 1.3429956 evi 6.512321 decreases similarity
#> 2 Germany Spain 1.3429956 rainfall 12.505764 decreases similarity
#> 3 Germany Spain 1.3429956 temperature -26.509115 increases similarity
#> 4 Germany Sweden 0.8571217 evi 29.026504 decreases similarity
#> 5 Germany Sweden 0.8571217 rainfall -4.209397 increases similarity
#> 6 Germany Sweden 0.8571217 temperature -26.661768 increases similarity
#> 7 Spain Sweden 1.4803954 evi -6.625437 increases similarity
#> 8 Spain Sweden 1.4803954 rainfall -4.416941 increases similarity
#> 9 Spain Sweden 1.4803954 temperature 13.668290 decreases similarity
#> psi_difference psi_without psi_only_with distance diagonal weighted
#> 1 0.08746019 1.3091727 1.3966329 euclidean TRUE TRUE
#> 2 0.16795186 1.2442260 1.4121779 euclidean TRUE TRUE
#> 3 -0.35601625 1.4170621 1.0610458 euclidean TRUE TRUE
#> 4 0.24879247 0.7850271 1.0338196 euclidean TRUE TRUE
#> 5 -0.03607966 0.8800855 0.8440058 euclidean TRUE TRUE
#> 6 -0.22852381 0.9121250 0.6836012 euclidean TRUE TRUE
#> 7 -0.09808266 1.5155933 1.4175106 euclidean TRUE TRUE
#> 8 -0.06538819 1.5451489 1.4797607 euclidean TRUE TRUE
#> 9 0.20234474 1.4411407 1.6434855 euclidean TRUE TRUE
#> ignore_blocks lock_step robust
#> 1 FALSE FALSE TRUE
#> 2 FALSE FALSE TRUE
#> 3 FALSE FALSE TRUE
#> 4 FALSE FALSE TRUE
#> 5 FALSE FALSE TRUE
#> 6 FALSE FALSE TRUE
#> 7 FALSE FALSE TRUE
#> 8 FALSE FALSE TRUE
#> 9 FALSE FALSE TRUE
#to wide format
df_wide <- utils_importance_df_to_wide(
df = df
)
df_wide
#> x y psi most_similar most_dissimilar importance__evi
#> 1 Germany Spain 1.3429956 temperature rainfall 6.512321
#> 2 Germany Sweden 0.8571217 temperature evi 29.026504
#> 3 Spain Sweden 1.4803954 evi temperature -6.625437
#> importance__rainfall importance__temperature psi_only_with__evi
#> 1 12.505764 -26.50912 1.396633
#> 2 -4.209397 -26.66177 1.033820
#> 3 -4.416941 13.66829 1.417511
#> psi_only_with__rainfall psi_only_with__temperature psi_without__evi
#> 1 1.4121779 1.0610458 1.3091727
#> 2 0.8440058 0.6836012 0.7850271
#> 3 1.4797607 1.6434855 1.5155933
#> psi_without__rainfall psi_without__temperature
#> 1 1.2442260 1.417062
#> 2 0.8800855 0.912125
#> 3 1.5451489 1.441141