0

Following my previous question, and with the same example, I would like to modify the groups in the comparison.

Just to remember, I am running a PLS regression by using geomorph.

This function requires two 3D arrays inside it (A1 and A2), as can be seen in the documentation in the previous link.

Basically the function would be:

two.b.pls(A1, A2, iter = 999)

The point is that I am having 8 different 3D matrix arrays and want to run the PLS analysis for any possible combination.

The difference with my previous question is the type of combinations. My arrays are named Group_1, Group_2... Group_8. I wanted earlier to compare Group_1 vs. Group_2 etc, but now I need to compare all combinations as possible by combining the groups, for instance, Group_1 vs. Group_2+Group_3, etc. What I need is to iteratively explore all possible combinations:

two.b.pls(Group_1, Group_2, iter = 999)
two.b.pls(Group 1, Group 3, iter = 999)
two.b.pls(Group 1, Group 2 + Group 3, iter = 999)
...
two.b.pls(Group_7, Group_8, iter = 999)

Minor comment on the combinations required

  • Group_1 vs. Group_2 (and all the combinations 1 by 1)
  • Group_1 vs. Group_2&Group_3 (combined) (and all the combinations 1 by 2)
  • Group_1 vs. Group_2&Group_3&Group_4 (combined) (and all the combinations 1 by 3)
  • ...
  • Group_1 vs. Group_2&Group_3&...&Group_8 (combined)

Another set:

  • Group_1&Group_2 vs. Group_3&Group_4 (combined) (and all the combinations 2 by 2).
  • ...
  • Group_1&Group_2&Group_3&Group_4 vs. Group_5&Group_6
  • ...

Specifications:

  • Group_1 vs. Group_2&Group_3 == Group_2&Group_3 vs. Group_1
  • Group_1 vs. Group_2&Group_3 == Group_1 vs. Group_3&Group_2

3D array as example

Please, download this example. Create Face, Frontal and the other groups with this same dataset. This is the structure of this example num [1:112, 1:3, 1:2]

structure(c(0.0121067537295831, -0.0139329378363627, -0.0128942856218092, 
0.00104644154378343, -0.00114530915378115, -0.000607912100374409, 
0.00151278447681022, 0.00393687340838906, 0.00621298060827974, 
0.00834044621831124, 0.0102092935435389, 0.0115755766569844, 
0.0119258892059719, -0.000396743612783844, 0.00185330841923162, 
0.00435613976082836, 0.00683328855687188, 0.0093417626098382, 
0.0110196500804907, 0.0119338477285669, 0.0122282953973805, 0.00970016937702731, 
0.00502149702279466, 6.43342133087913e-05, -0.00492288184466163, 
-0.00956756783898905, -0.0135047050650378, -0.0162386438360501, 
-0.0182130797956816, -0.0194252658586714, -0.019956478468564, 
-0.0195560089784483, -0.0194376122541402, -0.0189496884694952, 
-0.0188076982059598, -0.0184481816461359, -0.0178127383586681, 
-0.0172051565198613, -0.0162368638401209, -0.0169731739342895, 
-0.017597312625215, -0.0180638542635129, -0.0187144293475924, 
-0.0189884753925375, -0.0189947938350846, -0.0193729916935741, 
-0.0193636556951379, -0.00408430404773437, -0.00664029045820733, 
-0.00892836358740464, -0.0106234245916282, -0.0114889308750888, 
-0.0123253175220186, -0.00239864086586122, -0.00548067506615771, 
-0.00841302150977786, -0.0110588381511544, -0.0125741839608042, 
-0.0132378724743151, -0.0143350819811742, -0.0151336998776877, 
-0.0163526630884662, -0.0177165720198144, -0.0191285732564418, 
-0.019944892329024, -0.0199324039287649, -0.0202185556327263, 
-0.0190696924697975, -0.0173547483350903, -0.0159511654761443, 
-0.0147291258658671, -0.0137233248776445, -0.0203200694852889, 
-0.0184506889252457, -0.0158203449430831, -0.0196266755955667, 
-0.0209659699612106, -0.0205698543045638, -0.0183129557213343, 
-0.0162673719891882, -0.0204944283453325, -0.0168984523237582, 
-0.0172784962660288, -0.0204264167160555, -0.0205440506730952, 
-0.0187558434048595, -0.0152092221518476, -0.0203970113196534, 
-0.0176357135428962, -0.0193952758042404, -0.0198037508808749, 
-0.0203583856042399, -0.0208134667944455, -0.0150492447642772, 
-0.0152602566994186, -0.0191844556313852, -0.0175986034747731, 
-0.016240690926133, -0.017582868965997, 0.000203505568249415, 
-0.00268512269701802, -0.0131454051941203, -0.0125643151022891, 
-0.00511531931380859, -0.00203280827772074, 0.00320590657051683, 
-0.00626169715789532, -0.000668437780500823, -0.019380055733749, 
-0.00446052160041499, -0.0199727808288008, 0.00379018316863347, 
9.57128256764846e-05, 0.0176615324865033, -0.0183982515354167, 
0.021955722685282, -0.0208609214574232, -0.0216249847657198, 
-0.0215160559748617, -0.0202098811465698, -0.0182993603255582, 
-0.0153881733371962, -0.0119849076726351, -0.00826706040213423, 
-0.00411105738294977, 0.0216232694815021, 0.0212626099454012, 
0.0197639705630097, 0.0177457724953735, 0.0151158131692247, 0.0118629656679233, 
0.00798339321420489, 0.00403919891236629, 6.93300838151236e-05, 
-6.59969168921038e-05, -0.000176322187804505, -0.000214470519799677, 
-0.000140138774905899, -6.95124715839799e-05, -6.07152549401866e-05, 
-0.000121751691618514, -0.000190949191335675, -0.00420221113412627, 
-0.0046546857014779, -0.00590803504983574, -0.00742390203482344, 
-0.00955164077502198, -0.0116210651143029, -0.0136246811967233, 
-0.0153597202783619, -0.016520473599831, 0.0158209294861601, 
0.0144805016874292, 0.0127699288459808, 0.0108665503181813, 0.00880050918667468, 
0.00682965250590193, 0.00522906142230795, 0.00398456393406205, 
-0.0196649104672861, -0.0186792178514035, -0.0175459563818717, 
-0.0173203337783667, -0.017526142565625, -0.0179761177459468, 
0.0210626606617924, 0.0197037576394902, 0.0177482641644597, 0.0169824449782621, 
0.0171492142644067, 0.0173799507697275, 0.0175807822049577, 0.0166591521159536, 
0.0144723059446465, 0.0117073399302622, 0.00836867344687509, 
0.00420619178673691, -0.000475512210001711, -0.00513522463858741, 
-0.0096513057207465, -0.0129065159907077, -0.0156326089300706, 
-0.0177622453535592, -0.0183883852720748, 0.00483575892339502, 
0.0109585351836108, 0.0169248421290258, 0.00739883809085566, 
-0.000311708220811525, -0.00496356370416955, 0.012671019230947, 
-0.0162277686974197, 0.00282026501947482, -0.0165380742333304, 
0.0143504752307859, -0.00311853282722531, 0.0013439133424226, 
-0.0110193704417722, -0.0179826972534614, 0.00484808074784459, 
-0.0144688771464215, -0.0091834907261722, -0.00761739209299819, 
-0.00458104863708919, -0.00237537440293526, 0.0177086490258444, 
-0.0176924574890119, 0.00933439446690749, -0.0129201731056937, 
0.017049918790561, 0.0154059190489952, -0.00725653105931065, 
-0.0168114167454652, 0.0173954364309373, -0.0184093777902411, 
-0.00692227950521597, 0.0135066524432826, -0.0200377340229696, 
-0.0192924918628568, 0.0189953682053652, 0.0065920411043607, 
0.0207763069491844, -0.00490970221726531, 0.0070342803679922, 
-0.0299656339772703, -0.00781014999662473, -0.00742460195002254, 
-0.00852379235397777, -0.00770814329844858, -0.0128968190500875, 
-0.0169069261502681, -0.0199654117248723, -0.022833066018448, 
-0.0252541610417436, -0.0273094681489095, -0.0289140751399086, 
-0.029571942393349, -0.0131156818675002, -0.0168783584731727, 
-0.0197229377982092, -0.0222949528843976, -0.0246155933705453, 
-0.0270213460442498, -0.0286139332093845, -0.0298522067412257, 
-0.0306936892402078, -0.0312245434915385, -0.0311144376344305, 
-0.0301558790063451, -0.0283325451325485, -0.0255757771780149, 
-0.0221547869099635, -0.0190107068572344, -0.0170655364750566, 
-0.0085992823261642, -0.00983147288183302, -0.0113196124238418, 
-0.012606851536613, -0.0127016336390267, -0.0121251647817931, 
-0.0114146883856852, -0.010295370079425, -0.00886051780892385, 
-0.00911491927806971, -0.0103800514545884, -0.0113789519665083, 
-0.0120041072141714, -0.0124770003431828, -0.0122568444076323, 
-0.0111393316963931, -0.00980229783172321, -0.00757396956404178, 
-0.00746826930600419, -0.00753079445983466, -0.00752512063965866, 
-0.00748527714103993, -0.00742021392749337, -0.00837814516441945, 
-0.00815176012587459, -0.00787115435263527, -0.00777995325147563, 
-0.00782374041923372, -0.00785425926668388, -0.00967021213344859, 
-0.0118236999226699, -0.0134653423972038, -0.0151978835551724, 
-0.0166422891034175, -0.0171478960392589, -0.016908540157026, 
-0.0172903692640931, -0.016696130263402, -0.0151145154994161, 
-0.0131913922017915, -0.0110621643620987, -0.00906678245018461, 
-0.0157232922354404, -0.0143582255771394, -0.0106592633110684, 
-0.0157301827812935, -0.0137704426813924, -0.0161561119929206, 
-0.0123502372809837, -0.0120404772183872, -0.011205924393612, 
-0.0102236037598132, -0.0125646792086793, -0.00985264666590227, 
-0.0159946450762133, -0.0134197891804638, -0.00988036482173798, 
-0.0129789017819308, -0.0120314631340899, -0.0156257547247481, 
-0.0144193728249802, -0.0120215924211333, -0.0157810207816036, 
-0.00852616880899861, -0.00788467249309025, -0.01356536007035, 
-0.0143121132018561, -0.0083066837625688, -0.0108417415256806, 
-0.0301955476848072, -0.0241434062218676, -0.0122943605337793, 
-0.00775612886007838, -0.0290228197328159, -0.0259454272736183, 
-0.0208885324020887, -0.00853199509771019, -0.021016347241584, 
-0.0174833113107165, -0.0132131738700254, -0.0176623249942278, 
-0.0303206618263515, 0.0127776364853376, -0.0152452243000105, 
-0.0147105852230956, -0.000863874408630801, -0.000209885807261966, 
-0.000331581547817195, 0.000501913076487955, 0.00280122318386634, 
0.00586278420222562, 0.00884948590623061, 0.0110321835800337, 
0.0121504087239398, 0.0126238643777473, -0.00116678400949535, 
0.000309098039122892, 0.00274365192850091, 0.00536277214780085, 
0.00787276641694412, 0.00994463037319537, 0.0117030008228836, 
0.0127848253859643, 0.0102434336168691, 0.00536484343949205, 
0.000262677005211979, -0.00475716562751991, -0.0092856945102185, 
-0.0131277374842598, -0.0160383460447621, -0.0183311058353516, 
-0.0197199548288722, -0.0198559128532786, -0.0198579400897286, 
-0.0200326661395768, -0.0194686440260956, -0.019396466558016, 
-0.0193168686399384, -0.018836091216227, -0.0184061172416965, 
-0.0175896108878106, -0.0182014405947427, -0.0185988791253094, 
-0.0187820813333505, -0.0190165366997682, -0.0190174031419613, 
-0.0192544802580697, -0.0198412223742528, -0.019758033447168, 
-0.00320133118204574, -0.00615476035279051, -0.00937984850181281, 
-0.0119227278138075, -0.0134572187644259, -0.014266707013781, 
-0.00320248689735123, -0.00593510789800099, -0.00913687701439053, 
-0.0121478179417917, -0.0140997195693407, -0.0148624470466123, 
-0.0162853478207419, -0.0169558670069506, -0.0171485021492836, 
-0.0179293084780989, -0.0189236569302454, -0.0200280979178052, 
-0.0201835513258776, -0.0203155932654009, -0.0190617340444641, 
-0.0176470469832613, -0.0167847173642825, -0.0162820395311557, 
-0.0154790628049744, -0.0204204848345239, -0.0188209658483633, 
-0.0175505053387551, -0.0195717677446563, -0.021179463511248, 
-0.0208786568169446, -0.019069560636353, -0.0173645780141257, 
-0.0206194278230603, -0.0182266456298993, -0.0182349521436495, 
-0.0203936090235412, -0.020773374166366, -0.0194125058845639, 
-0.0168809938214606, -0.0205941325139531, -0.0185866626526175, 
-0.0196528192035162, -0.0202849258298999, -0.0210914618991165, 
-0.0210384427398307, -0.0166286873932309, -0.0168834667354705, 
-0.0193889694262657, -0.0180990834649523, -0.0177420142623336, 
-0.018800405940245, 0.000523501896703479, -0.0029261097264044, 
-0.0146321688981797, -0.0145531489430636, -0.00494439965759757, 
-0.00284250195686774, 0.00225485514966812, -0.00595669409878074, 
-0.00185724176389381, -0.019252019103788, -0.00539562893555244, 
-0.0200498867260231, 0.00350463890855844, 0.00100525471102834, 
0.017071734313362, -0.0180797098086776, 0.0212141654154872, -0.0213160923807591, 
-0.0212957182248067, -0.0214662450855171, -0.0199465405608737, 
-0.0182343573421267, -0.0154570896926197, -0.0120083526857707, 
-0.00780487511046493, -0.00339017439997714, 0.0209368593999181, 
0.020588563526874, 0.01913362662387, 0.0174819046855605, 0.0151727297678676, 
0.0120622439286332, 0.00854192437336988, 0.00477549549417729, 
0.000959514886792293, 0.00086367959534621, 0.000733910218756855, 
0.000556459985315933, 0.000368212110990821, 0.000167290914129546, 
-4.96631069309189e-05, -0.000257642952562252, -0.000393942844978405, 
-0.00370568556096609, -0.00423737604809828, -0.00562884468972012, 
-0.00717879773073304, -0.00924653564959142, -0.0113927508863948, 
-0.0134073925813304, -0.015185546576351, -0.0163707369270519, 
0.0152290436102138, 0.0138448530426031, 0.01205637447214, 0.0100153951166161, 
0.00788519518442069, 0.0057407469258699, 0.00409262353568515, 
0.00271017228405623, -0.0198288941212281, -0.0186318757659544, 
-0.0172712409469645, -0.0162335941301901, -0.0164126097070513, 
-0.0173771169051665, 0.020109104090643, 0.0187101345999028, 0.0167105166543032, 
0.0152575143210133, 0.0156886432759352, 0.0165319022262677, 0.0171582245693941, 
0.0162280492120763, 0.0141315427138271, 0.0112493507713461, 0.00773343947298834, 
0.00371546401835653, -0.000659605057928003, -0.00499491955935594, 
-0.0092477714337454, -0.0125017521159196, -0.0151786508806214, 
-0.0173865957635562, -0.0181793392041093, 0.0041939912863222, 
0.0104873358804602, 0.0166973173151379, 0.00671499620031813, 
-0.000587338004291861, -0.00486544441698405, 0.0121136769140914, 
-0.0159046406153872, 0.00191901645180105, -0.0163693673725423, 
0.0139924440541622, -0.00279045214703507, 0.000952406008266023, 
-0.0107832055228765, -0.0179357102553364, 0.00393811167380723, 
-0.0142708811035892, -0.00888102060955728, -0.00737323885894898, 
-0.00446214895976684, -0.00245190564496676, 0.0172248556504535, 
-0.0176757128782511, 0.00863985006836693, -0.0126206510681342, 
0.0166394585376546, 0.014952572452408, -0.00657700188211858, 
-0.0161911771734234, 0.0161059208508412, -0.0178817032028216, 
-0.00629111535992669, 0.0133969495769111, -0.0194959868885208, 
-0.0192009607384602, 0.0181259301303218, 0.00600314788573458, 
0.0197613597582916, -0.0047787506936498, 0.00745721889807159, 
-0.0292291332920766, -0.00812087569534304, -0.00743611172635218, 
-0.00885413422418974, -0.00777937002763539, -0.0126982336492491, 
-0.0169399947077556, -0.0202311363446088, -0.0229456543081723, 
-0.0249878361884412, -0.0269907846948384, -0.0282628825010996, 
-0.0290363401578354, -0.0133268120739664, -0.01728453720012, 
-0.0200285728729878, -0.0223837116395661, -0.0246147905484459, 
-0.0264508728197877, -0.0277270947907398, -0.0286012275090666, 
-0.0296560667420954, -0.0302363823717699, -0.0305095608113487, 
-0.0297799151195076, -0.0281034022184888, -0.0255680591416587, 
-0.0222831548185084, -0.0192325578880546, -0.017138061465351, 
-0.00795388801919832, -0.00948551730810068, -0.0109260623825648, 
-0.0121071142560424, -0.0122356889667297, -0.0119671852632039, 
-0.011443080611894, -0.0103264701670775, -0.00851301891308872, 
-0.00931943327911955, -0.0107854794928235, -0.0117606665554891, 
-0.0122981126741706, -0.0128417290779904, -0.0125396201596298, 
-0.0111872791263485, -0.00944900017887592, -0.00793458358918158, 
-0.00786784513235398, -0.00775618523658388, -0.00778342378570517, 
-0.00773341111129831, -0.00755905201258847, -0.00867994788574915, 
-0.00856767887507999, -0.00839917017153023, -0.00819969133205156, 
-0.00814350875744698, -0.00810097879331339, -0.00978077696715094, 
-0.012345919771051, -0.014314367742374, -0.0158047140930344, 
-0.0171268236313219, -0.0173475238154141, -0.0168777507682366, 
-0.0171907904533275, -0.0168079013041868, -0.0155387350270384, 
-0.0136071221385007, -0.0114788899879373, -0.00928254793674215, 
-0.0159243876515305, -0.0148734801957321, -0.0110391264286132, 
-0.0161052792860213, -0.0134551059432601, -0.0159335986419256, 
-0.0128237221185521, -0.0122201811479621, -0.0109864014492699, 
-0.0100574633053536, -0.0131924278835383, -0.0093236303173408, 
-0.0159954096611316, -0.0132487448657675, -0.00997422292451404, 
-0.0131129555120115, -0.012091752490751, -0.0154676321043934, 
-0.0140171395282845, -0.0116661532536343, -0.015532882738171, 
-0.00873293716563884, -0.00712030247295228, -0.0139380125569914, 
-0.0145631170966823, -0.00831320298976728, -0.0112506766032763, 
-0.0300052299191381, -0.0245186269012974, -0.0126849066479447, 
-0.0077783651484388, -0.0291941982398039, -0.0258349210210429, 
-0.0209999658365151, -0.00885832257691175, -0.0209788315824288, 
-0.0178253431091118, -0.013385631836996, -0.0176249210382204, 
-0.029103552012985), .Dim = c(112L, 3L, 2L), .Dimnames = list(
    c("11", "21", "23", "61", "64", "147", "148", "149", "150", 
    "151", "152", "153", "154", "163", "164", "165", "166", "167", 
    "168", "169", "170", "225", "226", "227", "228", "229", "230", 
    "231", "232", "233", "382", "383", "384", "385", "386", "387", 
    "388", "389", "390", "391", "392", "393", "394", "395", "396", 
    "397", "398", "410", "411", "412", "413", "414", "415", "416", 
    "417", "418", "419", "420", "421", "486", "487", "488", "489", 
    "490", "491", "492", "493", "494", "495", "496", "497", "498", 
    "535", "537", "546", "550", "558", "570", "571", "573", "576", 
    "584", "586", "591", "593", "594", "597", "605", "614", "630", 
    "634", "640", "649", "654", "661", "665", "672", "675", "676", 
    "681", "682", "683", "684", "685", "686", "687", "688", "689", 
    "690", "691", "692", "693"), c("X", "Y", "Z"), c("Homo sapiens", 
    "Homo sapiens")))
antecessor
  • 2,688
  • 6
  • 29
  • 61
  • When you say all possible combinations, Is it only pairwise `+` or include 2 + 3 + 4... – akrun Sep 16 '21 at 16:41
  • 1vs2,1vs3... 1vs2+3 (combined), 1vs2+3+4, 1+2vs3+4+5+6+7+8+9..... – antecessor Sep 16 '21 at 16:42
  • 1
    @akrun please check my updated post where I explain the expected combinations and the rules – antecessor Sep 16 '21 at 17:12
  • Regarding the Rules, does it mean that combination is not needed – akrun Sep 16 '21 at 17:14
  • I do not really follow you @akrun . Running a PLS between one module and another (A1 and A2) is ok, but also running one module with the sum of two / three.. modules that will form A2 (combined). – antecessor Sep 16 '21 at 17:16
  • I meant for your last section of `Rules`. with `==` does it meant that you want both cases i.e. `Group_1 vs. Group_2&Group_3` is same as `Group_2&Group_3 vs. Group_1` except that you are passing the arguments in reverse order in the function – akrun Sep 16 '21 at 17:17
  • Ahhh ok, with those rules I meant to inform that the order is not important (Group1+Group2 is the same of Group2+Group1) and also the comparison of both blocks is the same, so that Group1 vs Group2 is the same as Group2 vs Group1 – antecessor Sep 16 '21 at 17:20
  • You may try `nm1 <- paste0("Group_", 1:8); out <- lapply(2:8, function(i) combn(nm1, i, FUN = function(x) two.b.pls(get(x[1]), Reduce(`+`, mget(x[-1])), iter = 999), simplify = FALSE))` – akrun Sep 16 '21 at 17:30
  • Thanks akrun, remember that the real names of the groups are not Group_1.... but `c(Frontal, Face, Parietal_L, Parietal_R, Temporal_L, Temporal_R, Occipital, Sphenoid)`. If you remember, you answered this yesterday here https://stackoverflow.com/questions/69199807/run-function-in-r-that-requires-two-elements-and-want-to-compare-two-by-two/69199835#69199835 – antecessor Sep 16 '21 at 17:32
  • Then, your `nm1 <- c("Frontal", "Face", "Parietal_L", ..` – akrun Sep 16 '21 at 17:34
  • Thanks for the info, when I write this into RStudio `out <- lapply(2:8, function(i) combn(nm1, i, FUN = function(x) two.b.pls(get(x[1]), Reduce(+, mget(x[-1])), iter = 999), simplify = FALSE))`, it tells me that there is an unexpected token `,`. In the code I see it is placed to the right of the plus symbol (+) in the `Reduce` function. Is that comma necessary? – antecessor Sep 16 '21 at 17:41
  • I put a backquote on the `+`, but here it is dropped when I comment. You may also quote it i.e. `"+"` – akrun Sep 16 '21 at 17:41
  • I do not get you, would you mind answering the question with the code? – antecessor Sep 16 '21 at 17:44
  • Got it @akrun will tell you if it works – antecessor Sep 16 '21 at 17:46
  • Can you add the dput of one more i.e. `Frontal` as well – akrun Sep 16 '21 at 19:13

0 Answers0