Question: row t test with biocLite(genefilter)
0
gravatar for sebastien200109
3.9 years ago by
France
sebastien2001090 wrote:

I'm trying to run a t test on 2 groups of samples for a list of variables. My dataset (=df) looks like this: 

GeneName  group1  group1  group1  group2  group2  group2

gene1

gene2

gene3

...

I want to obtain p value for t test comparing for each row (gene) the values of group1 vs group2.

I tried to use the rowttests() function of genefilter package for bioconductor as such: 

df$ttest <- rowttests(df, factor(c(group1, group2)))

I'm getting the following error: 

Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘rowttests’ for signature ‘"data.frame", "factor"’

 

What am I doing wrong?

Thanks

genefilter row t test R • 3.2k views
ADD COMMENTlink modified 3.9 years ago • written 3.9 years ago by sebastien2001090
df$ttest <- rowttests(as.matrix(df[,-1]), factor(c(0,0,0,1,1,1)) gives the following error: 

Error in rowcoltt(x, fac, tstatOnly, 1L) : 
  Invalid argument 'x': must be a real matrix.

ADD REPLYlink written 3.9 years ago by sebastien2001090

So throw an as.double() in there.

ADD REPLYlink written 3.9 years ago by Devon Ryan90k

Could you be more specific? (I'm beginner in R)

ADD REPLYlink written 3.9 years ago by sebastien2001090

This is going to get messy, but the general idea is:

df$ttest <- rowttests(matrix(as.double(unlist(df[,-1])), ncol=6), factor(c(0,0,0,1,1,1))

Or something along those lines. BTW, don't worry about the unlist() part, it just converts your data.frame into a vector (data.frames are actually a special kind of list in R).

ADD REPLYlink written 3.9 years ago by Devon Ryan90k
1
gravatar for Devon Ryan
3.9 years ago by
Devon Ryan90k
Freiburg, Germany
Devon Ryan90k wrote:
> showMethods(rowttests)
Function: rowttests (package genefilter)
x="ExpressionSet", fac="character"
x="ExpressionSet", fac="factor"
x="ExpressionSet", fac="missing"
x="matrix", fac="factor"
x="matrix", fac="missing"


So, I suspect that something like this will work:

df$ttest <- rowttests(as.matrix(df[,-1]), factor(c(0,0,0,1,1,1))
ADD COMMENTlink modified 3.9 years ago • written 3.9 years ago by Devon Ryan90k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 796 users visited in the last hour