I am performing a TwoWay ANOVA on some data. When performing the TukeyHSD post-hoc, the following output is given:
diff lwr upr p adj
0.1-0 -7.6925867 -79.28269 63.89752 0.9999650
1-0 9.6882972 -40.93355 60.31014 0.9984060
10-0 4.1546350 -46.46721 54.77648 0.9999945
100-0 7.4767801 -44.70303 59.65659 0.9997580
1000-0 7.9958523 -41.34422 57.33593 0.9994555
10000-0 11.6970426 -42.41999 65.81407 0.9965756
100000-0 -104.3276885 -158.44472 -50.21066 0.0000106
1-0.1 17.3808839 -54.20922 88.97099 0.9930363
10-0.1 11.8472217 -59.74288 83.43732 0.9993756
100-0.1 15.1693668 -57.53073 87.86946 0.9972505
1000-0.1 15.6884389 -55.00112 86.37800 0.9959677
10000-0.1 19.3896293 -54.71317 93.49243 0.9891406
100000-0.1 -96.6351019 -170.73790 -22.53230 0.0038992
10-1 -5.5336622 -56.15551 45.08819 0.9999607
100-1 -2.2115171 -54.39132 49.96829 0.9999999
1000-1 -1.6924450 -51.03252 47.64763 1.0000000
10000-1 2.0087454 -52.10829 56.12578 1.0000000
100000-1 -114.0159857 -168.13302 -59.89895 0.0000019
100-10 3.3221451 -48.85766 55.50195 0.9999990
1000-10 3.8412172 -45.49886 53.18129 0.9999962
10000-10 7.5424076 -46.57462 61.65944 0.9997987
100000-10 -108.4823236 -162.59935 -54.36529 0.0000051
1000-100 0.5190721 -50.41818 51.45632 1.0000000
10000-100 4.2202625 -51.35684 59.79736 0.9999968
100000-100 -111.8044686 -167.38157 -56.22737 0.0000047
10000-1000 3.7011904 -49.21879 56.62117 0.9999982
100000-1000 -112.3235408 -165.24352 -59.40356 0.0000016
100000-10000 -116.0247312 -173.42451 -58.62495 0.0000043
Is there an easy way to separate out the first column into a new data frame, (this is to be the data input for p_stat_manual in a ggplot, which requires the dataframe to be Group 1 | Group 2 | P))
i.e. column 1, row 1 says: 0.1-0
. In the new dataframe how can I have 0.1 in column Group1 and 0 in column Group2 etc...
Currently I am writing by hand as follows, but this is time-consuming and is easy to introduce errors:
group1 <- (c(1, 10, 100, 1000, 10000, 100000, "DMSO", 10, 100, 1000, 10000, 100000, "DMSO", 100, 1000, 10000, 100000, "DMSO", 1000, 10000, 100000, "DMSO", 10000, 100000, "DMSO", 100000, "DMSO", "DMSO"))
group2 <- factor(c(0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 100, 100, 100, 100, 1000, 1000,1000, 10000, 10000, 100000))
CodePudding user response:
Here an example of how to do it, I used the ?TukeyHSD
example.
library(dplyr)
library(tibble)
library(tidyr)
fm1 <- aov(breaks ~ wool tension, data = warpbreaks)
tukey <- TukeyHSD(fm1, "tension", ordered = TRUE)
tukey$tension %>%
as.data.frame() %>%
rownames_to_column() %>%
separate(col = rowname,into = c("var1","var2"))