From fb9b7b8e5e879fd7734dc07cffa27cdb12b9ef0f Mon Sep 17 00:00:00 2001 From: noah Date: Mon, 21 Mar 2022 23:29:20 -0500 Subject: [PATCH] TOM and Dynamic Tree Cut --- Schrick-Noah_CS-7863_Homework-3.R | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Schrick-Noah_CS-7863_Homework-3.R b/Schrick-Noah_CS-7863_Homework-3.R index e00592e..f2370f7 100644 --- a/Schrick-Noah_CS-7863_Homework-3.R +++ b/Schrick-Noah_CS-7863_Homework-3.R @@ -40,9 +40,9 @@ x2_clusters <- ifelse(x2>0,1,-1) # Plotting V(g1)$color <- ifelse(x1_clusters>0,"green","yellow") -V(g1)$size <- 50*abs(x1) +#V(g1)$size <- 80*abs(x1) V(g2)$color <- ifelse(x2_clusters>0,"green","yellow") -V(g2)$size <- 50*abs(x2) +V(g2)$size <- 10 plot(g1, main=paste(g1.netname, " Laplace Spectral Clustering")) plot(g2, main=paste(g2.netname, " Laplace Spectral Clustering"), vertex.label=NA) @@ -77,6 +77,32 @@ plot(karate,vertex.size=10, ###################### Part 4: TOM and Dynamic Tree Cut ###################### +# Next smallest eig +y1 <- eigen(g1.Lap)$vectors[,n1-2] # get n-2 column +names(y1) <- names(V(g1)) +y1_val <- eigen(g1.Lap)$values[n1-2] +y2 <- eigen(g2.Lap)$vectors[,n2-2] # get n-2 column +names(y2) <- names(V(g2)) +y2_val <- eigen(g2.Lap)$values[n2-2] +# Distance in the 2D Laplacian Eig-Space +lap_dist1 <- dist(cbind(x1,y1)) +lap_dist2 <- dist(cbind(x2,y2)) + +# Use hierachical clustering of distance matrix +lap_tree1 <- hclust(lap_dist1) +lap_tree2 <- hclust(lap_dist2) + +# Use WGCNA to dynamically decide how many clusters +cutreeDynamicTree(lap_tree1) +cutreeDynamicTree(lap_tree2) + +# TOM +g1.TOM <- TOMsimilarity(as.matrix(g1.adj)) +g2.TOM <- TOMsimilarity(as.matrix(g2.adj)) +g1.TOM +g2.TOM +TOMplot(g1.TOM, lap_tree1, main=paste(g1.netname, " Heatmap Plot")) +TOMplot(g2.TOM, lap_tree2, main=paste(g2.netname, " Heatmap Plot")) ################################ Part 5: UMAP ################################ \ No newline at end of file