# --------------------------------------
# Network Graph Example from Robust Distances
# --------------------------------------
data("Data_HC_contamination", package = "dbrobust")
# Subset small dataset
Data_small <- Data_HC_contamination[1:20, ]
cont_vars <- c("V1", "V2", "V3", "V4")
cat_vars <- c("V5", "V6", "V7")
bin_vars <- c("V8", "V9")
w <- Data_small$w_loop
# Compute GGower robust distances
dist_sq_ggower <- dbrobust::robust_distances(
data = Data_small,
cont_vars = cont_vars,
bin_vars = bin_vars,
cat_vars = cat_vars,
w = w,
alpha = 0.10,
method = "ggower"
)
# Create factor indicating Normal vs Outlier
n_obs <- nrow(dist_sq_ggower)
group_vec <- rep("Normal", n_obs)
group_vec[attr(dist_sq_ggower, "outlier_idx")] <- "Outlier"
group_factor <- factor(group_vec, levels = c("Normal", "Outlier"))
# Plot network graph (small, for CRAN)
dbrobust::plot_qgraph(
dist_mat = sqrt(dist_sq_ggower),
group = group_factor,
max_nodes = 10,
label_size = 2,
edge_threshold = 0.1,
layout = "spring",
seed = 123,
main_title = "GGower Network Graph with Outliers"
)
Run the code above in your browser using DataLab