<p>You can simply <code>apply()</code> <code>t.test()</code> to your matrix. In general, though, I expect <code>lmFit()</code> from the <code>limma</code> package will be simpler to use.</p>

<p>Here is an example with <code>t.test()</code>:</p>

<pre><code>m = matrix(runif(100, max=c(rep(1, 50), rep(1.5, 50))), nrow=10) # make some data
apply(m, 1, function(x) t.test(x[1:5], x[6:10])$p.value)
</code></pre>

<p>Neither <code>t.test()</code> nor <code>lmFit()</code> should be expected to produce the same results as excel, since excel is inferior in every way and should never be relied upon for any statistical analysis (plus <code>lmFit</code> is doing something much much more complicated than a simple t-test).</p>

<p>As an aside, FPKMs are highly problematic for use in statistics. If possible, I strongly encourage you to get either per-gene counts or per-gene estimated counts and to use those in <code>limma</code> or another differential expression package instead, as the results will be much more reliable. I presume, though, that you're using TCGA data, so you may be stuck with FPKMs.</p>

CC BY-SA 3.0
2018-04-15T09:20:39.443Z
I totally agree with Devon's aside comment. FPKM values are not suitable for (sound) statistics and only informative for heatmaps etc. For proper statistics you should use count data, all statisticians agree on that.
benn
CC BY-SA 3.0
2018-04-15T13:02:14.383Z
@b.nota Source?
SmallChess
CC BY-SA 3.0
2018-04-15T13:48:14.263Z
@SmallChess, for example paper about [edgeR](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2796818/), but also the more difficult stuff of Gordon Smyth and read the discussions on bioconductor support.
benn
CC BY-SA 3.0
2018-04-15T13:55:40.177Z
I tried t.test()`Group1.ttest <- t.test(data.Normal, data.Group1, "two.sided", paired = FALSE, var.equal = FALSE)`but the function does not give me p.values row-wise. The result that I obtained for above code`> Group1.ttest$p.value
[1] 5.632393e-48`I tried lmFit() `fac <- factor(c(rep(0,80),rep(1,135)))
fit = lmFit(Normal.Group1, design=model.matrix(~ fac))  
e = eBayes(fit)
tab<-topTable(e, number=nrow(Normal.Group1))`  but the p-values obtained are different from the ones obtained when I do the t.test on the same data in Excel. I tried `log2(Normal.Group1)` but still the results differ.
user98059
CC BY-SA 3.0
2018-04-15T18:24:37.200Z
The results should differ, excel should never be relied on for anything important. lmFit is also a more complicated computation than a simple t-test. Please see my updated reply.
Devon Ryan
CC BY-SA 3.0
2018-04-19T19:19:02.250Z
Is a  parametric t-test really suitable, either?
CKM
CC BY-SA 3.0
2018-04-19T19:22:03.563Z
Depending on the input, yes. Limma is basically a fancy t-test.
Devon Ryan
CC BY-SA 3.0
2018-04-15T07:39:20.590Z
2018-04-15T18:23:32.837Z
2018-04-15T18:23:32.837Z
Devon Ryan
<p>I have FPKM values for Normal(80 cases), Group1(135 cases), Group2(147 cases), and Group3(102 cases) for 160 genes (Groups were obtained by clustering tumor data). </p>

<p>I want to perform t-test (two-sided, unpaired, unequal variance) between Normal and Group1, Normal and Group2, and Normal and Group3 such that I get p.value for each gene.<br>
The t.test function in R returns single p.value and not gene-wise (I don't want to do t-test in Excel). </p>

<p>Which package/function should I use to do this in R?</p>

<r><differential-expression>
Performing t.test to obtain p.values for each gene
# Performing t.test to obtain p.values for each gene

(Asked by: username_0 on 2018-04-15)

I have FPKM values for Normal(80 cases), Group1(135 cases), Group2(147 cases), and Group3(102 cases) for 160 genes (Groups were obtained by clustering tumor data).

I want to perform t-test (two-sided, unpaired, unequal variance) between Normal and Group1, Normal and Group2, and Normal and Group3 such that I get p.value for each gene.  
The t.test function in R returns single p.value and not gene-wise (I don't want to do t-test in Excel).

Which package/function should I use to do this in R?

**Tags:** r, differential-expression

---

## 1 answers

### Answer by username_1 on 2018-04-15. Score: 4 | Accepted answer

You can simply apply() t.test() to your matrix. In general, though, I expect lmFit() from the limma package will be simpler to use.
Here is an example with t.test():
m = matrix(runif(100, max=c(rep(1, 50), rep(1.5, 50))), nrow=10) # make some data
apply(m, 1, function(x) t.test(x[1:5], x[6:10])$p.value)

Neither t.test() nor lmFit() should be expected to produce the same results as excel, since excel is inferior in every way and should never be relied upon for any statistical analysis (plus lmFit is doing something much much more complicated than a simple t-test).
As an aside, FPKMs are highly problematic for use in statistics. If possible, I strongly encourage you to get either per-gene counts or per-gene estimated counts and to use those in limma or another differential expression package instead, as the results will be much more reliable. I presume, though, that you're using TCGA data, so you may be stuck with FPKMs.

> **Comments:**
> **username_2**: I totally agree with Devon's aside comment. FPKM values are not suitable for (sound) statistics and only informative for heatmaps etc. For proper statistics you should use count data, all statisticians agree on that.  
> **username_3**: @b.nota Source?  
> **username_2**: @SmallChess, for example paper about [edgeR](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2796818/), but also the more difficult stuff of Gordon Smyth and read the discussions on bioconductor support.  
> **username_0**: I tried t.test()`Group1.ttest <- t.test(data.Normal, data.Group1, "two.sided", paired = FALSE, var.equal = FALSE)`but the function does not give me p.values row-wise. The result that I obtained for above code`> Group1.ttest$p.value [1] 5.632393e-48`I tried lmFit() `fac <- factor(c(rep(0,80),rep(1,135))) fit = lmFit(Normal.Group1, design=model.matrix(~ fac))   e = eBayes(fit) tab<-topTable(e, number=nrow(Normal.Group1))`  but the p-values obtained are different from the ones obtained when I do the t.test on the same data in Excel. I tried `log2(Normal.Group1)` but still the results differ.  
> **username_1**: The results should differ, excel should never be relied on for anything important. lmFit is also a more complicated computation than a simple t-test. Please see my updated reply.  
> **username_4**: Is a  parametric t-test really suitable, either?  
> **username_1**: Depending on the input, yes. Limma is basically a fancy t-test.  

---

