0

在此处输入图像描述

我对 R 比较陌生,需要一些数据分析方面的帮助。在附表中,Master Protein Accession 列由一系列蛋白质组成,这些蛋白质在对照(C)、脱水(D)和再水合(R)三种条件下在皮层(C)中增加或减少。每个条件有5个样本;CC(1,2,3,4 和 5),CD(1,2,3,4 和 5)和 CR(1,2,3,4 和 5)。我需要进行 t 检验,以分别比较所有蛋白质的 Cortex 对照(CC1、2、3、4 和 5)样本与 Cortex 脱水(CD1、2、3、4 和 5)样本。这样当我运行代码时,第 1 行 CC1 值对第 1 行 CD 1 值进行 t 检验,第 2 行 CC1 值对第 2 行 CD 1 值进行 t 检验,依此类推。

我试过了

apply(allcor1, function(x){t.test(x[2:12],x[4:14], nchar)})

但它给了我

match.fun(FUN) 中的错误:缺少参数“FUN”,没有默认值

4

1 回答 1

1

您面临的挑战是数据太“宽”:当每个蛋白质至少有 5 个数据点时,您将其表示为一行。

如果你重塑它,问题会变得更容易。在这里,我将使用 tidyr 的pivot 函数以及extract

library(dplyr)
library(tidyr)

# Removing the "sd" columns,
# and renaming first column to "protein" to be easier to work with
longer_data <- yourdata %>%
  select(-starts_with("sd")) %>%
  rename(protein = 1) %>%
  # pivot all columns besides protein into one column condition_sample
  pivot_longer(cols = c(-protein),
               names_to = "condition_sample") %>%
  # Split your CC1, CD2, etc into two columns after the second letter
  separate(condition_sample, c("condition", "sample"), 2) %>%
  # Make them wide again by condition
  pivot_wider(names_from = condition, values_from = value)

如果没有可重现的示例,我无法进行测试,但这应该会给您一个包含proteinconditionsample(1-5) 和value) 列的表格。

此时,数据更灵活地用于统计建模,例如配对 t 检验。我在这里使用 dplyr 对 CC 和 CD 进行分组 t 检验,并使用broom包来整理它。

library(broom)

longer_data %>%
  group_by(protein) %>%
  summarize(tidied_model = list(tidy(t.test(CC, CD, paired = TRUE)))) %>%
  unnest(tidied_model)

这将为您提供每种蛋白质的 、 和 列estimatestatistic置信p.value区间等)。

于 2021-03-25T12:58:33.147 回答