library(clustNet)
First, we need to learn the networks. Here, we simulate data from three clusters. This process takes around two minutes on a local PC.
library(clustNet)
# Simulate data
<- 3 # numer of clusters
k_clust <- c(400, 500, 600) # samples in each cluster
ss <- sampleData(k_clust = k_clust, n_vars = 20, n_samples = ss)
simulation_data <- simulation_data$sampled_data
sampled_data
# Network-based clustering
<- get_clusters(sampled_data, k_clust = k_clust) cluster_results
We can visualize the networks as follows.
# Load additional pacakges to visualize the networks
library(ggplot2)
library(ggraph)
library(igraph)
##
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
## The following object is masked from 'package:base':
##
## union
library(ggpubr)
# Visualize networks
plot_clusters(cluster_results)
Finally, we can create a density plot of our clustering.
# Load additional pacakges to create a 2d dimensionality reduction
library(car)
## Loading required package: carData
library(ks)
##
## Attaching package: 'ks'
## The following object is masked from 'package:igraph':
##
## compare
library(graphics)
library(stats)
# Plot a 2d dimensionality reduction
density_plot(cluster_results)