[BioC] Error: couldn't find function "-<-"

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Wed Aug 18 13:03:22 CEST 2004


The problem lies in the name of the function "T-test". In R, you cannot
use a hypen in function name as it also represents the minus operator.
Try using underscore or dot. 

Here is a function that I use which generalises yours. It allows missing
values in class variable, returns NA when one of the groups contain one
or no valid observation and some basic error checking.

row.t.test <- function(mat, cl){

  stopifnot(length(cl)==ncol(mat))
  if(nlevels(as.factor(cl)) !=2 ) stop("Only two levels in cl allowed")
            
  g1 <- which( cl == levels(as.factor(cl))[1] )
  g2 <- which( cl == levels(as.factor(cl))[2] )
  length.na <- function(x) length( x[ !is.na(x) ] )

  results <- apply(mat, 1, function(x){ 
    if( length.na(x[g1]) < 2 || length.na(x[g2]) < 2 ){
      return(NA)
    } else {
      return( t.test( x[g1], x[g2] )$p.value )
    }
  })

  return(results)
}

# USAGE
mat <- matrix( rnorm(120), nc=12 )
mat[ lower.tri(mat) ] <- NA

cl  <- rep(1:2, each=6)
cl[3] <- NA

row.t.test(mat, cl)



On Tue, 2004-08-17 at 23:09, S Peri wrote:
> Hello Dr. Ramasamy,
> Thank you for your mail. I loaded only 49 files
> instead of 50. 
 
>  I am writing the a function for T-test and the
> following error creeps in always.
> 
> Could you pls. let me know if the problem is in
> defining function or something else. 
> Thank you.
> PS
> 
> 
> > T-test <- function(X,CL){
> + ttest <- function(Xrow,CL){
> + return(t.test(Xrow[CL==0],Xrow[CL==1])$p.value)
> + }
> + return(apply(X,1,ttest,CL=CL))
> + }
> Error: couldn't find function "-<-"
> 
> 
> 
> 
> 
> 
> 
> 
> 
> --- Adaikalavan Ramasamy <ramasamy at cancer.org.uk>
>  	wrote:
> 
> > First thing first. Are you sure justRMA is returning
> > expression for 49
> > arrays when you have 50 files in the working
> > directory ?
> > 
> > getwd()
> > library(affy)
> > length(list.celfiles())
> > 
> > If you accidentally deleted one CEL file, this could
> > be the reason later
> > calls also fail.
> > 
> > 
> > On Tue, 2004-08-17 at 17:44, S Peri wrote:
> > > Dear Group, 
> > >  
> > > I am analyzing Affy dataset from Harvard Brain CEL
> > > database. 
> > > 
> > > I am working on the data from an experiment where
> > 50
> > > samples were analyzed.  I exported the expressions
> > to
> > > a matrix. 
> > > 
> > > >gliexp <- exprs(justRMA())
> > > > dim(gliexp)
> > > [1] 12625    49
> > > 
> > > 
> > > I sorted out samples on the pathological state (4
> > > categories).  Now I want to do SAM and t-test on
> > any
> > > of the 2 samples. 
> > > 
> > > I made these 4 categories into 0,1,2 and 3. This
> > was
> > > made in a class file : Brain.cl
> > > 
> > > I wrote a function where values from 0 and 1 will
> > give
> > > me the means from 0 and 1.
> > > 
> > > My function:
> > > 
> > > >BrainFc <- function(exp,cl){
> > > +X0 = X[,cl==0]
> > > +X1 = X[,cl==1]
> > > +return(apply(X0,1,mean) - apply(X1,1,mean))}
> > > 
> > > >myBrainFcs <- BrainFc(gliexp,Brain.cl)
> > > Error in X[, CL == 0] : incorrect number of
> > dimensions
> > > 
> > > 
> > > I do not understand why am I getting this error.
> > > 
> > > I checked to see dim of my expression matrix:
> > > > dim(gliexp)
> > > [1] 12625    49
> > > 
> > > I have 50 samples, here I see 49.
> > > 
> > > Is this is the source of error? If so what should
> > I
> > > do?
> > > 
> > > 
> > > I also did the following by reading previous
> > messages
> > > from BioC mailing lists:
> > > 
> > > > gliexp_genes <- gliexp[1:12625,]
> > > > myBrainFcs <- BrainFc(gliexp_genes,Brain.cl)
> > > 
> > > Error in BrainFc(gliexp_genes, Brain.cl) :
> > (subscript)
> > > logical subscript too long
> > > 
> > > 
> > > After this I do not have any option to write to
> > BioC
> > > for some help. 
> > > 
> > > Please help me where I am doing wrong.
> > > 
> > > Thank you
> > > 
> > > PS
> > > 
> > > _______________________________________________
> > > Bioconductor mailing list
> > > Bioconductor at stat.math.ethz.ch
> > > https://stat.ethz.ch/mailman/listinfo/bioconductor
> > > 
> > 
> > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com
>



More information about the Bioconductor mailing list