基于Tukey HSD的合并因子级别

时间:2018-07-18 20:37:42

标签: r anova

我想通过Tuckey HSD的结果合并因子的水平。

因子有16个级别:

levels(aov_dat_mssubclass$MSSubClass)
 [1]  "20"  "30"  "40"  "45"  "50"  "60"  "70"  "75"  "80"  "85"  "90"  "120" 
 [13] "150" "160" "180" "190"

如果执行Tukey HSD,则会得到以下结果:

aov_mssubclass = aov(SalePrice~MSSubClass, aov_dat_mssubclass)

thsd_mssubclass = TukeyHSD(aov_mssubclass)  

library(knitr)
kable(head(thsd_mssubclass))

|        |      diff|        lwr|       upr|     p adj|
|:-------|---------:|----------:|---------:|---------:|
|180-30  | 0.0679407| -0.3096859| 0.4455673| 0.9999992|
|45-30   | 0.1452240| -0.2038366| 0.4942847| 0.9861887|
|190-30  | 0.3010442|  0.0569789| 0.5451094| 0.0027207|
|90-30   | 0.3471111|  0.1421648| 0.5520574| 0.0000011|
|160-30  | 0.3733815|  0.1789057| 0.5678574| 0.0000000|
|50-30   | 0.3807276|  0.2173256| 0.5441297| 0.0000000|

现在,我想结合那些基于0.01显着性水平而没有不同的水平。例如,我将合并前两行(将“ 180”,“ 45”和“ 30”合并为“ A”)。问题在于,不仅对必须在显着性水平0.01上匹配(180 -30/45 -30),而且其他因子水平也要匹配(180和45)。如果因子水平不错,要找到这些组合将非常困难。

在r中有没有办法解决这个问题?

as.data.frame(thsd_mssubclass$MSSubClass) %>% dput()

structure(list(diff = c(0.0679407080913705, 0.145224032594887, 
0.301044185284731, 0.347111111216851, 0.373381540043273, 0.380727619976023, 
0.436613403669551, 0.462057512926854, 0.530235822622267, 0.588015730511071, 
0.618978799478771, 0.630970957972266, 0.737745430917498, 0.906165700586902, 
0.0772833245035169, 0.23310347719336, 0.27917040312548, 0.305440831951902, 
0.312786911884652, 0.36867269557818, 0.394116804835484, 0.462295114530896, 
0.5200750224197, 0.551038091387401, 0.563030249880896, 0.669804722826127, 
0.838224992495531, 0.155820152689843, 0.201887078621963, 0.228157507448385, 
0.235503587381135, 0.291389371074663, 0.316833480331967, 0.385011790027379, 
0.442791697916183, 0.473754766883884, 0.485746925377379, 0.59252139832261, 
0.760941667992014, 0.04606692593212, 0.0723373547585417, 0.079683434691292, 
0.13556921838482, 0.161013327642124, 0.229191637337536, 0.28697154522634, 
0.317934614194041, 0.329926772687536, 0.436701245632767, 0.605121515302171, 
0.0262704288264217, 0.033616508759172, 0.0895022924526998, 0.114946401710004, 
0.183124711405416, 0.24090461929422, 0.271867688261921, 0.283859846755416, 
0.390634319700647, 0.559054589370051, 0.00734607993275027, 0.0632318636262781, 
0.088675972883582, 0.156854282578994, 0.214634190467798, 0.245597259435499, 
0.257589417928994, 0.364363890874225, 0.532784160543629, 0.0558857836935278, 
0.0813298929508317, 0.149508202646244, 0.207288110535048, 0.238251179502749, 
0.250243337996244, 0.357017810941475, 0.525438080610879, 0.0254441092573039, 
0.0936224189527159, 0.15140232684152, 0.182365395809221, 0.194357554302716, 
0.301132027247947, 0.469552296917351, 0.0681783096954121, 0.125958217584216, 
0.156921286551917, 0.168913445045412, 0.275687917990643, 0.444108187660047, 
0.0577799078888042, 0.0887429768565049, 0.10073513535, 0.207509608295231, 
0.375929877964635, 0.0309630689677007, 0.0429552274611957, 0.149729700406427, 
0.318149970075831, 0.011992158493495, 0.118766631438726, 0.28718690110813, 
0.106774472945231, 0.275194742614636, 0.168420269669404), lwr = c(-0.309685856297917, 
-0.20383660545705, 0.0569789281268702, 0.142164847580148, 0.178905688110185, 
0.217325552412349, -0.137345009448975, 0.178638489488477, 0.333234917405307, 
0.389206357585563, 0.476239262297527, 0.321301436275043, 0.557836938356105, 
0.757113872487482, -0.40056960689645, -0.174410871955045, -0.106190552329222, 
-0.0744551432773916, -0.0521792929814961, -0.291576011349635, 
-0.038117434735006, 0.0811003458540194, 0.137942503817384, 0.194843382716663, 
0.113146589721402, 0.297155879132726, 0.479454115095909, -0.225374615987033, 
-0.15552664928133, -0.123357014158027, -0.0998198946465453, -0.352947390180367, 
-0.0906808688164385, 0.0320940112581785, 0.0888612405123049, 
0.147999985814134, 0.0595582176629771, 0.248851982152365, 0.432371965531693, 
-0.209802364151775, -0.175224717486969, -0.144295042653017, -0.458479923201066, 
-0.161155052985391, -0.0203589172314597, 0.0359908898115743, 
0.10855290987366, -0.0155603259103405, 0.200410771163092, 0.391386702767641, 
-0.182827875426874, -0.146942289255733, -0.489574130695437, -0.178698939991968, 
-0.0283241015796785, 0.0277698951886967, 0.109769510199305, -0.0351957228945919, 
0.195011443859869, 0.391371282758204, -0.161234362429472, -0.512222209130615, 
-0.197759836172693, -0.044462598281158, 0.0115472715734668, 0.096957744710528, 
-0.0548435229257535, 0.179739419152106, 0.378072889710706, -0.509823301041267, 
-0.184987307786759, -0.0219790132569949, 0.0337263770654374, 
0.133498690097207, -0.0438548109780901, 0.205473842873937, 0.412234918014945, 
-0.585827414465304, -0.482689900474604, -0.425530684547523, -0.377724872220952, 
-0.429518832119773, -0.269563687264707, -0.0921798281450974, 
-0.219977850018248, -0.163437329181204, -0.097242422894059, -0.205412386808081, 
-0.00106410353826164, 0.186346547409987, -0.147726287388113, 
-0.0631853121777508, -0.213275759687653, 0.0202272139548308, 
0.218056267142752, -0.123302984056315, -0.272193391937779, -0.039454086786359, 
0.158025371401325, -0.271147490833055, -0.0102291593774373, 0.206630735531846, 
-0.196805090335564, -0.0111790219061828, 0.0324725369433648), 
    upr = c(0.445567272480658, 0.494284670646825, 0.545109442442591, 
    0.552057374853553, 0.56785739197636, 0.544129687539697, 1.01057181678808, 
    0.745476536365232, 0.727236727839226, 0.786825103436579, 
    0.761718336660016, 0.94064047966949, 0.91765392347889, 1.05521752868632, 
    0.555136255903484, 0.640617826341766, 0.664531358580182, 
    0.685336807181195, 0.677753116750801, 1.028921402506, 0.826351044405974, 
    0.843489883207773, 0.902207541022016, 0.907232800058139, 
    1.01291391004039, 1.04245356651953, 1.19699586989515, 0.53701492136672, 
    0.559300806525257, 0.579672029054797, 0.570827069408816, 
    0.935726132329693, 0.724347829480372, 0.73792956879658, 0.796722155320062, 
    0.799509547953634, 0.911935633091781, 0.936190814492856, 
    1.08951137045234, 0.301936216016015, 0.319899427004053, 0.303661912035601, 
    0.729618359970706, 0.483181708269639, 0.478742191906531, 
    0.537952200641105, 0.527316318514422, 0.675413871285412, 
    0.672991720102442, 0.818856327836701, 0.235368733079718, 
    0.214175306774077, 0.668578715600837, 0.408591743411975, 
    0.39457352439051, 0.454039343399743, 0.433965866324537, 0.602915416405423, 
    0.586257195541425, 0.726737895981899, 0.175926522294973, 
    0.638685936383171, 0.375111781939857, 0.358171163439146, 
    0.41772110936213, 0.39423677416047, 0.570022358783741, 0.548988362596345, 
    0.687495431376553, 0.621594868428322, 0.347647093688422, 
    0.320995418549482, 0.380849844004658, 0.343003668908291, 
    0.544341486970577, 0.508561779009013, 0.638641243206813, 
    0.636715632979912, 0.669934738380036, 0.728335338230563, 
    0.742455663839394, 0.818233940725205, 0.871827741760601, 
    1.0312844219798, 0.356334469409072, 0.415353764349636, 0.411084995997893, 
    0.543239276898905, 0.552439939519548, 0.701869827910108, 
    0.263286103165721, 0.240671265890761, 0.414746030387652, 
    0.394792002635631, 0.533803488786519, 0.185229121991716, 
    0.35810384686017, 0.338913487599213, 0.478274568750338, 0.295131807820045, 
    0.24776242225489, 0.367743066684415, 0.410354036226027, 0.561568507135454, 
    0.304368002395444), `p adj` = c(0.999999181040429, 0.986188743789841, 
    0.00272070247438971, 1.1067965176581e-06, 9.99876270668665e-09, 
    0, 0.381296178023648, 3.74790721968665e-06, 0, 0, 0, 6.9874084296373e-10, 
    0, 0, 0.999999797675824, 0.830712538009891, 0.469526845821558, 
    0.286771643232534, 0.192049493858192, 0.854781160060527, 
    0.119816510146092, 0.00363584463340194, 0.000403083223308176, 
    1.74052220063281e-05, 0.00210329533846199, 1.36815219042852e-07, 
    0, 0.98830112897335, 0.843612769473717, 0.66126972225992, 
    0.525766765256311, 0.97076305349436, 0.3430518282089, 0.0177256810405119, 
    0.00211640657743706, 8.76385725693263e-05, 0.0096401938954167, 
    6.06637432509771e-07, 0, 0.99999917355028, 0.999666730725907, 
    0.997078223945873, 0.999982963885388, 0.93388039688878, 0.112763228132348, 
    0.00919740731000851, 2.89491910098194e-05, 0.0794693647843098, 
    4.7201295760857e-08, 0, 0.999999993099237, 0.999998722285286, 
    0.999999889024167, 0.99229529301498, 0.178399713861488, 0.0108770731279192, 
    1.52664635733046e-06, 0.145959931697183, 1.78397163708155e-09, 
    0, 1, 0.99999999888119, 0.999355945523407, 0.339366012267686, 
    0.026548571516849, 2.46617778854041e-06, 0.247325680946513, 
    3.0289803998329e-09, 0, 0.999999999738737, 0.999447937367166, 
    0.170016952680963, 0.00468364759299456, 5.22915044598449e-13, 
    0.201763095990914, 0, 0, 1, 0.999999785443409, 0.999905917285777, 
    0.99887113494108, 0.999308890289821, 0.901211010191284, 0.226844622588068, 
    0.999973340464584, 0.979124584757051, 0.73673277647614, 0.971308354296563, 
    0.0520873920446344, 6.20832786735193e-07, 0.999787002313376, 
    0.807643468614558, 0.99904167659138, 0.0143835307565798, 
    0, 0.999996636157742, 0.99999997930695, 0.312727702747554, 
    2.23910556762519e-09, 1, 0.110401557331005, 0, 0.997408855846029, 
    0.0748611290161301, 0.00252005438458835)), class = "data.frame", row.names = c("180-30", 
"45-30", "190-30", "90-30", "160-30", "50-30", "40-30", "85-30", 
"70-30", "80-30", "20-30", "75-30", "120-30", "60-30", "45-180", 
"190-180", "90-180", "160-180", "50-180", "40-180", "85-180", 
"70-180", "80-180", "20-180", "75-180", "120-180", "60-180", 
"190-45", "90-45", "160-45", "50-45", "40-45", "85-45", "70-45", 
"80-45", "20-45", "75-45", "120-45", "60-45", "90-190", "160-190", 
"50-190", "40-190", "85-190", "70-190", "80-190", "20-190", "75-190", 
"120-190", "60-190", "160-90", "50-90", "40-90", "85-90", "70-90", 
"80-90", "20-90", "75-90", "120-90", "60-90", "50-160", "40-160", 
"85-160", "70-160", "80-160", "20-160", "75-160", "120-160", 
"60-160", "40-50", "85-50", "70-50", "80-50", "20-50", "75-50", 
"120-50", "60-50", "85-40", "70-40", "80-40", "20-40", "75-40", 
"120-40", "60-40", "70-85", "80-85", "20-85", "75-85", "120-85", 
"60-85", "80-70", "20-70", "75-70", "120-70", "60-70", "20-80", 
"75-80", "120-80", "60-80", "75-20", "120-20", "60-20", "120-75", 
"60-75", "60-120"))

0 个答案:

没有答案