Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f39698
commit ae8bac0
Showing
8 changed files
with
167 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
### rankprod.R (2008-12-18) | ||
### | ||
### Two-sided rank products statistic | ||
### | ||
### Copyright 2008 Korbinian Strimmer | ||
### | ||
### This function is in part based on code from Henry Wirth. | ||
### | ||
### This file is part of the `st' library for R and related languages. | ||
### It is made available under the terms of the GNU General Public | ||
### License, version 3, or at your option, any later version, | ||
### incorporated herein by reference. | ||
### | ||
### This program is distributed in the hope that it will be | ||
### useful, but WITHOUT ANY WARRANTY; without even the implied | ||
### warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | ||
### PURPOSE. See the GNU General Public License for more | ||
### details. | ||
### | ||
### You should have received a copy of the GNU General Public | ||
### License along with this program; if not, write to the Free | ||
### Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, | ||
### MA 02111-1307, USA | ||
|
||
|
||
rankprod.stat = function (X, L) | ||
{ | ||
FUN = rankprod.fun(L=L) | ||
score = FUN(X) | ||
|
||
return( score ) | ||
} | ||
|
||
rankprod.fun <- function (L) | ||
{ | ||
if (missing(L)) stop("Class labels are missing!") | ||
L = factor(L) | ||
cl = levels(L) | ||
if (length(cl) != 2) stop("Class labels must be specified for two groups, not more or less!") | ||
|
||
idx1 = which( L == levels(L)[1] ) | ||
idx2 = which( L == levels(L)[2] ) | ||
|
||
function(X) | ||
{ | ||
ranks = array(0, dim=c( ncol(X), length(idx1)*length(idx2) ) ) | ||
|
||
for( i in 1:length(idx1) ) | ||
{ | ||
for( j in 1:length(idx2) ) | ||
{ | ||
index = j+length(idx2)*(i-1) | ||
ranks[ , index] = rank( -abs( X[idx1[i], ] - X[idx2[j], ] ) ) | ||
} | ||
} | ||
|
||
# geometric mean | ||
avg.rank = exp(rowMeans(log(ranks))) | ||
|
||
# return rank complement | ||
compl.rank = ncol(X)-avg.rank+1 | ||
|
||
return( compl.rank ) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
\name{diffmean.stat} | ||
\alias{diffmean.stat} | ||
\alias{diffmean.fun} | ||
\alias{rankprod.stat} | ||
\alias{rankprod.fun} | ||
|
||
|
||
\title{Difference of Means (``Fold Change'') and Rank Products Statistic} | ||
|
||
\usage{ | ||
diffmean.stat(X, L) | ||
diffmean.fun(L) | ||
rankprod.stat(X, L) | ||
rankprod.fun(L) | ||
} | ||
|
||
\description{ | ||
These function compute the difference of group means (``fold change'') and the | ||
related rank products statistic of Breitling et al. (2004). | ||
} | ||
|
||
\arguments{ | ||
\item{X}{data matrix. Note that the \emph{columns} correspond to variables (``genes'') | ||
and the \emph{rows} to samples.} | ||
\item{L}{factor containing class labels for the two groups. } | ||
} | ||
\details{ | ||
\code{diffmean.*} computes the difference of means (i.e. the fold-change for log-transformed data). | ||
|
||
\code{rankprod.*} computes the two-sided rank products statistic, i.e. the geometric mean of the | ||
ranks of the pairwise absolute mean differences (Breitling et al. 2004). Note that for consistency with the other functions in this package the \emph{complement} of the averaged ranks is returned | ||
(i.e. rank 1 becomes \code{ncol(X)}, rank 2 becomes \code{ncol(X)-1}, etc.). | ||
} | ||
\value{ | ||
The *.stat functions directly return the respective statistic for each variable. | ||
|
||
The corresponding *.fun functions return a function that produces the respective | ||
statistics when applied to a data matrix (this is very useful for simulations). | ||
} | ||
|
||
\references{ | ||
Breitling, R., et al. 2004. Rank products: a simple, yet powerful, new method | ||
to detect differentially regulated genes in replicated microarray experiments. | ||
FEBS Letters \bold{573}:83-9. | ||
} | ||
\author{ | ||
Korbinian Strimmer (\url{http://strimmerlab.org}). | ||
|
||
This function is in part based on code from Henry Wirth. | ||
} | ||
\seealso{\code{\link{studentt.stat}},\code{\link{shrinkt.stat}}.} | ||
|
||
\examples{ | ||
# load st library | ||
library("st") | ||
|
||
# load Choe et al. (2005) data | ||
data(choedata) | ||
X <- choe2.mat | ||
dim(X) # 6 11475 | ||
L <- choe2.L | ||
L | ||
|
||
# L may also contain some real labels | ||
L = c("group 1", "group 1", "group 1", "group 2", "group 2", "group 2") | ||
|
||
|
||
# difference of means resp. fold change statistic | ||
score = diffmean.stat(X, L) | ||
order(abs(score), decreasing=TRUE)[1:10] | ||
# [1] 4790 6620 1022 10979 970 35 2693 5762 5885 2 | ||
|
||
# two-sided rank products statistic | ||
score = rankprod.stat(X, L) | ||
order(score, decreasing=TRUE)[1:10] | ||
# [1] 4790 1022 10979 6620 35 2693 970 5762 5885 2 | ||
|
||
} | ||
\keyword{univar} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters