# Using just the base distance metrics ------------------------------------
dist_fns_list <- dist_fns_list()
# Adding your own metrics --------------------------------------------------
# This will contain only the and user-provided distance function:
cubed_euclidean <- function(df, weights_row) {
# (your code that converts a data frame to a distance metric here...)
weights <- diag(weights_row, nrow = length(weights_row))
weighted_df <- as.matrix(df) %*% weights
distance_matrix <- weighted_df |>
stats::dist(method = "euclidean") |>
as.matrix()
distance_matrix <- distance_matrix^3
return(distance_matrix)
}
dist_fns_list <- dist_fns_list(
cnt_dist_fns = list(
"my_cubed_euclidean" = cubed_euclidean
)
)
# Using default base metrics------------------------------------------------
# Call ?distance_metrics to see all distance metric functions provided in
# metasnf. The code below will contain a mix of user-provided and built-in
# distance metric functions.
dist_fns_list <- dist_fns_list(
cnt_dist_fns = list(
"my_distance_metric" = cubed_euclidean
),
dsc_dist_fns = list(
"my_distance_metric" = cubed_euclidean
),
ord_dist_fns = list(
"my_distance_metric" = cubed_euclidean
),
cat_dist_fns = list(
"my_distance_metric" = gower_distance
),
mix_dist_fns = list(
"my_distance_metric" = gower_distance
),
use_default_dist_fns = TRUE
)
Run the code above in your browser using DataLab