r - .I want to do a pairwise.t.test of every column against every column in a dataframe
问题描述
violin plots generated from data frame
The numbers in each column represent localisation of signal relative to another signal inside nuclei of cells. There are 3 treatment conditions and 7 time points of treatment + 2 controls giving a total of 23 columns (see violin plots).
I would like to perform a t-test or a Wilcox t-test with each column to each column. I think I have done it before with a pairwise.t.test(Chr)
. However, the function requires to define how you group your data and I would like to group mine by columns.
I've imported my data:
Chr <- read_csv("Chromocenters-intensity.csv",
+ na = "NA")
Parsed with column specification: cols( .default = col_double() )
And then tried:
pairwise.t.test(Chr, cols())
Error in order(y) : unimplemented type 'list' in 'orderVector1'
pairwise.wilcox.test(Chr,g=cols(Chr))
Error: Some
col_types
are not S3 collector objects: 1
I do not understand what the errors mean.
a normal t.test works fine:
t.test(Chr$S0,Chr$S1)
Welch Two Sample t-test
data: Chr$S0 and Chr$S1 t = 0.85955, df = 154.12, p-value = 0.3914 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -1.920629 4.879370 sample estimates: mean of x mean of y 100.41579 98.93642
but how do I scale it up to include every column by every column?
Thank you
解决方案
您可以使用expand.grid
和apply
。
data <- as.data.frame(sapply(1:23,function(x){runif(470,1,200)}))
names(data) <-c(paste0("S",0:7),paste0("N",1:7),paste0("P",1:7),"TKO")
pairs <- expand.grid(names(data),names(data))
result <- data.frame(pairs,p.val = apply(pairs,1,function(x){t.test(data[x[1]],data[x[2]])$p.val}))
result
Var1 Var2 p.val
1 S0 S0 1.000000000000
2 S1 S0 0.573722556263
3 S2 S0 0.874552764274
4 S3 S0 0.467670724537
5 S4 S0 0.700539636188
6 S5 S0 0.736422364244
7 S6 S0 0.599066387580
8 S7 S0 0.940641228509
9 N1 S0 0.727290760056
10 N2 S0 0.057120608982
11 N3 S0 0.523554180769
12 N4 S0 0.485633891380
不要忘记稍后更正以进行多次测试。
推荐阅读
- django - 在 forms.py 中,当我将“to_field_name”设置为多个列名时,它给了我错误
- javascript - 如何将输入的数字存储在 localStorage 中,然后再加载?
- android - 如何从“lasttime”firebase android中包含的唯一键获取所有数据并在listview android中显示?
- redis - Redis对订阅频道数量的限制?
- python - 如何将掩码应用于保持形状和检索值的 numpy 数组?
- c++ - 如何在 Windows 10 上正确安装 SOCI c++ 库?
- objective-c - UIViewController 的位置
- python - python - 如何在不耗尽python内存的情况下遍历一个大文件?
- asp.net-core - ASP.NET Core 使用没有 Razor 页面的 IdentityUser 绑定外部登录
- ios - 在第一个 VC 的第二个 VC 中显示我的图像时出现问题!相反,第二个 VC 变成了一个新的相机视图