[R] Order output list od TukeyHSD function by "p adj"
Sergio Fonda
sergio.fonda99 at gmail.com
Wed Feb 24 01:21:43 CET 2016
Hello, It's already for several hours that I try to order the list
obtained by the function TukeyHSD according to the variable "p adj"
(in ascending order). Unfortunately, without success.
In addition to following two lines of code, that offer the result but
separately so do not correspond to the desired result, I was unable to
go:
DF.5 <-lapply(DF.4, function (x) as.data.frame(x[c("patient:Fold.fac")]))
DF.6 <- DF.5[[1]][order(DF.5[[1]]$patient.Fold.fac.p.adj),]
Please, I ask some help to answer these two questions:
1) is it possible to get directly from the function TukeyHSD sorted
rows by "p adj"?
2) or, may the output list from TukeyHSD() be processed (e.g. by
lapply) to sort its elements according to "p adj"?
I attach at bottom a simulation of a list obtained from TukeyHSD which
should be ordered by "p adj".
Thanks in advance for any suggestion!
Sergio
#
> dput(DF.4)
list(structure(list(patient = structure(c(12289274.0619908, -2380308.48287107,
-14669582.5448618, -4176414.56676197, -18845997.1116238, -31135271.1736146,
28754962.6907435, 14085380.1458817, 1796106.0838909, 0.186808233632622,
0.938592742253258, 0.0922160074633905), .Dim = 3:4, .Dimnames = list(
c("PARTIAL-COMPLETE", "NO-COMPLETE", "NO-PARTIAL"), c("diff",
"lwr", "upr", "p adj"))), Fold.fac = structure(c(-12697325.7957036,
-23938561.4288898, -1456090.1625174, 0.0268617694934425), .Dim = c(1L,
4L), .Dimnames = list("middle-low", c("diff", "lwr", "upr", "p adj"
))), `patient:Fold.fac` = structure(c(15369710.0977205, 6521960.91205235,
-4695802.45257667, 4502968.78925385, -16007472.7140147, -8847749.18566819,
-20065512.5502972, -10866741.3084667, -31377182.8117352, -11217763.364629,
-2018992.12279849, -22529433.626067, 9198771.24183052, -11311670.261438,
-20510441.5032685, -12927630.9811041, -21775380.1667723, -33016252.8378897,
-23817481.5960591, -44327923.0993277, -37145090.2644928, -48385962.9356102,
-39187191.6937797, -59697633.1970482, -39538213.749942, -30339442.5081115,
-50849884.01138, -19144769.6082929, -39655211.1115614, -48853982.353392,
43667051.1765452, 34819301.990877, 23624647.9327363, 32823419.1745669,
12312977.6712983, 19449591.8931564, 8254937.83501579, 17453709.0768463,
-3056732.42642223, 17102687.020684, 26301458.2625145, 5791016.75924596,
37542312.0919539, 17031870.5886854, 7833099.34685487, 0.632098034657304,
0.986399530577416, 0.997064140940244, 0.997595806079891, 0.590366152539712,
0.948510666498818, 0.330512619876425, 0.883673837089478, 0.0198821692150445,
0.868982868764254, 0.999952294188371, 0.207190890959777, 0.939934594322161,
0.86529009598038, 0.306625751897378), .Dim = c(15L, 4L), .Dimnames = list(
c("PARTIAL:low-COMPLETE:low", "NO:low-COMPLETE:low",
"COMPLETE:middle-COMPLETE:low",
"PARTIAL:middle-COMPLETE:low", "NO:middle-COMPLETE:low",
"NO:low-PARTIAL:low", "COMPLETE:middle-PARTIAL:low",
"PARTIAL:middle-PARTIAL:low",
"NO:middle-PARTIAL:low", "COMPLETE:middle-NO:low", "PARTIAL:middle-NO:low",
"NO:middle-NO:low", "PARTIAL:middle-COMPLETE:middle",
"NO:middle-COMPLETE:middle",
"NO:middle-PARTIAL:middle"), c("diff", "lwr", "upr", "p adj"
)))), .Names = c("patient", "Fold.fac", "patient:Fold.fac"
), class = c("TukeyHSD", "multicomp"), orig.call = aov(formula = abundance ~
patient * Fold.fac, data = x), conf.level = 0.95, ordered = FALSE),
structure(list(patient = structure(c(11084928.3849924, -3790273.898858,
-14875202.2838504, -2565656.8579769, -17440859.1418273, -28525787.5268197,
24735513.6279617, 9860311.34411127, -1224617.0408811, 0.137587687259541,
0.791659281224941, 0.028733410253219), .Dim = 3:4, .Dimnames = list(
c("PARTIAL-COMPLETE", "NO-COMPLETE", "NO-PARTIAL"), c("diff",
"lwr", "upr", "p adj"))), Fold.fac = structure(c(25003217.9525667,
15683872.2084017, 34322563.6967316, 1.59282125378191e-07), .Dim = c(1L,
4L), .Dimnames = list("low-high", c("diff", "lwr", "upr",
"p adj"))), `patient:Fold.fac` = structure(c(6786144.11764773,
-14136208.8235292, 15255972.7140153, 30625682.8117357, 21777933.6260674,
-20922352.9411769, 8469828.59636761, 23839538.6940879, 14991789.5084197,
29392181.5375445, 44761891.6352649, 35914142.4495966, 15369710.0977203,
6521960.91205206, -8847749.18566828, -16711562.4882314, -37633915.4294083,
-8222591.1541805, 7147118.94353984, -1700630.24212845, -44420059.547056,
-15008735.2718282, 360974.825892106, -8486774.35977618, 5913617.6693487,
21283327.767069, 12435578.5814008, -8089695.41243546, -16937444.5981037,
-32307154.6958241, 30283850.7235268, 9361497.78234989, 38734536.5822112,
54104246.6799315, 45256497.4942632, 2575353.66470216, 31948392.4645634,
47318102.5622838, 38470353.3766155, 52870745.4057404, 68240455.5034607,
59392706.3177924, 38829115.6078761, 29981366.4222079, 14611656.3244875,
0.963180623746077, 0.521122619371869, 0.431445001590424,
0.00280179326576413, 0.0869916657428951, 0.113173926329674,
0.908231706478258, 0.0441523667992262, 0.451984651996765,
0.00489618219443777, 9.080596613531e-07, 0.000195613055067767,
0.42174023314457, 0.968747601969596, 0.891038899833401), .Dim = c(15L,
4L), .Dimnames = list(c("PARTIAL:high-COMPLETE:high",
"NO:high-COMPLETE:high",
"COMPLETE:low-COMPLETE:high", "PARTIAL:low-COMPLETE:high",
"NO:low-COMPLETE:high", "NO:high-PARTIAL:high", "COMPLETE:low-PARTIAL:high",
"PARTIAL:low-PARTIAL:high", "NO:low-PARTIAL:high", "COMPLETE:low-NO:high",
"PARTIAL:low-NO:high", "NO:low-NO:high", "PARTIAL:low-COMPLETE:low",
"NO:low-COMPLETE:low", "NO:low-PARTIAL:low"), c("diff", "lwr",
"upr", "p adj")))), .Names = c("patient", "Fold.fac", "patient:Fold.fac"
), class = c("TukeyHSD", "multicomp"), orig.call = aov(formula = abundance ~
patient * Fold.fac, data = x), conf.level = 0.95, ordered = FALSE))
>
More information about the R-help
mailing list