英文:
Why do I have different p-values if calculated differently?
问题
以下是您要翻译的内容:
我确实有以下的数据框:
df <- data.frame(
Assay = c("Gene1", "Gene2", "Gene3"),
DT1 = c(1,2,3),
DT2 = c(4,5,6),
DT3 = c(4,5,6),
DT4 = c(0,8,7),
DT5 = c(-1,2,5),
DT6 = c(4,5,3),
DT7 = c(5,2,9),
DT8 = c(0,0,4),
DT9 = c(3,6,2),
DT10 = c(5,9,1),
DT11 = c(2,3,4),
DT12 = c(8,1,6)
)
并且我想要创建一个包含逐行比较的组的p值的列。前5列(2:6)与接下来的7列(7:13):
# 逐行执行t检验并获取p值
p_values <- apply(df[, 2:6], 1, function(row) {
t_test_result <- t.test(row, df[, 7:13])
t_test_result$p.value
})
# 将p值列添加到数据框中
df$p_values <- p_values
df
对于第一行,当我使用此脚本时,我得到了`0.09335115`的p值,而如果我手动执行:
t.test(c(1,4,4,0,-1),
c(4,5,0,3,5,2,8))
我得到的p值是`0.1425`
问题出在哪里?
如果您需要进一步的解释或有其他问题,请随时提出。
英文:
I do have the following dataframe:
df <- data.frame(
Assay = c("Gene1", "Gene2", "Gene3"),
DT1 = c(1,2,3),
DT2 = c(4,5,6),
DT3 = c(4,5,6),
DT4 = c(0,8,7),
DT5 = c(-1,2,5),
DT6 = c(4,5,3),
DT7 = c(5,2,9),
DT8 = c(0,0,4),
DT9 = c(3,6,2),
DT10 = c(5,9,1),
DT11 = c(2,3,4),
DT12 = c(8,1,6)
)
And I would like to create a column that will contain p-values for groups compared row by row. First 5 columns (2:6) versus Next 7 columns (7:13)
# Perform t-tests row-wise and obtain p-values
p_values <- apply(df[, 2:6], 1, function(row) {
t_test_result <- t.test(row, df[, 7:13])
t_test_result$p.value
})
# Add the p-values column to the dataframe
df$p_values <- p_values
df
For the first row when I use this script I have a p-value of 0.09335115
while if I do it manually:
t.test(c(1,4,4,0,-1),
c(4,5,0,3,5,2,8))
I do have a p-value of 0.1425
What's the issue?
答案1
得分: 2
只返回翻译好的部分:
只需执行:
p_values <- apply(df[-1], 1, function(row) {
t_test_result <- t.test(row[1:5], row[6:12])
t_test_result$p.value
})
p_values
[1] 0.1425172 0.6840726 0.3266262
英文:
just do:
p_values <- apply(df[-1], 1, function(row) {
t_test_result <- t.test(row[1:5], row[6:12])
t_test_result$p.value
})
p_values
[1] 0.1425172 0.6840726 0.3266262
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论