## Run with pre-defined random matrix:
set.seed(777)
random.matrix <- create.rand.mat(size = 1000, distrib = "norm")$rand.matr
dim(random.matrix) # 1000 1000
## Not run:
# res <- rm.get.threshold(random.matrix) # threshold might be 3.21
# str(res) # List of 26
# rm.show.plots(res$comparison.plots) # watch sequence of plots once more
# ## End(Not run)
## Try other parameters:
## Not run:
# res <- rm.get.threshold(random.matrix, unfold.method = "spline")
# res <- rm.get.threshold(random.matrix, dist.method = "KLD")
# res <- rm.get.threshold(random.matrix, discard.outliers = FALSE) # might cause problems
# res <- rm.get.threshold(random.matrix, wait.seconds = 2) # slow down
# res <- rm.get.threshold(random.matrix, discard.zeros = TRUE)
# res <- rm.get.threshold(random.matrix, discard.zeros = TRUE, dist.method = "KLD")
# ## End(Not run)
## Refine analysis by choosing narrower threshold range
## Not run:
# res <- rm.get.threshold(random.matrix, interval = c(2.5, 3.5))
# ## End(Not run)
## Apply the identified threshold to the matrix
cleaned.matrix <- rm.denoise.mat(random.matrix, threshold = 3.21)
cleaned.matrix <- rm.discard.zeros(cleaned.matrix)
dim(cleaned.matrix) # smaller
## Find the clusters in the thresholded matrix:
## Not run:
# library(igraph)
# g <- graph.adjacency(cleaned.matrix, mode = "undirected")
# clusters(g)
# ## End(Not run)
## Not run:
#
# ## Create modular matrix and validate:
# matlist = list()
# for (i in 1:4) matlist[[i]] = get.adjacency(erdos.renyi.game(250, 0.1))
# mat <- bdiag(matlist) # create block-diagonal matrix
# rm.matrix.validation(as.matrix(mat)) # Exponential case, modular matrix
#
# ## Add noise:
# mat1 = add.Gaussian.noise(as.matrix(mat), mean = 0, stddev = 0.1)
#
# ## Find threshold, denoise, reconstruct the modules:
# res <- rm.get.threshold(mat1) # threshold possibly about 0.46
# # a smaller interval had been ok as well:
# res <- rm.get.threshold(mat1, interval = c(0, 0.8))
# cleaned <- rm.denoise.mat(mat1, 0.5)
# matr <- cleaned != 0
# g <- graph.adjacency(matr, mode = "undirected")
# clusters(g) # 4 clusters reconstructed
#
# ## End(Not run)
Run the code above in your browser using DataLab