对数据集中每一行的列进行t.test [英] doing t.test for columns for each row in data set
本文介绍了对数据集中每一行的列进行t.test的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一组数据x
,它由12列和167行组成.第一列是每一行的复合ID.我想分别为每行分别将3列的t.test
作为一组运行,将其他3组作为第二组运行.我的代码如下,但不起作用.
I have a set of data x
which consists of 12 columns and 167 rows. The first column is compound Id for each row. I want to run a t.test
for 3 column as one group and the other 3 groups as the second group, separately for each row. My code is as below but it does not work.
for (i in 1:nrow(x)) {
function(i)c(compound=i,
t.test(x[2:4],x[8:10],
x[x$compound==i, ],
alternative='two.sided',conf.level=0.95)
)
}
print(c(compound=i,t.test(x[2:4],x[8:10],x[x$compound==i,],
alternative='two.sided',conf.level=0.95)))
我的目的是对AC组和SC组之间的每种代谢物(化合物)进行t.test
,这是两组细胞.
My intention was doing a t.test
for each metabolite (compound) between AC groups and SC groups, these are two group of cells.
compound AC-1 AC-2 AC-3 AM-1 AM-2 AM-3 SC-1 SC-2 SC-3 SM-1 SM-2 SM-3
alanine 27612820 22338050 15359640 19741350 18726880 18510800 10914980 12071660 16036180 16890860 16066960 16364300
arginine 7067206 7172234 5933320 136272600 131596800 134717600 6102838 7186256 6770344 140127100 155341300 151748000
asparagine 3151398 2141378 1240904 11522180 8907711 9842342 1677299 2265826 2942991 11690360 12552660 12102620
推荐答案
另一种替代方法是使用软件包.
Another alternative is using a package.
您的数据:
df <- rbind(c(27612820, 22338050, 15359640, 19741350, 18726880, 18510800, 10914980, 12071660, 16036180, 16890860, 16066960, 16364300),
c(7067206, 7172234, 5933320, 136272600, 131596800, 134717600, 6102838, 7186256, 6770344, 140127100, 155341300, 151748000),
c(3151398, 2141378, 1240904, 11522180, 8907711, 9842342, 1677299, 2265826, 2942991, 11690360, 12552660, 12102620)
)
df <- data.frame(df)
rownames(df) <- c("alanine", "arginine", "asparagine")
colnames(df) <- c("AC-1", "AC-2", "AC-3", "AM-1", "AM-2", "AM-3", "SC-1", "SC-2", "SC-3", "SM-1", "SM-2", "SM-3")
然后对AC组和SC组之间的每一行进行t检验:
Then to run a t-test on every row between AC and SC groups:
library(matrixTests)
> row_t_welch(df[,c("AC-1", "AC-2", "AC-3")], df[,c("SC-1", "SC-2", "SC-3")])
obs.x obs.y obs.tot mean.x mean.y mean.diff var.x var.y stderr df statistic pvalue conf.low conf.high alternative mean.null conf.level
alanine 3 3 6 21770170 13007607 8762563.3 37776970798900 7213669482133 3872580.5 2.736945 2.26271945 0.1171389 -4259692 21784819 two.sided 0 0.95
arginine 3 3 6 6724253 6686479 37774.0 471939373529 298723602417 506840.9 3.807645 0.07452832 0.9443398 -1397926 1473474 two.sided 0 0.95
asparagine 3 3 6 2177893 2295372 -117478.7 913496858185 401148784303 661978.3 3.472571 -0.17746605 0.8690016 -2070931 1835973 two.sided 0 0.95
这篇关于对数据集中每一行的列进行t.test的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文