Skip to content
Permalink
4077cc3076
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
45 lines (40 sloc) 1.45 KB
#' Function to apply kmeans clustering on the score of links
#'
#' @param score_matrix score matrix obtained from DPM or reg.DPM.
#'
#' @return a list containing
#' - the list of the links as a data frame. Each line of the data frame corresponds to a link.
#' The first and second columns are the corresponding nodes of the link and the third column is the score of the link.
#' - the threshold that all the links with scores more than it are considered as an edge.
#'
#' @examples
#' ## Load DREAM4 data (insilico_size10_1_knockouts)
#' data(dream4)
#'
#'## Run regularized DPM
#' res <- reg.dpm(data)
#'
#' ## Get the list of the links based on kmeans clustering
#' linklist <- kmeans_links(res)$LinkList
#'
#' ##Get the threshold at significance level alpha=0.05
#' kmeans_links(res)$threshold
#'
#'
#' @export
###########################################################
### Function to compute fisher z transformation pvalues ###
###########################################################
kmeans_links <- function(score_matrix){
score_matrix <- abs(score_matrix)
diag(score_matrix) <- NA
score_matrix[upper.tri(score_matrix)] <- NA
linkList <- reshape2::melt(score_matrix, na.rm=TRUE)
colnames(linkList) <- c("Node1", "Node2", "Score")
# do kmeans on scores
res = kmeans(linkList$Score, centers=2)
linkList <- linkList[res$cluster==which.max(res$centers),]
# compute threshold
threshold = mean(a$centers)
return(list(LinkList=linkList,threshold=threshold))
}