1

我有以下数据框:

structure(list(Name = c("BACKGROUND_VL_1_100_H", "BACKGROUND_VL_1_100_G", 
"BACKGROUND_VL_1_100_F", "BACKGROUND_VL_1_100_E", "BACKGROUND_VL_1_100_D", 
"BACKGROUND_VL_1_100_C", "BACKGROUND_VL_1_100_B", "BACKGROUND_VL_1_100_A", 
"BACKGROUND_VL_05_100_H", "BACKGROUND_VL_05_100_G", "BACKGROUND_VL_05_100_F", 
"BACKGROUND_VL_05_100_E", "BACKGROUND_VL_05_100_D", "BACKGROUND_VL_05_100_C", 
"BACKGROUND_VL_05_100_B", "BACKGROUND_VL_05_100_A", "BACKGROUND_VL_025_100_H", 
"BACKGROUND_VL_025_100_G", "BACKGROUND_VL_025_100_F", "BACKGROUND_VL_025_100_E", 
"BACKGROUND_VL_025_100_D", "BACKGROUND_VL_025_100_C", "BACKGROUND_VL_025_100_B", 
"BACKGROUND_VL_025_100_A", "BACKGROUND_VL_0125_100_F", "BACKGROUND_VL_0125_100_E", 
"BACKGROUND_VL_0125_100_D", "BACKGROUND_VL_0125_100_C", "BACKGROUND_VL_0125_100_B", 
"BACKGROUND_VL_0125_100_A", "BACKGROUND_NEHC_0125_100_A", "BACKGROUND_NEHC_0125_100_B", 
"BACKGROUND_NEHC_0125_100_C", "BACKGROUND_NEHC_0125_100_D", "BACKGROUND_NEHC_0125_100_E", 
"BACKGROUND_NEHC_0125_100_F", "BACKGROUND_NEHC_0125_100_G", "BACKGROUND_NEHC_025_100_G", 
"BACKGROUND_NEHC_025_100_F", "BACKGROUND_NEHC_025_100_D", "BACKGROUND_NEHC_025_100_C", 
"BACKGROUND_NEHC_025_100_B", "BACKGROUND_NEHC_025_100_A", "BACKGROUND_NEHC_05_100_C", 
"BACKGROUND_NEHC_05_100_H", "BACKGROUND_NEHC_05_100_G", "BACKGROUND_NEHC_05_100_F", 
"BACKGROUND_NEHC_05_100_D", "BACKGROUND_NEHC_05_100_C", "BACKGROUND_NEHC_05_100_B", 
"BACKGROUND_NEHC_05_100_A"), ID = c(24, 23, 22, 21, 20, 19, 18, 
17, 24, 23, 22, 21, 20, 19, 18, 17, 24, 23, 22, 21, 20, 19, 18, 
17, 14, 13, 12, 11, 10, 9, 7, 6, 5, 4, 3, 2, 1, 21, 20, 19, 18, 
17, 16, 15, 23, 22, 21, 20, 19, 18, 17), Conc_factor = c(1, 1, 
1, 1, 1, 1, 1, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.25, 
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.125, 0.125, 0.125, 
0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 
0.125, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.5, 0.5, 0.5, 0.5, 
0.5, 0.5, 0.5, 0.5), Peptide_factor = c("Background", "Background", 
"Background", "Background", "Background", "Background", "Background", 
"Background", "Background", "Background", "Background", "Background", 
"Background", "Background", "Background", "Background", "Background", 
"Background", "Background", "Background", "Background", "Background", 
"Background", "Background", "Background", "Background", "Background", 
"Background", "Background", "Background", "Background", "Background", 
"Background", "Background", "Background", "Background", "Background", 
"Background", "Background", "Background", "Background", "Background", 
"Background", "Background", "Background", "Background", "Background", 
"Background", "Background", "Background", "Background"), serum_factor = c("VL", 
"VL", "VL", "VL", "VL", "VL", "VL", "VL", "VL", "VL", "VL", "VL", 
"VL", "VL", "VL", "VL", "VL", "VL", "VL", "VL", "VL", "VL", "VL", 
"VL", "VL", "VL", "VL", "VL", "VL", "VL", "NEHC", "NEHC", "NEHC", 
"NEHC", "NEHC", "NEHC", "NEHC", "NEHC", "NEHC", "NEHC", "NEHC", 
"NEHC", "NEHC", "NEHC", "NEHC", "NEHC", "NEHC", "NEHC", "NEHC", 
"NEHC", "NEHC"), dilution_factor = c(100, 100, 100, 100, 100, 
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 
100, 100, 100, 100, 100, 100, 100), mean_fluorescence = c(17399.95703125, 
17554.48828125, 17206.38671875, 17961.63671875, 17531.802734375, 
18382.783203125, 17886.12890625, 17760.802734375, 18121.12109375, 
18030.228515625, 18016.548828125, 17790.91015625, 17892.90625, 
18479.763671875, 17880.212890625, 17876.267578125, 17338.04296875, 
17497.556640625, 17575.44140625, 16903.13671875, 17713.2109375, 
18043.900390625, 17703.81640625, 17848.75, 16977.166015625, 17366.0390625, 
16957.97265625, 16449.564453125, 16725.259765625, 16712.982421875, 
19181.806640625, 18695.166015625, 18568.4453125, 18718.474609375, 
18195.10546875, 17979.955078125, 17738.958984375, 19387.955078125, 
19103.15625, 18983.361328125, 18790.640625, 18412.255859375, 
18014.478515625, 17973.759765625, 19574.638671875, 17291.458984375, 
18660.455078125, 18704.978515625, 17241.298828125, 18838.076171875, 
17792.349609375)), row.names = c(NA, -51L), class = c("tbl_df", 
"tbl", "data.frame"), .Names = c("Name", "ID", "Conc_factor", 
"Peptide_factor", "serum_factor", "dilution_factor", "mean_fluorescence"
))

我想要做的是比较mean_fluorescence分组后的手段Conc_factorserum_factor

为了更好地说明,如果我运行以下代码:

library(dplyr)    
backgound_dil100 %>% group_by(Conc_factor, serum_factor) %>% summarise(means_mean_fluorescence = mean(mean_fluorescence))

我会得到下表:

  Conc_factor serum_factor means_mean_fluorescence
        <dbl> <chr>                          <dbl>
1       0.125 NEHC                          18440.
2       0.125 VL                            16865.
3       0.250 NEHC                          18782.
4       0.250 VL                            17578.
5       0.500 NEHC                          18260.
6       0.500 VL                            18011.
7       1.00  VL                            17710.

对于每个Conc_factor我想比较 和 的均值NEHCVL查看均值 ( means_mean_fluorescence) 是否在统计上不同:

如果我做:

library(broom)
backgound_dil100 %>% group_by(Conc_factor, serum_factor) %>% do(tidy(t.test(mean_fluorescence~serum_factor, data = .)))

我将收到以下错误消息:

Error in t.test.formula(mean_fluorescence ~ serum_factor, data = .) : 
  grouping factor must have exactly 2 levels

这部分对我来说是有道理的,毕竟我在Conc_factor. 但是,我正好有两个级别,serum_factor这实际上是我想要比较的。

有谁知道将这个多重 t.test 应用于具有两个以上级别的分组因子的方法?

4

1 回答 1

1

首先,您缺少如下所示的值:

 table(backgound_dil100$serum_factor,backgound_dil100$Conc_factor)

       0.125 0.25 0.5 1
  NEHC     7    6   8 0
  VL       6    8   8 8

因此,删除它们。此外,正如 Jimbou 建议的那样,根据需要serum_factor从.group_by()t.test()

你会得到:

backgound_dil100[-c(1:8),] %>%
  group_by(Conc_factor) %>% 
  do(tidy(t.test(mean_fluorescence~serum_factor, data = .)))
于 2018-03-20T12:00:03.457 回答