I have the following data frame:
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"
))
What I want to do is to compare the means of mean_fluorescence
after grouping by Conc_factor
and serum_factor
.
To better illustrate, if I run the following code:
library(dplyr)
backgound_dil100 %>% group_by(Conc_factor, serum_factor) %>% summarise(means_mean_fluorescence = mean(mean_fluorescence))
I will get the following table:
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.
For each Conc_factor
I want to compare the means of NEHC
and VL
and see if the means (means_mean_fluorescence
) are statistically different:
If I do:
library(broom)
backgound_dil100 %>% group_by(Conc_factor, serum_factor) %>% do(tidy(t.test(mean_fluorescence~serum_factor, data = .)))
I will get the following error message:
Error in t.test.formula(mean_fluorescence ~ serum_factor, data = .) :
grouping factor must have exactly 2 levels
This partly makes sense to me, after all I have four levels in Conc_factor
. However, I have exactly two levels in serum_factor
and this is actually what I am trying to compare.
Does anyone know a way to apply this multiple t.test for grouping factor with more than two levels?
serum_factor
from thegroup_by()
function. – Roman