为什么如果不同方式计算,我会得到不同的p值?

huangapple go评论84阅读模式
英文:

Why do I have different p-values if calculated differently?

问题

以下是您要翻译的内容:

  1. 我确实有以下的数据框:
  2. df <- data.frame(
  3. Assay = c("Gene1", "Gene2", "Gene3"),
  4. DT1 = c(1,2,3),
  5. DT2 = c(4,5,6),
  6. DT3 = c(4,5,6),
  7. DT4 = c(0,8,7),
  8. DT5 = c(-1,2,5),
  9. DT6 = c(4,5,3),
  10. DT7 = c(5,2,9),
  11. DT8 = c(0,0,4),
  12. DT9 = c(3,6,2),
  13. DT10 = c(5,9,1),
  14. DT11 = c(2,3,4),
  15. DT12 = c(8,1,6)
  16. )
  17. 并且我想要创建一个包含逐行比较的组的p值的列。前5列(2:6)与接下来的7列(7:13):
  18. # 逐行执行t检验并获取p值
  19. p_values <- apply(df[, 2:6], 1, function(row) {
  20. t_test_result <- t.test(row, df[, 7:13])
  21. t_test_result$p.value
  22. })
  23. # 将p值列添加到数据框中
  24. df$p_values <- p_values
  25. df
  26. 对于第一行,当我使用此脚本时,我得到了`0.09335115`p值,而如果我手动执行:
  27. t.test(c(1,4,4,0,-1),
  28. c(4,5,0,3,5,2,8))
  29. 我得到的p值是`0.1425`
  30. 问题出在哪里?

如果您需要进一步的解释或有其他问题,请随时提出。

英文:

I do have the following dataframe:

  1. df &lt;- data.frame(
  2. Assay = c(&quot;Gene1&quot;, &quot;Gene2&quot;, &quot;Gene3&quot;),
  3. DT1 = c(1,2,3),
  4. DT2 = c(4,5,6),
  5. DT3 = c(4,5,6),
  6. DT4 = c(0,8,7),
  7. DT5 = c(-1,2,5),
  8. DT6 = c(4,5,3),
  9. DT7 = c(5,2,9),
  10. DT8 = c(0,0,4),
  11. DT9 = c(3,6,2),
  12. DT10 = c(5,9,1),
  13. DT11 = c(2,3,4),
  14. DT12 = c(8,1,6)
  15. )

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)

  1. # Perform t-tests row-wise and obtain p-values
  2. p_values &lt;- apply(df[, 2:6], 1, function(row) {
  3. t_test_result &lt;- t.test(row, df[, 7:13])
  4. t_test_result$p.value
  5. })
  6. # Add the p-values column to the dataframe
  7. df$p_values &lt;- p_values
  8. df

For the first row when I use this script I have a p-value of 0.09335115 while if I do it manually:

  1. t.test(c(1,4,4,0,-1),
  2. c(4,5,0,3,5,2,8))

I do have a p-value of 0.1425
What's the issue?

答案1

得分: 2

只返回翻译好的部分:

  1. 只需执行:
  2. p_values <- apply(df[-1], 1, function(row) {
  3. t_test_result <- t.test(row[1:5], row[6:12])
  4. t_test_result$p.value
  5. })
  6. p_values
  7. [1] 0.1425172 0.6840726 0.3266262
英文:

just do:

  1. p_values &lt;- apply(df[-1], 1, function(row) {
  2. t_test_result &lt;- t.test(row[1:5], row[6:12])
  3. t_test_result$p.value
  4. })
  5. p_values
  6. [1] 0.1425172 0.6840726 0.3266262

huangapple
  • 本文由 发表于 2023年6月2日 06:12:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76386043.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定