From 4077cc307664a9541a3d37691d9b2513fbd1237f Mon Sep 17 00:00:00 2001 From: Ghanbari Date: Thu, 5 Oct 2017 17:42:28 +0200 Subject: [PATCH] update R package --- NAMESPACE | 2 +- R/fisher_test.R | 51 --------------------------------------------- R/kmeans_links.R | 45 +++++++++++++++++++++++++++++++++++++++ README.md | 32 ++++++++++++++++++++-------- man/fisher_test.Rd | 41 ------------------------------------ man/kmeans_links.Rd | 35 +++++++++++++++++++++++++++++++ 6 files changed, 104 insertions(+), 102 deletions(-) delete mode 100644 R/fisher_test.R create mode 100644 R/kmeans_links.R delete mode 100644 man/fisher_test.Rd create mode 100644 man/kmeans_links.Rd diff --git a/NAMESPACE b/NAMESPACE index f59fae7..5e740e3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,8 +2,8 @@ export(Dcenter) export(dpm) -export(fisher_test) export(get_link) +export(kmeans_links) export(nldata) export(rdata) export(reg.dpm) diff --git a/R/fisher_test.R b/R/fisher_test.R deleted file mode 100644 index d5c72fc..0000000 --- a/R/fisher_test.R +++ /dev/null @@ -1,51 +0,0 @@ -#' Function to compute fisher z-transformation pvalues for the links -#' -#' @param score_matrix score matrix obtained from DPM or reg.DPM. -#' @param alpha a significance level -#' @param nsamp is the number of samples (number of rows of input matrix for (reg-)DPM ). Note that we need nsamp such that: nsamp*(nsamp+1)> 2*(nvar-5) -#' @param nvar is the number of variables (number of columns of input matrix for (reg-)DPM ) -#' -#' @return a list containing -#' - the list of significant 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, the third column is the score of the link and the forth column is the corresponding pvalue. -#' - the threshold that all the links with scores more than it are significant at defined significance level. -#' -#' @examples -#' ## Load DREAM4 data (insilico_size10_1_knockouts) -#' data(dream4) -#' -#'## Run regularized DPM -#' res <- reg.dpm(data) -#' -#' ## Get the list of significant links at significance level alpha=0.05 -#' fisher_test(res,alpha=0.05,10,10)$LinkList -#' -#' ##Get the threshold at significance level alpha=0.05 -#' fisher_test(score_matrix=res,alpha=0.05,nsamp=10,nvar=10)$threshold -#' -#' -#' @export - -########################################################### -### Function to compute fisher z transformation pvalues ### -########################################################### - -fisher_test <- function(score_matrix, alpha, nsamp, nvar){ - nsamp <- (nsamp*(nsamp+1))/2 - if (nsamp-(nvar-2)-3 <= 0 ) stop("the test requires nsamp such that: nsamp*(nsamp+1)> 2*(nvar-5)") - 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") - p <- linkList["Score"] - z <- sqrt(nsamp-(nvar-2)-3) * abs(atan(p)) - pval <- 2 * pnorm(-as.matrix(z)) - colnames(pval) <- "Pvalue" - linkList <- cbind(linkList,pval) - linkList <- linkList[linkList$Pvalue 2*(nvar-5)} - -\item{nvar}{is the number of variables (number of columns of input matrix for (reg-)DPM )} -} -\value{ -a list containing -- the list of significant 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, the third column is the score of the link and the forth column is the corresponding pvalue. -- the threshold that all the links with scores more than it are significant at defined significance level. -} -\description{ -Function to compute fisher z-transformation pvalues for the links -} -\examples{ -## Load DREAM4 data (insilico_size10_1_knockouts) -data(dream4) - -## Run regularized DPM -res <- reg.dpm(data) - -## Get the list of significant links at significance level alpha=0.05 -fisher_test(res,alpha=0.05,10,10)$LinkList - -##Get the threshold at significance level alpha=0.05 -fisher_test(score_matrix=res,alpha=0.05,nsamp=10,nvar=10)$threshold - - -} diff --git a/man/kmeans_links.Rd b/man/kmeans_links.Rd new file mode 100644 index 0000000..06e8e92 --- /dev/null +++ b/man/kmeans_links.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/kmeans_links.R +\name{kmeans_links} +\alias{kmeans_links} +\title{Function to apply kmeans clustering on the score of links} +\usage{ +kmeans_links(score_matrix) +} +\arguments{ +\item{score_matrix}{score matrix obtained from DPM or reg.DPM.} +} +\value{ +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. +} +\description{ +Function to apply kmeans clustering on the score of links +} +\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 + + +}