Home > Enterprise >  How to plot automatically ANOVA diagnostic plots (i.e. residuals and fitted values) with a list of
How to plot automatically ANOVA diagnostic plots (i.e. residuals and fitted values) with a list of

Time:10-11

I've stored some Anova statistics in a list through the following code:

Az[i] <- rep(list(matrix(NA,nrow = 2, ncol= 3)), 12)

for (i in 5:ncol(df_join)){
  column <- names(df_join[i])
  Az[i] <- summary(aov(df_join[,i] ~ COND, data = df_join))
  print(column)
  print(Az[i])
}

Where I've obtained the first out of sixteen elements within it = NA and I've attemp to remove them through this code

Az = Az[-which(sapply(Az, is.null))]

If I'm interest to obtain from it the four diagnostic plots of fitted vs residuals value via an automatic method (loops, apply family functions and so on) what an I supposed to do?

To be clearer, if a run a single variable ANOVA for example for P3FCz

variable as follows:

> res.aov <- aov(P3FCz~ COND, data = df_join)
> summary(res.aov)
            Df Sum Sq Mean Sq F value Pr(>F)
COND         2    0.5   0.243   0.012  0.988
Residuals   72 1439.1  19.988 

And I try to extract the four-related diagnostic plots as follows:

plot(res.aov)

I obtain this plots:

enter image description here

I would like to extract them automatically from the list I entered the ANOVA results.

For knowledge I report data here below

> head(dput(df_join))
structure(list(ID = c("01", "01", "01", "04", "04", "04", "06", 
"06", "06", "07", "07", "07", "08", "08", "08", "09", "09", "09", 
"10", "10", "10", "11", "11", "11", "12", "12", "12", "13", "13", 
"13", "15", "15", "15", "16", "16", "16", "17", "17", "17", "18", 
"18", "18", "19", "19", "19", "21", "21", "21", "22", "22", "22", 
"23", "23", "23", "25", "25", "25", "27", "27", "27", "28", "28", 
"28", "30", "30", "30", "44", "44", "44", "46", "46", "46", "49", 
"49", "49"), GR = c("RP", "RP", "RP", "RP", "RP", "RP", "RP", 
"RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", 
"RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", 
"RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", 
"RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", 
"RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", 
"RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", "RP", 
"RP", "RP"), SES = c("V", "V", "V", "V", "V", "V", "V", "V", 
"V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", 
"V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", 
"V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", 
"V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", 
"V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", "V", 
"V", "V"), COND = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 
3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 
1L, 2L, 3L), .Label = c("NEG-CTR", "NEG-NOC", "NEU-NOC"), class = "factor"), 
    P3FCz = c(-11.6312151716924, -11.1438413285935, -3.99591470944713, 
    -0.314155675382471, 0.238885648959708, 5.03749946898385, 
    -0.213621915029167, -2.96032491743069, -1.97168681693488, 
    -2.83109425298642, 1.09291198163802, -6.692991645215, 4.23849942428043, 
    2.9898889629932, 3.5510699900835, 9.57481668808606, 5.4167795618285, 
    1.7067607715475, -6.13036076093477, -2.82955734597919, -2.50672211111696, 
    0.528517585832501, 8.16418133488309, 1.88777321897925, -7.73588468896919, 
    -9.83058052401056, -6.97442700196932, 1.27327945355082, 2.11962397764132, 
    0.524299677616254, -1.83310726842883, 0.658810483381172, 
    -0.261373488428192, 4.37524298634374, 0.625555654900511, 
    3.19617639836154, 0.0405517582137798, -3.29357103412113, 
    -0.381435057304614, -5.73445509910268, -6.1129152355645, 
    -2.45744234877604, 2.95352732001065, 0.527721249096473, 1.91803490989119, 
    -3.46703346467546, -2.40438419043702, -5.35374408162217, 
    -7.27028665849262, -7.1532211375959, -5.39955520296854, 2.65765002364624, 
    0.372495441513391, 6.24433066412776, 1.85698518142405, -0.564454675803529, 
    -0.068523080368053, -7.04782633579147, -4.52263283590558, 
    -6.62134671432544, 4.56661945182626, 3.05859761335498, 2.02997952225347, 
    -6.10523962206958, -0.521871236969702, -3.97851995684846, 
    -2.61258020387919, -4.13974828699279, -3.9210032516844, -4.63162466544638, 
    -4.36762718685405, -6.71005969834916, -4.22719611676328, 
    -0.229916506217565, -5.69725200870146), P3Cz = c(-5.16524399006139, 
    -5.53112490175437, 0.621502123415388, 2.23100741241039, 3.96990710862955, 
    7.75899775608441, -1.30019374375434, -3.59899040898949, -1.92340529575071, 
    2.19344184533265, 5.87900720863083, -5.92378937757888, 2.44958531767688, 
    3.10043497883256, 1.65779442628225, 13.7118233181713, 6.86178446511352, 
    5.31481098188172, -4.13240668697805, 0.162182285588285, 0.142083484505352, 
    5.42592103255673, 14.5496375672716, 4.52018125654081, -2.40677805475299, 
    -5.3832670295207, -1.55736964635117, 3.48359241788107, 4.23167123533126, 
    2.00051785325202, 1.48755216347718, 2.37269462739372, 1.30346907198835, 
    3.89476490634811, 1.87516303240986, 4.36353100770575, 1.9413417416824, 
    -2.22114447555529, -0.015852062711641, -2.76146409940467, 
    -3.51627712447581, 1.01799377568815, 1.74783962328435, 1.1303870721987, 
    2.16398550183836, -3.31557794753334, -1.83920975041768, -6.06703163736936, 
    -8.1566939611461, -9.23030396302541, -4.35545141573936, 0.906302081219897, 
    0.45401759063429, 3.80236232314171, 4.0336657306528, 2.0185967445137, 
    0.835589319243251, -4.6805488231028, -1.20746167339041, -5.50475999427345, 
    4.96594373869991, 4.1349308440931, 3.00187233307059, -5.61465293602653, 
    0.544596077279702, -5.20450410570445, -0.0325220589039272, 
    -2.28038421035601, -2.01375702882255, -1.6547144697087, -0.619979893871085, 
    -4.48258340054462, -1.42281778522059, 2.62315679073783, -4.13736508533355
    ), P3Pz = c(11.8802266972569, 12.1053426662461, 12.955441582096, 
    15.0981004360619, 15.4046229884164, 16.671036999147, 3.13771453335467, 
    -0.0892565159000666, 2.15365554736525, 13.6778924406572, 
    14.3862738306396, 6.86762877785576, 7.47946451329025, 8.93405130318593, 
    8.45962311067909, 23.4166601996042, 15.1868092142896, 9.97183712753913, 
    6.267521071803, 10.142198458411, 10.6320358418368, 12.9998037913548, 
    20.7052065690674, 11.8852179570666, 15.7899796085713, 7.50729833890206, 
    14.3076172484818, 9.93797956768228, 10.7693238464384, 5.04681800218272, 
    5.16656503460515, 7.87875085817396, 2.29899409536951, 10.0135486953849, 
    5.48278706243332, 7.81908431468528, 8.64382513728869, 3.35777109534179, 
    3.47474629234488, 4.35678644331281, 3.47085321062162, 6.56231512354717, 
    4.93825547529124, 7.33985613752315, 6.81966900599588, 6.54487921689425, 
    7.25872117706077, 1.10301223694429, -0.856423579793706, -0.887835692028378, 
    -0.931653372049331, 5.6617683754256, 2.29939831067085, 5.1554825066748, 
    6.59026080217083, 3.0741733363644, 1.80359068950898, 1.63892755704177, 
    3.857933716935, 0.769316188513939, 10.7031907391191, 9.53278894637555, 
    8.01071628743378, 6.04891324234645, 11.1964453850602, 3.46633322373091, 
    14.4393884282958, 11.2339563353478, 7.74933708914689, 7.1182095475238, 
    7.39260082121406, 0.627435381320771, 9.15473202689768, 13.6559037433263, 
    7.14786907480758), LPPearlyFCz = c(-11.7785042972793, -9.14927207125904, 
    -7.58190508537766, -4.01515836011381, -6.60165385653499, 
    -2.02861964460179, 4.46729570509601, 2.54036572774646, 2.22923889930115, 
    -0.883620011106743, -2.63569087592267, -2.0629672230873, 
    1.14544537612393, 2.08056674659401, 0.0422658298956365, 13.2986259796748, 
    5.06669915366333, 3.93467692474742, 0.0229069420708053, 4.31923128857779, 
    0.237726051904304, 1.89972383690448, 3.2371880079134, 0.318100791495115, 
    -8.08292381883298, -5.73174008540523, -15.7998485301436, 
    1.75469999857951, 0.677370118816266, -1.8397955509895, 2.55445787016256, 
    -0.380810453692585, 0.62462329496673, 2.61316333850434, 2.68202480583985, 
    1.76690658846479, 0.148635887703097, -0.958853757041888, 
    -3.17305964093897, -7.82526758429289, -6.58557573679886, 
    -4.39207076049089, 2.36752476749952, 0.594715760553033, -0.29794568443312, 
    -4.5365387390683, 0.196832250811775, -2.70852853745588, 0.498995124872827, 
    0.165171574219401, 0.269498974991661, 0.901948386281446, 
    -2.45955661653299, 1.63525170542944, 0.155897732673534, 1.8491735212703, 
    -0.856727109535223, -1.16182571974245, 1.07658425742917, 
    -2.21433585407388, 4.3385479368043, 4.40588599635354, 0.127710423625772, 
    -6.26956613362656, -1.17658595005389, -7.25886366924741, 
    -0.888293709383838, -2.14177059335841, -2.42141595261389, 
    -2.958120275175, -5.1274001953303, -5.32347488769128, -4.41290818553442, 
    -1.21404719262173, -4.23649270310915), LPPearlyCz = c(-5.96429031525769, 
    -5.10918437158799, -2.81732229625975, -1.43557366487622, 
    -3.14872157912645, 0.160393685024631, 3.52155765271648, 2.10437989449921, 
    2.70693992810407, 5.49897156207812, 5.81171180245335, -1.37301251388987, 
    -0.434363848460157, 2.87987510596148, -1.27152670283348, 
    17.2093269365993, 7.79412746755931, 8.11964589961276, 4.95253363860044, 
    9.50695673265293, 4.15235381401148, 6.1294488368639, 8.01447499455337, 
    0.783414018677801, -1.24197194087055, -0.487178595894761, 
    -9.79031812534203, 4.22150266269492, 4.20139847550095, 0.208005397351335, 
    4.19096721581768, 0.815283302847055, 1.48137456347872, 2.0809543999959, 
    4.35199943309111, 2.84860039832237, 3.05879540677983, 2.11976068962167, 
    -0.269002712326028, -2.77155065610474, -2.59002218694999, 
    0.17928456999128, 2.24515223348079, 1.88805943988563, -0.0920286086411814, 
    -2.00968595029144, 2.59427260100332, -1.27622011197768, 0.588399071755827, 
    -1.43982473126936, 1.96978732491278, -0.338674980283045, 
    -1.86484698930706, -0.0154791822607025, 2.55036185373462, 
    4.42520405730058, -0.599156247027551, 1.60091251589958, 4.7367320574401, 
    -0.192490723623988, 4.8452288234686, 5.71745745981867, 1.02554478706585, 
    -4.5951256708181, 1.1704842909792, -7.42770276334892, 3.15655538248828, 
    -0.639830772856786, -0.345116641695513, -0.0391030568720636, 
    -2.61585906518491, -2.71685194532693, -1.7348388034111, 1.00287124847525, 
    -2.4844653851482), LPPearlyPz = c(8.23981597718437, 9.51261484648731, 
    9.42367409925817, 5.06332653216481, 5.02619159395405, 9.07903916629231, 
    7.56089165217984, 5.49719893790597, 4.91476855238182, 13.0320953572069, 
    10.8414516494484, 5.86927622259489, 3.25309970442897, 4.6847880297099, 
    2.71096740085175, 25.567439566524, 16.3241813617706, 13.0990192799703, 
    11.9200281736866, 14.6901305277101, 9.67397418905514, 10.2974302220899, 
    12.0768070828642, 5.9401530589224, 12.4817579327688, 12.419526465857, 
    1.00612108990875, 9.63063375751153, 10.5631237176538, 3.08031473770521, 
    3.35694102903017, 4.28046277054405, -0.133592200169464, 6.9103658689166, 
    7.64737651416791, 6.75669517393108, 8.5369185279747, 7.08645126073423, 
    4.47409706618326, 4.39617687043259, 3.27924738047746, 6.06169418872804, 
    5.34939694712468, 5.58288092654703, 4.85729686493463, 7.38032829587839, 
    11.7259526759912, 4.95764559864061, 6.24066579989613, 3.49843659402445, 
    4.07498375647916, 3.55732294589389, 1.33918111568512, 0.956782967443242, 
    2.32002496709926, 3.15289777246607, -0.832211906889126, 6.39254974438057, 
    7.0533787627062, 2.97245026797807, 6.23573445580928, 7.6052386193207, 
    2.98791225155534, 3.10850022259445, 8.12060882554471, -0.00459651443883508, 
    13.5899217198075, 9.93070913311253, 8.10285456644801, 5.04464304009428, 
    2.02262615478956, 1.0510618938653, 5.62233873107127, 10.1193593084848, 
    5.87476640145049), LPP1FCz = c(-5.67295796971287, -4.3918290080777, 
    -2.96652960658775, 0.159183652691071, -1.78361184935376, 
    1.97377908783621, 3.17401220482225, 1.60211665164145, 2.27932356239417, 
    2.41479226362682, -0.16792378673807, 1.37236796086306, 1.17012593697048, 
    1.40362599894122, -0.0352287346576431, 12.7528246377871, 
    8.65746780516039, 5.29087810500407, -0.53593239213453, 5.14963479715099, 
    -0.350235251052037, 3.33072474503479, 5.69883686071382, 0.368353479250859, 
    -6.16029227437628, -4.63273873600962, -11.6929994675865, 
    3.03797140797724, 1.9835624834285, -0.105609513369084, 4.42881386089238, 
    2.52938643377794, 0.790366882022175, 2.81796777502117, 4.4468631569674, 
    0.481312527645089, 2.07031118447562, 1.88437037400787, -1.6987207178219, 
    -7.67207306345715, -7.47167401086238, -3.70465330706651, 
    2.76956021356389, 0.170115859759874, -0.117663849819739, 
    -0.318029598802272, 2.5952186989928, 0.495791777472788, 4.23210597331405, 
    7.04880390672238, 4.2493002120623, 1.85997966736632, -1.68653874227364, 
    4.49876374949007, 0.972224468902529, 0.283281427206851, -1.88216552531471, 
    1.93604180609212, 4.36911508867038, 0.396199418616196, 2.119167943437, 
    2.78021097216721, -0.797780510446411, -5.39742090103356, 
    -3.25249602443759, -7.90158650835565, 0.0347244526123614, 
    -0.812966906667064, 0.71379455593, -4.33933038854005, -3.97555431948626, 
    -4.99161397741678, -2.08242541523686, -0.770668513084632, 
    -2.90677423807339), LPP1Cz = c(-0.774461731301161, -0.650009462761383, 
    1.14010250644923, 1.51403741206392, 0.25571835554024, 3.76051565494304, 
    2.74763442988403, 1.09116707485702, 3.29833843753872, 6.55857216695288, 
    7.06029312947389, 0.6053954850232, -0.362612239707932, 2.72729847885135, 
    -1.9659602005953, 16.5065564383967, 9.68783611391578, 9.47863905985504, 
    3.56318544046926, 9.23934223584773, 2.81836003896073, 6.49648576604693, 
    8.95767573723818, 0.0583773785365037, 0.407191700432703, 
    -0.355920498472261, -6.69531720196194, 5.1987079378275, 4.46546567977094, 
    1.95912937005718, 5.56965921078155, 3.02810334275795, 1.73555945138244, 
    2.27122847213408, 5.67690071529437, 1.08565421371063, 4.34660284150802, 
    4.36701185856921, 1.13778488337031, -3.75158080397933, -3.70816720802515, 
    1.11347399164258, 2.71639671748793, 2.04095164097647, -0.0125553251938872, 
    1.81478467865213, 5.51311465032187, 1.84877511449264, 3.72063461781626, 
    5.69841082671879, 6.11884162455143, 0.149229976075454, -1.21110028746356, 
    2.26488777144961, 2.47692422786086, 3.0362097791307, -2.36683956150553, 
    3.71871325602406, 6.88800630791438, 2.16160561308748, 1.85724439689509, 
    3.89090518078692, -0.0613289083097637, -5.10749483497166, 
    -1.91878923633278, -9.5077807770796, 1.97916368442935, 0.0574790574701361, 
    2.05005047140863, -1.76271721053775, -1.9052154727859, -2.94229298615359, 
    -0.080319620782262, 1.67927888371665, -1.30897538037428), 
    LPP1Pz = c(9.99385579756163, 11.1212652173052, 10.6989716871958, 
    3.7899021820967, 4.59413830322224, 8.52123662617732, 6.34418311104072, 
    4.10771312429751, 4.94124365003338, 11.8912196156261, 10.1332638103233, 
    5.33467168055784, 1.04545904874305, 2.86650202467156, 0.456014907516276, 
    22.137894648313, 16.2554496910698, 12.3737995164614, 8.53744587416335, 
    12.0085617194691, 6.44029646492883, 7.92145847204293, 11.0671124200944, 
    3.67962142328031, 13.2326207795965, 10.6863371331174, 1.19234165952119, 
    8.65720626559161, 9.10677414828206, 3.56217081729065, 3.6553384403983, 
    4.92332669673837, -0.955862637061474, 5.12280569940421, 7.96701055540939, 
    4.20070031588935, 7.74511728369855, 6.81338213343676, 3.53005530275895, 
    2.00057785517691, 0.307336075640122, 6.27767029539405, 5.46564282736687, 
    5.31077105909017, 4.21138025611764, 7.33605094723817, 10.9042628775492, 
    4.92138251507151, 6.79108056396903, 7.2234966296861, 4.88215501512899, 
    3.23055080248757, 1.67062187720051, 2.24719486660004, 1.16267428814891, 
    1.66931713099581, -2.63749003510716, 7.26747194148891, 7.40312084435906, 
    3.85188130526715, 3.51813473706825, 4.96827359204273, 1.35864978279665, 
    2.44180972822096, 3.52588208615053, -0.909253908918845, 8.83165959849771, 
    7.35889570568267, 6.3336610852979, 2.60112153747699, 1.24372245314509, 
    -0.385577376783475, 5.16871756657453, 8.83562199570849, 5.14162645294768
    ), LPP2FCz = c(-0.198736254963744, -3.16101041766438, 0.895992279831378, 
    3.11042068112836, 2.27800090558473, 3.83846437952292, 0.70169995101623, 
    1.75290674648806, -1.33916628569866, 6.69246804853767, 4.76363910849669, 
    5.6387334295083, 1.37744267413711, 0.973396686787801, 1.98775658048965, 
    4.70492544977759, 12.1173859570715, 1.04588866129981, -3.27424811388479, 
    3.17906097432267, -0.737029533303028, -0.548079192716476, 
    4.61956745266038, 2.83406431170166, -2.03662250850588, -1.04583230182887, 
    -4.10197843548265, 1.74578985593211, 0.337182270006865, 1.0088582830766, 
    4.7071611424039, 2.91357065338633, 3.41865997847206, 0.112840808931107, 
    3.65320446800974, 1.68471621974079, -1.0319619837514, -1.20400880603756, 
    -0.36155713377909, -3.37172556803734, -4.73982223428082, 
    0.276424687829489, 5.00204428574547, 2.59240054429885, 1.76823718363874, 
    2.89875624368901, 3.26725194423518, 1.68068636794087, 5.10788499683596, 
    10.9438273543919, 8.57093653637002, 4.13801289432792, -0.0919103435752493, 
    7.14602235806343, 0.951033896893375, -3.50828531999296, -0.245809508894366, 
    3.74570635774348, 3.35958383952017, 0.585956207256955, -0.953752628300353, 
    0.198016547101522, -1.52627773487111, -2.5380125964518, -3.87040246779716, 
    -3.39003001417816, -0.0562425891448048, -1.93150124231358, 
    0.14533441948593, -6.30600497325119, -4.05937234925567, -5.38510065662888, 
    3.42195795553968, 4.06645814493399, 1.56160375018352), LPP2Cz = c(2.96437294922766, 
    -2.12913230708907, 2.94619035115619, 3.44844607014521, 3.02403433835637, 
    4.7045767546583, -0.119440173019054, 0.668265457194833, -0.405630185540259, 
    7.32640154038155, 6.75063445570149, 1.59973104216962, 0.716894061961362, 
    1.15587576192688, -0.0113614476558772, 6.44896958389742, 
    10.5178519351064, 3.79329103591037, -0.881527211868382, 4.99936090838488, 
    0.547336389166803, 0.914180881345654, 4.57223746317305, 0.544379787211248, 
    2.10232992003589, 0.364087929362296, -2.01625839730052, 2.92045510618672, 
    0.589250314392448, 2.47669253216776, 3.8646810953732, 1.39548469719622, 
    3.99379121188326, -2.43380575479143, 3.55543459632094, 1.8064338549701, 
    1.32843479186238, 0.998168707936746, 2.22142205600503, -2.57872703851591, 
    -2.47010661770972, 3.56904822058867, 6.29976121968667, 4.17893812674545, 
    2.05354063483883, 2.80516686935069, 5.94481009988668, 2.24420650476028, 
    3.87077739797244, 7.51898916194332, 8.04385138833399, -0.837752514082802, 
    -0.472475810660207, 3.94854087847063, 1.42192692667874, 0.41259599596416, 
    -1.26656454994214, 3.70559987919106, 4.95053154685134, 1.54527082821889, 
    -2.35132492869438, 1.27825568281823, -1.87474139426298, -4.61839904975041, 
    -2.75088839785752, -4.54674069848035, 0.707894602445896, 
    -2.39741431959044, 1.06029338143336, -4.65014144483362, -3.37506398767823, 
    -4.32939541342964, 3.99189974753945, 5.66199164861177, 3.38297407425817
    ), LPP2Pz = c(6.28027312932027, 5.24535230966772, 7.68162285335806, 
    1.08242973465635, 2.99896314000211, 5.36085942954182, 1.22060069796986, 
    0.43007709818575, 0.476667611076957, 8.73650967214853, 7.20593389743811, 
    4.57722295263921, -1.33620384654018, -1.28885901608471, -0.547579465083117, 
    8.11715753014206, 13.3060153720352, 2.03237948843614, 2.88799699943079, 
    5.57921718107867, 0.224312643096751, -1.35508717090199, 5.24004334238142, 
    -0.524427185444798, 9.53009273459153, 5.96824937367958, 0.354581513905486, 
    3.75491412513142, 1.62293479252637, 1.13298849399454, 1.3038251300445, 
    2.21921258546698, -0.982935199970812, -0.87603278792859, 
    4.07313151833664, 2.67697914555442, 2.01133614153975, 0.713386363228727, 
    1.82011380148253, -2.14054013397946, -2.91688430317331, 3.4064978775436, 
    6.970012019096, 4.8346929061964, 4.05060374186422, 3.15582202707403, 
    6.30033458860474, 1.54086695776033, 4.70486363207892, 7.02302307690502, 
    4.86622757700525, 0.519683704125285, 3.22734666260273, 2.66173787497657, 
    -1.38695689767217, -1.01240056675658, -2.24262472628189, 
    6.00477421965019, 4.20438929142231, 1.13798685231667, -0.897086547028692, 
    2.0228708306979, -0.589472259038692, -0.204119654251134, 
    1.34241259142242, 1.9188582401756, 3.75503694959562, 2.11369999794381, 
    2.2112162248386, -2.7719104342547, -3.28212379920159, -2.66041249378004, 
    4.4514507366784, 8.01351241284005, 8.18987741895779)), row.names = c(NA, 
-75L), class = "data.frame")

CodePudding user response:

The issue in the assignment is that the summary output is a list of length 1 with the element being data.frame.

> str(summary(aov(df_join[,5] ~ COND, data = df_join)))
List of 1
 $ :Classes ‘anova’ and 'data.frame':   2 obs. of  5 variables:
  ..$ Df     : num [1:2] 2 72
  ..$ Sum Sq : num [1:2] 0.486 1439.108
  ..$ Mean Sq: num [1:2] 0.243 19.988
  ..$ F value: num [1:2] 0.0122 NA
  ..$ Pr(>F) : num [1:2] 0.988 NA
 - attr(*, "class")= chr [1:2] "summary.aov" "listof"

If we extract the single list element with [[ it works along with the assignment to the list element i.e. [[ instead of [

Az <- vector('list', ncol(df_join) - 5   1)
names(Az) <- names(df_join)[5:ncol(df_join)]
for (nm in names(Az)){
  column <- nm
  Az[[nm]] <- summary(aov(df_join[,nm] ~ COND, data = df_join))[[1]]
  print(column)
  print(Az[nm])
}

-output

> str(Az)
List of 12
 $ P3FCz      :Classes ‘anova’ and 'data.frame':    2 obs. of  5 variables:
  ..$ Df     : num [1:2] 2 72
  ..$ Sum Sq : num [1:2] 0.486 1439.108
  ..$ Mean Sq: num [1:2] 0.243 19.988
  ..$ F value: num [1:2] 0.0122 NA
  ..$ Pr(>F) : num [1:2] 0.988 NA
 $ P3Cz       :Classes ‘anova’ and 'data.frame':    2 obs. of  5 variables:
  ..$ Df     : num [1:2] 2 72
  ..$ Sum Sq : num [1:2] 8.96 1412.91
  ..$ Mean Sq: num [1:2] 4.48 19.62
  ..$ F value: num [1:2] 0.228 NA
  ..$ Pr(>F) : num [1:2] 0.797 NA
 $ P3Pz       :Classes ‘anova’ and 'data.frame':    2 obs. of  5 variables:
  ..$ Df     : num [1:2] 2 72
  ..$ Sum Sq : num [1:2] 81.3 1818
  ..$ Mean Sq: num [1:2] 40.6 25.3
  ..$ F value: num [1:2] 1.61 NA
  ..$ Pr(>F) : num [1:2] 0.207 NA
 $ LPPearlyFCz:Classes ‘anova’ and 'data.frame':    2 obs. of  5 variables:
  ..$ Df     : num [1:2] 2 72
  ..$ Sum Sq : num [1:2] 32.8 1333.7
  ..$ Mean Sq: num [1:2] 16.4 18.5
  ..$ F value: num [1:2] 0.885 NA
  ..$ Pr(>F) : num [1:2] 0.417 NA
 $ LPPearlyCz :Classes ‘anova’ and 'data.frame':    2 obs. of  5 variables:
  ..$ Df     : num [1:2] 2 72
  ..$ Sum Sq : num [1:2] 82.3 1115.6
  ..$ Mean Sq: num [1:2] 41.1 15.5
  ..$ F value: num [1:2] 2.65 NA
  ..$ Pr(>F) : num [1:2] 0.0772 NA
 $ LPPearlyPz :Classes ‘anova’ and 'data.frame':    2 obs. of  5 variables:
  ..$ Df     : num [1:2] 2 72
  ..$ Sum Sq : num [1:2] 161 1252
  ..$ Mean Sq: num [1:2] 80.4 17.4
  ..$ F value: num [1:2] 4.62 NA
  ..$ Pr(>F) : num [1:2] 0.0129 NA
 $ LPP1FCz    :Classes ‘anova’ and 'data.frame':    2 obs. of  5 variables:
  ..$ Df     : num [1:2] 2 72
  ..$ Sum Sq : num [1:2] 34.3 1138.2
  ..$ Mean Sq: num [1:2] 17.1 15.8
  ..$ F value: num [1:2] 1.08 NA
  ..$ Pr(>F) : num [1:2] 0.344 NA
 $ LPP1Cz     :Classes ‘anova’ and 'data.frame':    2 obs. of  5 variables:
  ..$ Df     : num [1:2] 2 72
  ..$ Sum Sq : num [1:2] 73 1073
  ..$ Mean Sq: num [1:2] 36.5 14.9
  ..$ F value: num [1:2] 2.45 NA
  ..$ Pr(>F) : num [1:2] 0.0935 NA
 $ LPP1Pz     :Classes ‘anova’ and 'data.frame':    2 obs. of  5 variables:
  ..$ Df     : num [1:2] 2 72
  ..$ Sum Sq : num [1:2] 130 1182
  ..$ Mean Sq: num [1:2] 65.2 16.4
  ..$ F value: num [1:2] 3.97 NA
  ..$ Pr(>F) : num [1:2] 0.0231 NA
 $ LPP2FCz    :Classes ‘anova’ and 'data.frame':    2 obs. of  5 variables:
  ..$ Df     : num [1:2] 2 72
  ..$ Sum Sq : num [1:2] 2.61 916.68
  ..$ Mean Sq: num [1:2] 1.31 12.73
  ..$ F value: num [1:2] 0.103 NA
  ..$ Pr(>F) : num [1:2] 0.903 NA
 $ LPP2Cz     :Classes ‘anova’ and 'data.frame':    2 obs. of  5 variables:
  ..$ Df     : num [1:2] 2 72
  ..$ Sum Sq : num [1:2] 9.37 755.65
  ..$ Mean Sq: num [1:2] 4.69 10.5
  ..$ F value: num [1:2] 0.446 NA
  ..$ Pr(>F) : num [1:2] 0.642 NA
 $ LPP2Pz     :Classes ‘anova’ and 'data.frame':    2 obs. of  5 variables:
  ..$ Df     : num [1:2] 2 72
  ..$ Sum Sq : num [1:2] 26.8 825.5
  ..$ Mean Sq: num [1:2] 13.4 11.5
  ..$ F value: num [1:2] 1.17 NA
  ..$ Pr(>F) : num [1:2] 0.316 NA

Also, we may do this in lapply

Az1 <- lapply(names(df_join)[5:ncol(df_join)], function(x) 
          summary(aov(df_join[, nm] ~ COND, data = df_join))[[1]])

Update

As there are many plots, redirect it to a pdf to store all the plots in a single file

pdf("file_aov_plots.pdf")
par(mfrow = c(4, 3)) 
Az1 <- lapply(names(df_join)[5:ncol(df_join)], function(x) {
   tmp <- aov(df_join[, nm] ~ COND, data = df_join)
   plot(tmp)
          summary(tmp)[[1]]
})
dev.off()

-output

enter image description here

  • Related