# Load example dataset
data("Data_HC_contamination")
# Reduce dataset to first 50 rows
Data_small <- Data_HC_contamination[1:50, ]
# Select only continuous variables
cont_vars <- names(Data_small)[1:4]
Data_cont <- Data_small[, cont_vars]
# Compute squared Euclidean distance matrix
dist_mat <- as.matrix(dist(Data_cont))^2
# Introduce a small non-Euclidean distortion
dist_mat[1, 2] <- dist_mat[1, 2] * 0.5
dist_mat[2, 1] <- dist_mat[1, 2]
# Uniform weights
weights <- rep(1, nrow(Data_cont))
# Apply Euclidean correction
res <- make_euclidean(dist_mat, weights)
# Check results (minimum eigenvalues before/after)
res$transformed
min(res$eigvals_before)
min(res$eigvals_after)
# First 5x5 block of corrected matrix
round(res$D_euc[1:5, 1:5], 4)
Run the code above in your browser using DataLab