ARDL model in R - r

I have this data frame on which I want to apply the ARDL model but every time I run it, it gives me an error. If anyone could please help me or point out what I am doing wrong would be highly appreciated. Error:'list' object cannot be coerced to type 'double' If I remove the prediction part of the code in the loop out then it runs otherwise no.
Data:
structure(list(Industrialproduction = c(1.65801981343852, 1.79541527049647,
-0.0326429293424051, 0.104752527715549, -0.992082392187777, -2.26823002723453,
-2.33809212404366, -3.02972688245404, -2.14713572609871, -1.29947561814794,
0.104752527715549, 0.228175565411677, 0.305023871901719, 0.218860619170459,
0.216531882610155, 0.139683576120113, 0.25146293101472, 0.249134194454415,
0.626389517223712, 1.13405408737005, 0.58214352257793, -0.0629165046263609,
-0.619484542539089, -0.652086854383349, 0.591458468819148, 2.0259601899666,
1.73021064680795, 0.561184893535192, 0.207216936368938, -0.489075295162048
), Householdconsumption = c(-1.5532531908672, -1.52804903107083,
-1.51957878064746, -1.50015918211582, -1.4800165134261, -1.47578138821441,
-1.46235294242126, -1.45274643889231, -1.43477298067686, -1.42299726667364,
-1.41225451003912, -1.39892935998284, -1.38694705450587, -1.37909657850372,
-1.36525494976309, -1.34924411054818, -1.33457611591258, -1.32538279533112,
-1.31143787085362, -1.30255443748276, -1.29181168084824, -1.27838323505509,
-1.27476788426463, -1.25586476441735, -1.24336598025603, -1.22942105577852,
-1.21051793593124, -1.1953334626113, -1.17581056834279, -1.15804370160108
), Investmentgrowth = c(1.47348593810751, 2.17792802452104, 2.57620375293532,
3.11977876989162, 2.03003410582649, 1.238671909303, 0.670447905897604,
0.0127091622297187, -0.222104866574793, -0.1974558801257, -0.215618291193452,
-0.31551155206609, 0.0762776009668517, 0.37206543835596, 0.593906316397791,
0.867639797490343, 1.12321086751514, 0.272172177483322, 0.191738642754705,
0.619852617923151, 0.675637166202676, 1.31910544403161, 1.23348264899792,
0.702880782804304, 1.61748791157326, 0.308496999618827, 0.395417109728784,
0.290334588551075, -0.659300047277115, -0.117022345397083), ConsumerPriceIndex = c(-2.03033282052684,
-1.98504568168304, -1.91626049909952, -1.88507218649954, -1.82055937550506,
-1.75220143008044, -1.72955786065854, -1.7026419196476, -1.65991820375721,
-1.60053223866958, -1.57447077197644, -1.53473771619839, -1.51166690961758,
-1.46381634782035, -1.46381634782035, -1.45057199589433, -1.43860935544502,
-1.40400314557381, -1.3800778646752, -1.36341561547795, -1.35188021218754,
-1.31727400231633, -1.29933004164237, -1.28394950392183, -1.24549815962049,
-1.19380246339312, -1.19380246339312, -1.18183982294381, -1.16816823385889,
-1.14595190159589), Employment = c(-1.02390309005026, -0.997493370038682,
-0.974856467171615, -0.96353801573808, -0.978629284316127, -1.00881182147222,
-1.07294971292891, -1.14840605581914, -1.21631676442034, -1.28045465587703,
-1.32950127875568, -1.38232071877884, -1.41250325593493, -1.45023142738004,
-1.5030508674032, -1.55587030742636, -1.58228002743794, -1.56341594171538,
-1.49173241596967, -1.43136734165749, -1.38232071877884, -1.34081973018921,
-1.30686437588861, -1.2691362044435, -1.24272648443192, -1.22386239870936,
-1.20499831298681, -1.19745267869778, -1.18990704440876, -1.17481577583072
), Unemploymentrate = c(-0.815370914670033, -0.815370914670033,
-0.772756573338144, -0.687527890674367, -0.517070525346812, -0.303998818687369,
0.0795302532996298, 0.463059325286628, 0.803974055941737, 1.05966010393307,
1.18750312792874, 1.3153461519244, 1.40057483458818, 1.44318917592007,
1.57103219991573, 1.6988752239114, 1.74148956524329, 1.82671824790707,
1.86933258923895, 1.91194693057084, 1.99717561323462, 1.95456127190273,
1.91194693057084, 1.86933258923895, 1.78410390657518, 1.74148956524329,
1.74148956524329, 1.74148956524329, 1.74148956524329, 1.78410390657518
), Stockmarketindex = c(-1.66493184730628, -1.66463355820282,
-1.6694061838583, -1.6887949755837, -1.67417880951378, -1.66493184730628,
-1.64285845364968, -1.63748924978726, -1.63152346771791, -1.61601243433759,
-1.62615426385549, -1.62078505999307, -1.60616889392316, -1.58976299323243,
-1.56082895019607, -1.53875555653946, -1.51548900646899, -1.47790457943206,
-1.48088747046674, -1.47074564094884, -1.41615873501425, -1.43345950301538,
-1.40631519459982, -1.36544958742475, -1.32577713666355, -1.32816344949129,
-1.3189164872838, -1.2792440365226, -1.17722916313666, -1.1805103432748
), Economicgrowth = c(-0.419475860074214, 1.77103185704958, -1.24091625399564,
0.219422224086891, -0.693289324714688, -1.14964509911548, -0.282569127753977,
-0.738924902154767, -0.282569127753977, -0.14566239543374, 0.26505780152697,
-0.191297972873819, -0.14566239543374, 0.26505780152697, -0.14566239543374,
0.0825154917666544, 0.630142421047602, 0.128151069206733, 0.26505780152697,
0.173786646646812, 0.0825154917666544, -0.647653747274609, 0.0368799143265754,
0.675777998487681, 0.128151069206733, 0.72141357592776, -0.191297972873819,
-0.14566239543374, 0.26505780152697, 0.0825154917666544), Consumptiongrowth = c(1.49948934326176,
2.80290969177971, 2.43863500922448, 3.0742184397245, 3.29809558837824,
1.78028441106475, 1.98708618397371, 1.30407115418265, 1.06311862978413,
1.41221520056623, 1.19213257985578, 1.30976294609757, 0.943590999570694,
0.717816586945313, 0.803193465669196, 0.856316856875168, 0.915132039996066,
0.932207415740842, 0.877186760563229, 0.550857357440829, 0.359233696305002,
0.484453118433365, 0.0879249483602165, 0.410459823539332, 0.437021519142318,
0.419946143397541, 0.898056664251289, 0.717816586945313, 0.896159400279647,
0.962563639287112), Governmentexpenditure = c(-1.40005492084802,
-1.38413625639177, -1.36971935273328, -1.35410104043658, -1.33277603710839,
-1.31355349889707, -1.28802356533516, -1.2715041965598, -1.26880102712384,
-1.2558858842631, -1.24627461515744, -1.24417215004058, -1.22765278126522,
-1.21503799056404, -1.2159390470427, -1.20692848225614, -1.18259995733244,
-1.17989678789647, -1.18139854869423, -1.17058587095036, -1.17509115334364,
-1.14956121978173, -1.13814783771876, -1.13093938588951, -1.13274149884682,
-1.12853656861309, -1.1210277646243, -1.11622213007147, -1.09820100049835,
-1.07867811012748), Longtermgovernmentbondyield = c(1.40229182288022,
1.52084996657255, 1.52084996657255, 2.1284604529957, 2.10623080105339,
1.8221852484572, 1.74561644732258, 1.8221852484572, 1.79254571253412,
2.04695172920723, 2.32358739782265, 2.3705166630342, 1.87899435897644,
1.81477536447643, 1.26150402724559, 1.27879375653405, 1.22939452999558,
1.13306603824557, 1.19728503274558, 1.07872688905325, 1.0515573144571,
1.28126371786097, 1.19234511009173, 1.10342650232249, 1.21704472336097,
1.14294588355326, 1.05649723711094, 1.08119685038018, 0.811971065745526,
0.752691993899364), BankRate = c(1.46586697149636, 1.35154387389459,
1.66960408302535, 1.97274804858215, 2.29546045675764, 2.29546045675764,
2.09326712428386, 1.92386866579365, 1.57025981463491, 1.25236650053715,
1.3619748134568, 1.79713275011286, 1.62283175002842, 1.46140252936374,
1.11755703763521, 0.767494705927617, 1.00504892351727, 0.836192873884299,
0.743461821176297, 0.639548801257612, 0.614285065637952, 0.59615609267884,
1.0233656533885, 0.831874464905546, 1.44483819733896, 1.35112663631211,
1.16530987895099, 1.12197975600959, 1.27587783831036, 0.9050787987531
), ConsumerConfidenceIndex = c(0.846829650502804, 1.60472118016078,
0.469774413325411, -0.621585188209513, -1.60430771883233, -1.68373613752742,
-1.63528611498984, -1.66413766753932, -1.70435864332681, -1.66902678210495,
-1.59673510529459, -1.59602090595954, -0.999706472923775, 0.0694026684451194,
0.236084189726601, 0.627318384290896, 0.856229774103751, 1.00626414911988,
1.18224076468833, 1.53172580694677, 1.23795881575313, 0.203420073079754,
0.031697144727374, 0.197538431497049, -0.4751060554715, -0.723547646218374,
-0.38459179268613, -0.144363494292252, -0.345373846847121, -0.204466519215588
), RealPersonalDisposableIncome = c(-1.61847984374121, -1.5861635599299,
-1.57225712600034, -1.49848239094777, -1.53946529757862, -1.54497109045523,
-1.52492940490883, -1.54175692919285, -1.53951841454553, -1.57492545682787,
-1.59099234107728, -1.58530147051583, -1.59103377902389, -1.5730264259375,
-1.58525138856384, -1.58529970465885, -1.58192644597089, -1.52325368596072,
-1.53501582928257, -1.52925478110938, -1.50631522176011, -1.51590689703409,
-1.46151870482198, -1.40729486382567, -1.3789215787237, -1.3693640758863,
-1.36306692499173, -1.34201378673398, -1.29684320450097, -1.22228202649678
), PersonalDisposableIncome = c(-1.63374935499688, -1.61912533368493,
-1.59170800880699, -1.55197024453754, -1.5482842190616, -1.53111502598353,
-1.51272050030567, -1.496600325591, -1.47962148432076, -1.47543914833698,
-1.46603002900108, -1.44363362658138, -1.43430337270118, -1.41678955114361,
-1.41553667304378, -1.4009808145215, -1.39475625982839, -1.36509006246891,
-1.3676348839483, -1.35648303480995, -1.33818372341837, -1.33674498698592,
-1.3094343652563, -1.28373893947937, -1.27703100460648, -1.26432160075519,
-1.25275608335059, -1.23583637919461, -1.22110869865322, -1.18194367906969
), SPPricechange = c(1.26871538917159, 0.851034944363406, -0.128615553459435,
0.296659081254357, -2.70557732809419, 0.554861538044873, 0.509296398611252,
-0.98675901279262, 0.782687235212975, -0.391880803520353, -1.49050694319765,
-0.890565940654977, -0.386818010249951, -0.642489070405266, 0.0637705908158519,
0.256156735091138, 0.709276732792142, 0.689025559710533, 0.129586903331082,
-0.351378457357135, 0.213122992292719, 0.314378857700765, -0.217214435691474,
0.43841729282562, -0.202026055880268, 0.177683439399903, -1.00701018587423,
1.01304432901628, 1.20796186992677, 0.228311372103926), HouseStarts = c(-0.752212186140825,
1.99649271779397, 1.8436488194287, 1.69950335430372, -0.603096187735683,
0.0865653048881011, -0.685109986858511, -1.57110754404907, -1.21198651455668,
-0.257644124763769, -0.214151958562269, -0.962217217228067, -0.0128453607153271,
0.914159096036641, 0.712852498189699, 0.0766242383277583, 1.13783309364436,
1.96915478475302, 1.07942932760234, 0.407164701459157, 0.581133366265157,
1.28073592544928, 0.633323965706957, -0.424156989649512, -0.316047890805783,
1.23848639256783, 0.96137916219827, 0.337577235536758, -0.0811901933176841,
1.76039238698582), HouseCompleted = c(0.727121448038834, 1.51512215827386,
1.27770235093872, 4.62342810215839, 1.63310378032383, 1.60397251562013,
1.87343671412934, 2.03511523323486, 1.11893695830357, 0.288695914248185,
0.362980639242614, 0.395025030416681, -0.395888806288709, -0.695940832736795,
-0.378410047466491, 0.467853192175925, -0.349278782762793, 0.483875387762959,
0.46930975541111, 1.47288182445349, 0.598943883342565, 0.362980639242614,
0.829080874501776, 1.38985772004796, 0.143039590729697, 0.281413098072261,
0.138669901024142, 0.973280634785079, -0.238579976888742, 0.502810709820363
), TermSpread = c(-0.982486215892947, -1.35440528815526, -1.77852352845439,
-2.1243430166983, -2.91385543325514, -2.47668740094681, -1.8046231124728,
-0.891137671828519, 0.83143487338641, 1.14462988160731, -0.499643911552399,
-0.127724839290084, 0.43994111311029, 0.727036537312779, 0.916258521446237,
0.629163097243749, 0.37469215306427, 0.857534457404817, 0.968457689483053,
0.968457689483053, 1.18377925763492, 1.444775097819, 0.335542777036658,
0.981507481492256, -1.19780778404481, -0.89766256783312, -0.656241415662847,
-0.538793287580011, -1.4718534162381, -0.1799240073269), BuildingPermits = c(-0.757294212433685,
1.98548228249596, 1.83296803797682, 1.68913346590998, -0.608499827536959,
0.0796742026103982, -0.690336739230158, -1.5744233761582, -1.21607689919859,
-0.263792835859544, -0.220394473597999, -0.966846304496574, -0.0195220539874191,
0.905483038787227, 0.704610619176647, 0.0697545769506165, 1.12867461613232,
1.95820331193156, 1.0703968153811, 0.399582130138359, 0.573175579184539,
1.27126923499168, 0.625253613898393, -0.429946565660888, -0.322070636610762,
1.22911082593761, 0.95260126067119, 0.330144750519887, -0.0877194803984184,
1.74989117307615), Date = structure(c(289094400, 297043200, 304992000,
312854400, 320716800, 328665600, 336614400, 344476800, 352252800,
360201600, 368150400, 376012800, 383788800, 391737600, 399686400,
407548800, 415324800, 423273600, 431222400, 439084800, 446947200,
454896000, 462844800, 470707200, 478483200, 486432000, 494380800,
502243200, 510019200, 517968000), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), NORTH = c(4.06976744186047, 5.51675977653633,
7.2799470549305, 4.75015422578655, 4.59363957597172, 3.15315315315317,
1.2008733624454, -0.377562028047452, -0.108283703302655, 0.650406504065032,
0.969305331179318, 0.106666666666688, 3.09003729355352, 2.11886304909562,
2.32793522267207, 5.68743818001977, -1.46934955545156, 3.95611702127658,
5.19438987619354, -0.0912012507600199, 2.81677896109541, 3.97412590369087,
1.30118326353028, 3.31553807249226, 1.32872294960955, 2.93700394923507,
0.908853875665812, 1.81241002546971, -1.3414545718222, 4.81772747317361
), YORKSANDTHEHUMBER = c(4.0121120363361, 5.45851528384282, 9.52380952380951,
6.04914933837431, 3.03030303030299, 5.42099192618225, 2.78993435448577,
-0.53219797764768, 1.97966827180309, 1.15424973767052, 0.466804979253115,
-1.96179659266907, 2.42232754081095, 0.719794344473031, -0.306278713629415,
3.37941628264209, 2.74393263992076, 3.91920555341303, 1.91585099967527,
0.892125625853447, 2.91888477848958, 3.78293078507868, 0.109815847271484,
6.83486625601216, 0.722691730511011, 3.56008625759656, -0.227160867754524,
2.69419041475355, -1.17134094520194, 2.78546324684064), NORTHWEST = c(6.57894736842105,
6.95256660168939, 6.50060753341436, 5.5904164289789, 4.59211237169096,
4.70041322314051, 2.96003946719288, -1.38955438428365, 0.242954324586984,
2.18128938439167, -0.853889943073994, -2.15311004784691, 0.929095354523226,
2.51937984496125, 0.189035916824195, 2.21698113207546, 2.51499769266268,
3.5066396578888, 1.77437592415414, 0.948636868643719, 4.60125296308836,
3.95775160859537, -0.237455720347246, 4.218042765725, 2.79306600771276,
2.22545984338008, 0.709042970141798, 0.258269945161875, 0.663420142564747,
2.23655612423752), EASTMIDS = c(4.98489425981872, 8.20143884892085,
6.91489361702127, 5.22388059701494, 5.61465721040189, 4.64465584778958,
2.03208556149733, 0.314465408805028, 2.82131661442007, 0, 2.79471544715448,
-0.939199209095414, -1.14770459081835, 2.97829379101462, -0.68627450980392,
3.40572556762095, 3.42243436754175, 4.89223242719342, 0.730408764905171,
2.10107893242476, 2.31025926242835, 5.01798109893785, 0.382256908497274,
4.64894882982943, 3.04374194526571, 2.25491999264298, 0.651125980286367,
1.40105078809108, 2.87265165133409, 3.59418899472349), WESTMIDS = c(4.65838509316771,
4.74777448071216, 8.66855524079319, 6.56934306569344, 3.22896281800389,
3.17535545023698, 0.643086816720257, -1.36923779096303, 1.61962054604351,
2.00364298724953, -0.491071428571428, -2.78151637505608, 0, 2.39963082602676,
0.540784136998647, 1.83774092335275, 4.66989436619718, 1.82498633362771,
2.51909973157134, 0.644511581067457, 3.9503702221333, 3.15724626520867,
0.548671245147809, 4.19837410445824, 3.20983256145349, 1.12526319422872,
1.4028740144042, 0.434226470984247, -0.194389516372279, 2.32714328889485
), EASTANGLIA = c(6.74525212835624, 8.58895705521476, 8.47457627118643,
10.7291666666667, 4.8447789275635, 4.84522207267835, -0.299529311082601,
1.45922746781116, 0.88832487309645, 0.29350104821803, -0.877926421404701,
1.64487557992411, -2.69709543568468, 3.49680170575694, 3.25504738360115,
2.39425379090184, 2.98519095869059, 4.36691137516082, 3.57868020304568,
1.66275772744776, 3.79450451070863, 4.52162951167727, 2.28203256419209,
4.17054552224914, 3.2439678284182, 4.76643873164257, 0.955633279171614,
2.91614381581101, 0.848198902642676, 5.02010671012167), OUTERSEAST = c(6.7110371602884,
7.53638253638255, 9.47317544707589, 8.56512141280351, 3.82269215128102,
2.11515863689776, 1.64940544687381, -1.73584905660378, 1.34408602150539,
1.78097764304659, 0.446760982874161, -1.26019273535953, 0.150150150150159,
3.11094452773611, 1.4176663031625, 2.54480286738352, 5.56448794127927,
4.89371564797033, 3.88257575757575, 1.85961713764815, 5.54859495256845,
4.29879599796508, 2.00525702517411, 3.63679834232127, 3.44509381728699,
3.46664684309643, 1.93988743863012, 2.50440502760482, 2.96578121060713,
4.47634947134114), OUTERMET = c(4.54545454545458, 6.58505698607005,
7.36633663366336, 7.08225746956843, 4.3747847054771, 1.68316831683168,
1.00616682895164, -1.28534704370181, 2.01822916666665, 0.797702616464613,
0.949667616334271, -0.940733772342415, 1.10794555238999, 2.19160926737633,
2.84926470588237, 2.62138814417631, 5.02467343976781, 5.65213786241397,
3.22555328833776, 3.73552294786995, 5.05948745510956, 4.28797321179426,
2.86300392436674, 2.60339894216597, 4.28031183318191, 3.43199821714381,
3.34554286721641, 3.04770569170409, 1.65167650683293, 4.62120252591965
), LONDON = c(8.11719500480309, 10.3065304309196, 6.32299637535239,
7.65151515151515, 1.30190007037299, 2.1535255296978, -0.204012240734436,
-0.306643952299836, 0.786056049213951, 1.18684299762631, 1.00536193029493,
-2.85335102853352, 2.76639344262296, 2.06048521103356, 1.23738196027352,
2.70183338694115, 3.30410272471031, 5.76322570865546, 4.73255747291176,
1.98428989791171, 6.03563952552197, 4.88977753030802, 2.12581135535556,
4.43247330120026, 5.42986425339366, 3.96781115879828, 3.43247538648888,
4.0668901660281, 4.09587727708534, 4.81707991010573), SOUTHWEST = c(6.17577197149644,
7.71812080536912, 7.63239875389407, 9.45489628557649, 2.46804759806079,
2.19354838709679, 1.72558922558922, 0.248241621845247, 1.48576145274456,
2.03334688897925, -0.677560781187733, -2.3274478330658, 1.80772391125718,
2.42130750605327, 1.85185185185186, 0.928433268858785, 5.95247221157533,
4.38447346525341, 3.30272049904696, 2.25107353730542, 3.86823714688802,
2.04371722787289, 3.04596811639065, 4.19057346270538, 2.45646407565451,
2.17525889239081, 2.83400809716597, 1.58015962290428, 2.77894958869438,
4.08650146221331), WALES = c(6.09418282548476, 8.35509138381203,
7.40963855421687, 7.01065619742007, 1.15303983228513, 3.47150259067357,
-0.150225338007013, 0.852557673019058, 0.944803580308295, -1.13300492610835,
0.946686596910786, -2.17176702862782, 3.98587285570131, 0.485201358563789,
3.62143891839691, 1.63094128611373, 1.61852361302152, 4.32251951450617,
1.28887158859911, 0.68747598104105, 3.71925360474978, 4.66941979801284,
1.44927536231884, 1.05121293800539, 1.67663757954501, 2.9419480568152,
-0.422309596621509, 2.67987715706347, 0.0249243368346056, 2.03260714794249
), SCOTLAND = c(5.15222482435597, 4.12026726057908, 5.40106951871658,
8.67579908675796, -0.280112044817908, 2.94943820224719, 1.04592996816735,
1.21512151215122, 1.33392618941751, 3.59806932865292, 0.974163490046604,
0.125838926174496, 1.46627565982404, 3.42691990090835, -0.838323353293421,
1.97262479871176, 3.40702724042636, 4.30649410147751, 2.44866586142527,
1.93997856377279, 2.09581887638873, 4.22573890357352, 0.833278440155458,
4.15155969296095, 2.01655899140689, 1.93980755633434, 0.325693606755129,
0.796561260069754, -0.381713535919834, 2.90974405029185), NIRELAND = c(4.54545454545454,
4.94752623688156, 4.42857142857145, 2.96397628818967, 6.06731620903454,
0.0835073068893502, -1.66875260742594, -2.96987696224015, -1.18058592041975,
-0.884955752212393, -1.74107142857143, -0.545206724216265, 1.96436729100047,
-0.224014336917564, -1.84104176021554, 1.6010978956999, 1.42278253039172,
1.97993429814437, 1.29287828660979, 1.61158623060724, 2.28387751649466,
1.84005954349984, 1.79057208981284, 2.22177901874749, 2.88757950598978,
-0.731975575530031, 3.07939176281808, -0.0593031875463392, -1.05696484201158,
3.40717418194087), UK = c(5.76890543055322, 7.20302836425676,
7.39543442582184, 7.22885986848197, 3.23472252213347, 2.95766398929048,
1.20271423347285, -0.554061107319231, 0.98913965036942, 1.55113136643479,
0.373986300291293, -1.61195434757029, 1.59052858167903, 2.07573082205217,
1.17628969016684, 2.44680851063832, 2.84453345201007, 4.10010457610617,
2.88208396840793, 1.58922558922557, 3.67559326527908, 3.90013106997858,
1.36611181194425, 4.12505691303686, 2.02017257462689, 2.93167985827357,
1.54068234183715, 2.12149379408387, 0.594313861969269, 3.83755588673622
)), row.names = c(NA, 30L), class = "data.frame")
Code:
library(tidyverse)
library(GGally)
library(Amelia)
library(inspectdf)
library(ggcorrplot)
library(ggplot2)
library(reshape2)
library(tseries)
library(dplyr)
library(caret)
library(tidyverse)
library(ARDL)
library(dLagM)
library(forecast)
in_sampleARDL <- data %>%
dplyr::filter(Date < '2020-03-01')
out_sampleARDL <-data %>%
dplyr::filter(Date >= '2020-03-01')
# Model Building
# Create the formulas
indep_vars <- expression(Industrialproduction, Householdconsumption, Investmentgrowth, ConsumerPriceIndex, Employment, Unemploymentrate,
Stockmarketindex, Economicgrowth, Consumptiongrowth, Governmentexpenditure, Longtermgovernmentbondyield,
BankRate, ConsumerConfidenceIndex, RealPersonalDisposableIncome, PersonalDisposableIncome, SPPricechange,
HouseStarts, HouseCompleted, TermSpread, BuildingPermits)
dep_vars <- expression(NORTH, YORKSANDTHEHUMBER, NORTHWEST, EASTMIDS, WESTMIDS, EASTANGLIA, OUTERSEAST, OUTERMET, LONDON,
SOUTHWEST, WALES, SCOTLAND, NIRELAND, UK)
# Formulae with diff()
formulae <- unlist(lapply(dep_vars, \(x) lapply(indep_vars, \(y) bquote(.(x)~diff(.(y))))))
length(formulae)
# Without diff()
formulae2 <- unlist(lapply(dep_vars, \(x) lapply(indep_vars, \(y) bquote(.(x)~.(y)))))
length(formulae2)
result <- vector('list', length = length(formulae))
names(result) <- formulae2
# Loop for H = 4
for (i in seq_along(formulae)){
# auto_ardl
result[[i]][[1]] <- auto_ardl(formula(formulae2[[i]]),
data = in_sampleARDL, max_order = 4, selection = 'BIC')
# prediction
result[[i]][[2]] <- forecast(ardlDlm(formula = formula(formulae[[i]]), data = in_sampleARDL, p = 3),
x = out_sampleARDL |> select(sub("\\s~.*", "", formula(formulae[[i]]))) |> pull(), h = 4)
# error
result[[i]][[3]] <- mean((out_sampleARDL |> select(sub("\\s~.*", "", formula(formulae[[i]]))) |> pull() |> (\(x) x[1:4])() - result[[i]][[2]][["forecasts"]])^2)
# set names
names(result[[i]]) <- c('auto_ardl','forecast','error')
}
print(result[[i]])

traceback() shows that this error is coming from the forecast call, and that it occurs with i==1, so look at the first parameter to forecast :: ardlDlm(formula = formula(formulae[[i]]), data = in_sampleARDL, p = 3) and realize that it is not something that forecast is designed to work with. forecast was expecting an atomic numeric vector.
Looking at the output of ardlDlm(formula = formula(formulae[[1]]), data = in_sampleARDL, p = 3), it appears that you really want numeric vectors contained in the $data leaf of that much longer list and in particular probably want only the i-th column, so try this:
for (i in seq_along(formulae)){
# auto_ardl
result[[i]][[1]] <- auto_ardl(formula(formulae2[[i]]),
data = in_sampleARDL,
max_order = 4, selection = 'BIC')
# prediction
#
result[[i]][[2]] <- forecast(ardlDlm(formula = formula(formulae[[i]]),
#---------------extract one col------------------\/-\/-\/-
data = in_sampleARDL, p = 3)$data[[i]],
x = out_sampleARDL |>
select(sub("\\s~.*", "", formula(formulae[[i]]))) |>
pull(), h = 4)
# error
result[[i]][[3]] <- mean((out_sampleARDL |> select(sub("\\s~.*",
"", formula(formulae[[i]]))) |>
pull() |> (\(x) x[1:4])() -
result[[i]][[2]][["forecasts"]])^2)
# set names
names(result[[i]]) <- c('auto_ardl','forecast','error')
}
Note that you only printed the last value in the much longer result object. The last such value looks like:
print(result[[i]])
$auto_ardl
$auto_ardl$best_model
Time series regression with "ts" data:
Start = 5, End = 30
Call:
dynlm::dynlm(formula = full_formula, data = data, start = start,
end = end)
Coefficients:
(Intercept) L(UK, 1) BuildingPermits L(BuildingPermits, 1) L(BuildingPermits, 2)
1.59718 -0.04719 0.90441 -0.04269 0.19583
L(BuildingPermits, 3) L(BuildingPermits, 4)
0.63773 0.02544
$auto_ardl$best_order
[1] 1 4
$auto_ardl$top_orders
UK BuildingPermits BIC
1 1 4 90.18992
2 2 4 93.11884
3 3 4 96.02905
4 1 3 98.36867
5 4 4 99.15721
6 3 3 100.20359
7 2 3 100.53056
8 2 2 104.78506
9 1 2 104.85999
10 1 1 106.10666
$forecast
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
1 NaN NaN NaN NaN NaN
2 NaN NaN NaN NaN NaN
3 NaN NaN NaN NaN NaN
4 NaN NaN NaN NaN NaN
$error
[1] NaN

Related

Arima model with Rolling Origin in R

I am working on a data set with 14 variables. I have used the Arima model with Rolling Origin but applying the rolling origin method on each variable every time is a bit slow and want to automate the process. I have tried to automate the process so that it gives me outputs for 14 models but it gives me an error. Please any help is appreciated.
Data:
structure(list(Date = structure(c(289094400, 297043200, 304992000,
312854400, 320716800, 328665600, 336614400, 344476800, 352252800,
360201600, 368150400, 376012800, 383788800, 391737600, 399686400,
407548800, 415324800, 423273600, 431222400, 439084800, 446947200,
454896000, 462844800, 470707200, 478483200, 486432000, 494380800,
502243200, 510019200, 517968000, 525916800, 533779200, 541555200,
549504000, 557452800, 565315200, 573177600, 581126400, 589075200,
596937600, 604713600, 612662400, 620611200, 628473600, 636249600,
644198400, 652147200, 660009600, 667785600, 675734400), tzone = "UTC", class = c("POSIXct",
"POSIXt")), NORTH = c(4.06976744186047, 5.51675977653633, 7.2799470549305,
4.75015422578655, 4.59363957597172, 3.15315315315317, 1.2008733624454,
-0.377562028047452, -0.108283703302655, 0.650406504065032, 0.969305331179318,
0.106666666666688, 3.09003729355352, 2.11886304909562, 2.32793522267207,
5.68743818001977, -1.46934955545156, 3.95611702127658, 5.19438987619354,
-0.0912012507600199, 2.81677896109541, 3.97412590369087, 1.30118326353028,
3.31553807249226, 1.32872294960955, 2.93700394923507, 0.908853875665812,
1.81241002546971, -1.3414545718222, 4.81772747317361, -3.4743890895067,
4.63823913990992, 0.857370960463727, 1.78620594713658, 0.527472527472524,
-4.05973562947765, -0.136726966764838, 3.16657890117607, 5.95161125667812,
8.01002055498458, 10.5501040737437, 13.4138468987035, 2.93371279497212,
8.84291046495554, -6.87764606265876, 2.90741287990725, 3.71548486856639,
1.23317430567388, -1.1153443739474, 4.31313207880924), YORKSANDTHEHUMBER = c(4.0121120363361,
5.45851528384282, 9.52380952380951, 6.04914933837431, 3.03030303030299,
5.42099192618225, 2.78993435448577, -0.53219797764768, 1.97966827180309,
1.15424973767052, 0.466804979253115, -1.96179659266907, 2.42232754081095,
0.719794344473031, -0.306278713629415, 3.37941628264209, 2.74393263992076,
3.91920555341303, 1.91585099967527, 0.892125625853447, 2.91888477848958,
3.78293078507868, 0.109815847271484, 6.83486625601216, 0.722691730511011,
3.56008625759656, -0.227160867754524, 2.69419041475355, -1.17134094520194,
2.78546324684064, 1.01487759630426, 1.54843356139717, 4.15602836879435,
4.43619773934357, -0.309698451507728, -1.45519947678222, -1.09839057574248,
9.08267346664877, 11.8913598474363, 13.9511229623114, 9.71243848306475,
7.66524473371739, 6.46801731884651, -2.26736490763654, -4.35729847494552,
-2.93870179974964, -7.72353426221536, -7.01127302722023, 2.02543627323513,
2.51245245873873), NORTHWEST = c(6.57894736842105, 6.95256660168939,
6.50060753341436, 5.5904164289789, 4.59211237169096, 4.70041322314051,
2.96003946719288, -1.38955438428365, 0.242954324586984, 2.18128938439167,
-0.853889943073994, -2.15311004784691, 0.929095354523226, 2.51937984496125,
0.189035916824195, 2.21698113207546, 2.51499769266268, 3.5066396578888,
1.77437592415414, 0.948636868643719, 4.60125296308836, 3.95775160859537,
-0.237455720347246, 4.218042765725, 2.79306600771276, 2.22545984338008,
0.709042970141798, 0.258269945161875, 0.663420142564747, 2.23655612423752,
1.69729803867784, 0.792339593378065, 2.82330902522246, 2.20899212700891,
1.48327338701976, -1.78151365931687, 1.8457608174996, 5.06380710500736,
7.57132625044768, 9.28561520321818, 9.51969943135663, 11.3671132539057,
10.5960954085668, -1.43026516363364, 3.55308627832826, 3.99351008518014,
-1.44138713566414, -0.165494414563527, 2.01304344107922, 1.70645628251555
), EASTMIDS = c(4.98489425981872, 8.20143884892085, 6.91489361702127,
5.22388059701494, 5.61465721040189, 4.64465584778958, 2.03208556149733,
0.314465408805028, 2.82131661442007, 0, 2.79471544715448, -0.939199209095414,
-1.14770459081835, 2.97829379101462, -0.68627450980392, 3.40572556762095,
3.42243436754175, 4.89223242719342, 0.730408764905171, 2.10107893242476,
2.31025926242835, 5.01798109893785, 0.382256908497274, 4.64894882982943,
3.04374194526571, 2.25491999264298, 0.651125980286367, 1.40105078809108,
2.87265165133409, 3.59418899472349, 1.76616504051596, 3.78627839708797,
3.9017974572556, 3.85473176612416, 0.0696479874633737, 1.45578980947134,
2.96698585107904, 12.8612275490659, 16.8142463597009, 10.6860102754148,
5.80782620275077, 2.65911542610573, -2.54295171544163, 4.66512121048756,
-3.66911045104132, -1.75382312052187, -3.61743042705271, -5.070772474025,
-1.21063610003222, 1.9530155970429), WESTMIDS = c(4.65838509316771,
4.74777448071216, 8.66855524079319, 6.56934306569344, 3.22896281800389,
3.17535545023698, 0.643086816720257, -1.36923779096303, 1.61962054604351,
2.00364298724953, -0.491071428571428, -2.78151637505608, 0, 2.39963082602676,
0.540784136998647, 1.83774092335275, 4.66989436619718, 1.82498633362771,
2.51909973157134, 0.644511581067457, 3.9503702221333, 3.15724626520867,
0.548671245147809, 4.19837410445824, 3.20983256145349, 1.12526319422872,
1.4028740144042, 0.434226470984247, -0.194389516372279, 2.32714328889485,
1.7360199527435, 3.3224734685978, 4.23339889482064, 5.79267379518974,
4.39964893406187, 0.374237288135615, 4.31199848701807, 13.9164443523531,
18.0050929925879, 6.07502745611839, 3.93976822755839, 4.07004176642259,
3.48434981192908, -1.92610381813166, 0.438451356717408, -0.103780578206083,
-3.0952145377791, -1.72381519612015, -2.02143896779759, 4.40768347678723
), EASTANGLIA = c(6.74525212835624, 8.58895705521476, 8.47457627118643,
10.7291666666667, 4.8447789275635, 4.84522207267835, -0.299529311082601,
1.45922746781116, 0.88832487309645, 0.29350104821803, -0.877926421404701,
1.64487557992411, -2.69709543568468, 3.49680170575694, 3.25504738360115,
2.39425379090184, 2.98519095869059, 4.36691137516082, 3.57868020304568,
1.66275772744776, 3.79450451070863, 4.52162951167727, 2.28203256419209,
4.17054552224914, 3.2439678284182, 4.76643873164257, 0.955633279171614,
2.91614381581101, 0.848198902642676, 5.02010671012167, 2.80551592962435,
5.64292321924145, 4.17550004608719, 9.7903026013095, 5.88709352460008,
3.07862089961185, 8.83080444493668, 14.1609281183215, 14.9330678829839,
-2.38242974223737, 1.8287757399192, 1.22633166874738, -5.71564382892894,
-5.25820956533587, -9.72515856236787, 0.957479010339489, -3.50481300299826,
-3.45549395738277, -0.828308094308001, -0.331408094033985), OUTERSEAST = c(6.7110371602884,
7.53638253638255, 9.47317544707589, 8.56512141280351, 3.82269215128102,
2.11515863689776, 1.64940544687381, -1.73584905660378, 1.34408602150539,
1.78097764304659, 0.446760982874161, -1.26019273535953, 0.150150150150159,
3.11094452773611, 1.4176663031625, 2.54480286738352, 5.56448794127927,
4.89371564797033, 3.88257575757575, 1.85961713764815, 5.54859495256845,
4.29879599796508, 2.00525702517411, 3.63679834232127, 3.44509381728699,
3.46664684309643, 1.93988743863012, 2.50440502760482, 2.96578121060713,
4.47634947134114, 4.50826657576274, 4.92742395824838, 5.38770910645244,
7.13653626341212, 6.15524925576032, 1.08283352245096, 6.66955322492704,
9.69075574665124, 11.4606033194907, 3.4233015677836, 1.10095233565968,
1.65461280649144, -3.58737650679069, -5.85546129756061, -4.98846560711691,
-2.32068359558401, -5.55914140928629, -4.66925504224286, -1.07093896112692,
2.07357059157311), OUTERMET = c(4.54545454545458, 6.58505698607005,
7.36633663366336, 7.08225746956843, 4.3747847054771, 1.68316831683168,
1.00616682895164, -1.28534704370181, 2.01822916666665, 0.797702616464613,
0.949667616334271, -0.940733772342415, 1.10794555238999, 2.19160926737633,
2.84926470588237, 2.62138814417631, 5.02467343976781, 5.65213786241397,
3.22555328833776, 3.73552294786995, 5.05948745510956, 4.28797321179426,
2.86300392436674, 2.60339894216597, 4.28031183318191, 3.43199821714381,
3.34554286721641, 3.04770569170409, 1.65167650683293, 4.62120252591965,
6.34025700005186, 6.1931790459772, 8.10781836281492, 6.14401677315165,
5.88313802952244, 0.112183931227468, 4.21036727396348, 5.85740693754756,
8.61496319123439, 2.24246818616477, 2.39678510128783, 1.57885756155336,
-2.68472955079939, -5.09925369345585, -6.23990242127901, -2.51851513733724,
-2.72874133732908, -5.45172276846427, 0.20833593462305, 2.61721355963614
), LONDON = c(8.11719500480309, 10.3065304309196, 6.32299637535239,
7.65151515151515, 1.30190007037299, 2.1535255296978, -0.204012240734436,
-0.306643952299836, 0.786056049213951, 1.18684299762631, 1.00536193029493,
-2.85335102853352, 2.76639344262296, 2.06048521103356, 1.23738196027352,
2.70183338694115, 3.30410272471031, 5.76322570865546, 4.73255747291176,
1.98428989791171, 6.03563952552197, 4.88977753030802, 2.12581135535556,
4.43247330120026, 5.42986425339366, 3.96781115879828, 3.43247538648888,
4.0668901660281, 4.09587727708534, 4.81707991010573, 7.42869193863026,
6.70069362648866, 6.67699006500675, 7.43184006668679, 5.53177257525084,
-1.06737656081638, 1.7605678920595, 5.86902048679756, 6.75919979067056,
0.943616938313976, 1.29679498499027, 1.95787891003782, -1.64030775806797,
-2.62806236080178, -2.6208912592328, -4.49717565910836, -5.18403877531433,
-5.57502752084625, -0.947552316580683, 0.978175016770521), SOUTHWEST = c(6.17577197149644,
7.71812080536912, 7.63239875389407, 9.45489628557649, 2.46804759806079,
2.19354838709679, 1.72558922558922, 0.248241621845247, 1.48576145274456,
2.03334688897925, -0.677560781187733, -2.3274478330658, 1.80772391125718,
2.42130750605327, 1.85185185185186, 0.928433268858785, 5.95247221157533,
4.38447346525341, 3.30272049904696, 2.25107353730542, 3.86823714688802,
2.04371722787289, 3.04596811639065, 4.19057346270538, 2.45646407565451,
2.17525889239081, 2.83400809716597, 1.58015962290428, 2.77894958869438,
4.08650146221331, 4.40418977202712, 2.87285774987016, 3.86424654076504,
5.69560126372535, 5.04170063334797, 1.07854257457266, 6.75066443547593,
13.56963706108, 16.2190250397843, 2.62121000419169, -0.940827274460141,
2.85066318466084, -0.886020125887025, -6.46387832699618, -3.51150320013839,
-0.306262698697259, 0.555963495227118, -7.19650681052728, -1.76899526612503,
0.528003461834023), WALES = c(6.09418282548476, 8.35509138381203,
7.40963855421687, 7.01065619742007, 1.15303983228513, 3.47150259067357,
-0.150225338007013, 0.852557673019058, 0.944803580308295, -1.13300492610835,
0.946686596910786, -2.17176702862782, 3.98587285570131, 0.485201358563789,
3.62143891839691, 1.63094128611373, 1.61852361302152, 4.32251951450617,
1.28887158859911, 0.68747598104105, 3.71925360474978, 4.66941979801284,
1.44927536231884, 1.05121293800539, 1.67663757954501, 2.9419480568152,
-0.422309596621509, 2.67987715706347, 0.0249243368346056, 2.03260714794249,
1.14433241461116, 3.01472870890965, 0.7768290641219, 3.81433365451707,
-0.140822531605095, -2.99349379827568, 4.11669475005782, 4.95668454288706,
12.973544973545, 15.3990258523792, 9.25324675324674, 6.63977924007642,
0.236872486962066, -0.381277677383487, 0.681750224259938, -2.67091690260756,
-5.39078074779283, -3.51337404317537, 0.996191624080064, 2.8524564276044
), SCOTLAND = c(5.15222482435597, 4.12026726057908, 5.40106951871658,
8.67579908675796, -0.280112044817908, 2.94943820224719, 1.04592996816735,
1.21512151215122, 1.33392618941751, 3.59806932865292, 0.974163490046604,
0.125838926174496, 1.46627565982404, 3.42691990090835, -0.838323353293421,
1.97262479871176, 3.40702724042636, 4.30649410147751, 2.44866586142527,
1.93997856377279, 2.09581887638873, 4.22573890357352, 0.833278440155458,
4.15155969296095, 2.01655899140689, 1.93980755633434, 0.325693606755129,
0.796561260069754, -0.381713535919834, 2.90974405029185, 0.802862378916138,
0.473263498109834, 1.33268231036562, 0.742609336470062, 0.427651014264418,
-2.00028015128168, -2.46419484863213, 3.18590814502184, 4.33732886439812,
3.78406337625565, 4.59302783096821, 9.65541455585091, 7.16082700576343,
2.74890619997868, -6.81926759861247, 3.2880071333036, 2.69558648969462,
-2.78454942837929, 1.79123210602768, 2.88825864878425), NIRELAND = c(4.54545454545454,
4.94752623688156, 4.42857142857145, 2.96397628818967, 6.06731620903454,
0.0835073068893502, -1.66875260742594, -2.96987696224015, -1.18058592041975,
-0.884955752212393, -1.74107142857143, -0.545206724216265, 1.96436729100047,
-0.224014336917564, -1.84104176021554, 1.6010978956999, 1.42278253039172,
1.97993429814437, 1.29287828660979, 1.61158623060724, 2.28387751649466,
1.84005954349984, 1.79057208981284, 2.22177901874749, 2.88757950598978,
-0.731975575530031, 3.07939176281808, -0.0593031875463392, -1.05696484201158,
3.40717418194087, 1.07655502392344, -1.70701093778018, -2.34959319931409,
6.56454324677751, -1.80912979454455, -4.90966221523961, 0.319176899102556,
1.67315466387184, -2.88259765121672, 2.95678544351781, -0.54123711340205,
4.15355569540591, -1.90510040874357, 0.923946519801462, 4.1035398865513,
-2.3519674449081, -5.50238389546177, 7.24670179766041, 2.75090864790844,
0.446509889559553), UK = c(5.76890543055322, 7.20302836425676,
7.39543442582184, 7.22885986848197, 3.23472252213347, 2.95766398929048,
1.20271423347285, -0.554061107319231, 0.98913965036942, 1.55113136643479,
0.373986300291293, -1.61195434757029, 1.59052858167903, 2.07573082205217,
1.17628969016684, 2.44680851063832, 2.84453345201007, 4.10010457610617,
2.88208396840793, 1.58922558922557, 3.67559326527908, 3.90013106997858,
1.36611181194425, 4.12505691303686, 2.02017257462689, 2.93167985827357,
1.54068234183715, 2.12149379408387, 0.594313861969269, 3.83755588673622,
3.33948434056075, 3.50933756603259, 3.25378570059421, 5.14920870654849,
3.36548010504709, -0.177206541696886, 1.65971553844507, 8.51865098567251,
11.0759984490113, 5.32351247098249, 3.99880682100659, 4.55095927082668,
0.864171188197283, -2.04898834977862, -3.10383660120637, -1.01415357182659,
-2.94496091613858, -4.06343734981687, -0.677156948752485, 1.59717017296902
)), row.names = c(NA, -50L), class = c("tbl_df", "tbl", "data.frame"
))
This manual code works:
y <- data2$NORTH
ourCall <- "predict(arima(x=data,order=c(1,0,0)),n.ahead=h)"
ourValue <- c("pred")
returnedValues1 <- ro(y, h=4, origins = 8,
call=ourCall, value=ourValue)
returnedValues1$actuals
returnedValues1$holdout
returnedValues1$pred
But this doesn't:
y <- data2
y %<>% dplyr::select(-Date)
ourCall <- "predict(arima(x=data,order=c(1,0,0)),n.ahead=h)"
ourValue <- c("pred")
ar_ro_model_4 = apply(y,2,function(x){
return(
list(
returnedValues1 <- ro(y, h=4, origins = 8,
call=ourCall, value=ourValue)
))
} )
ar_ro_model_4

permanova betadisper: missing observations due to 'group' removed Error in eigen(-x/2, symmetric = TRUE) : 0 x 0 matrix

I tried to adapt a code from an earlier version of R to process some data. I got most of it working again but ran into an issue.... I am trying to use vegan to run a permanova and permdisp, however when I get to the betadisper part I get the error "missing observations due to 'group' removed
Error in eigen(-x/2, symmetric = TRUE) : 0 x 0 matrix" I am not the best at R.... but I have tried to futz with it and don't know where I went wrong....
Thank you for reading and any Help would be appreciated.
require (vegan)
require (ggplot2)
require (gridExtra)
require (pals)
require (ape)
require (RColorBrewer)
legpro<- read.table('legpro.txt', sep='\t', header=T,row.names = 1)
legpro.std<-legpro[,3:ncol(legpro)]/legpro$Overall.body.Size.Estimator
legpro.std<-cbind(legpro$Code,legpro.std)
names(legpro.std)[1]<- 'Code'
legpro.std<-cbind(legpro$Species.Name,legpro.std)
names(legpro.std)[1]<- 'Species.Name'
#legpro.std<-legpro.std[-54]
#excluding body size from data
legpro.std<-legpro.std[-54]
#-6,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-21,-22,-23,-29,-35,-41,-45,-46,-48,-49,-51,-52, can eliminate
head(legpro.std)
tail(legpro.std)
plot(legpro.std$claw1,legpro.std$claw2)
plot(legpro.std$claw1,legpro.std$claw3)
plot(legpro.std$Forewing.width,legpro.std$Forewing.length)
plot(legpro$Overall.body.Size.Estimator,legpro$Forewing.length)
legpro.std$Code <- factor(legpro.std$Code,levels = c('A.adnixa','A.modesta','A.bicolor','A.plomleyi','C.rastricornis','S.itasca','S.mohri','C.fitchi','C.simplicior','S.flinti','S.vicaria','C.areolaris','O.fulvicephalus','D.macleodi','N.americanus','D.binocula','H.costalis','H.stigma','S.angustus','M.tasmaniae','L.banksi','L.squamosa','S.pavida','D.sayi','C.tenuistriga','C.cincta','A.eureka','C.collaris','P.prasinus','C.coloradensis','N.myrmeleonoides','A.occidens','P.capicola','P.immensus','P.libelluloides','U.macleayanus','U.floridanus','U.quadripunctatus','U.bicolor','L.longicornis','L.coccajus','D.speciosus','C.pusillus','B.mexicanus','B.californicus','B.abdominalis','C.abdominalis','C.schwarzi','M.trigrammus','M.californicus','M.exitialis','P.hageni','V.fallax','S.carrizonus','S.dissimilis','S.eiseni','B.furcatus','B.lethalis','E.sinuatum','E.ornatum','E.arizonense','G.luniger','M.bilineatus','C.plumbeus','D.tetragrammicus'))#for setting species order
###Permanova
permanova<-adonis2(log10(legpro.std[,3:ncol(legpro.std)])~legpro.std$Species.Name,method='euclidean')
permanova
###Permdisp
Name.Code<- as.factor(legpro.std$Code)
legpro.dis<- vegdist(log10(legpro.std[,3:ncol(legpro.std)]),'euclidean')
perm.legpro <- betadisper (legpro.dis,Name.Code,type=c('median'))
perm.legpro2<- permutest(perm.legpro,pairwise=T, permutations=9999)
anova(perm.legpro)
TukeyHSD(perm.legpro)
pcoa<- pcoa(vegdist(log10(legpro.std[,3:ncol(legpro.std)]),'euclidean'))
print(pcoa)#Cumum_eig or
pcoa.cm<-cmdscale(vegdist(log10(legpro.std[,3:ncol(legpro.std)]),'euclidean'),add = F)
print(pcoa.cm) #% explanation of each axis is given by the variance of the axis/total pcoa variance or check above
The data from head is:
head(legpro.std)
Species.Name Code claw1 claw2 claw3 Totleglength1 Totleglength2 Totleglength3 Coxa1.anterior
1 Sialis.itasca.Ross 0.04570004 0.04528458 0.05359368 2.080806 2.397590 3.108226 0.3477358
2 Sialis.itasca.Ross 0.04510309 0.05111684 0.05025773 2.026632 2.348797 2.907216 0.3311856
3 Sialis.itasca.Ross 0.04593070 0.05116841 0.04472200 1.904915 2.350322 2.831184 0.2912973
4 Sialis.itasca.Ross 0.04196933 0.04237288 0.04640840 1.945924 2.228612 2.730024 0.2824859
5 Sialis.itasca.Ross 0.04725473 0.05220522 0.05445545 2.048830 2.428218 2.951395 0.3280828
6 Sialis.itasca.Ross 0.04471005 0.05046481 0.05002213 2.318504 2.488490 3.011067 0.3333333
coxa1.posterior Coxa1average Coxa2.anterior coxa2.posterior Coxa2.average Coxa3.anterior coxa3.posterior
1 0.3169921 0.3323639 0.3402576 0.3485667 0.3444121 0.2937266 0.3223930
2 0.3144330 0.3228093 0.3784364 0.3625429 0.3704897 0.2916667 0.3487972
3 0.2538275 0.2725624 0.3352135 0.3231265 0.3291700 0.2828364 0.3227236
4 0.2861178 0.2843019 0.2744149 0.2836965 0.2790557 0.2655367 0.2869250
5 0.3352835 0.3316832 0.2812781 0.3096310 0.2954546 0.2736274 0.3105311
6 0.3196104 0.3264719 0.3430721 0.3413015 0.3421868 0.3005755 0.3594511
Coxa3.average femur1 femur2 femur3 Forewing.length Forewing.width Forewingsurice.area tarsi1_1 tarsi1_2
1 0.3080598 0.5334441 0.6248442 0.7714998 3.905692 1.140839 10.72503 0.1479020 0.08516826
2 0.3202319 0.5945017 0.6224227 0.7096220 3.717354 1.240550 10.73572 0.1271478 0.08161512
3 0.3027800 0.5302175 0.6877518 0.7304593 3.708702 1.221595 11.24479 0.1373892 0.07775987
4 0.2762308 0.5145279 0.5952381 0.7094431 3.672720 1.142454 10.39747 0.1323648 0.07627119
5 0.2920792 0.5234024 0.6710172 0.7178218 3.894690 1.299730 11.24786 0.1314131 0.08190819
6 0.3300133 0.7242143 0.6573705 0.7312970 3.911022 1.100044 9.71889 0.1496237 0.08632138
tarsi1_3 tarsi1_4 tarsi1_5 tarsi1tot tarsi2_1 tarsi2_2 tarsi2_3 tarsi2_4 tarsi2_5 tarsi2tot tarsi3_1
1 0.05899460 0.03406730 0.07810552 0.4042376 0.1798920 0.09056917 0.08890735 0.03199003 0.1574574 0.5488159 0.3103448
2 0.06185567 0.03006873 0.09235395 0.3930412 0.1859966 0.12113402 0.08376288 0.03565292 0.1245704 0.5511168 0.2843643
3 0.06124093 0.02739726 0.08622079 0.3900080 0.1833199 0.11724416 0.07534246 0.03424657 0.1446414 0.5547945 0.2123288
4 0.06133979 0.02986279 0.09604520 0.3958838 0.1949153 0.10895885 0.07506054 0.02945924 0.1142050 0.5225989 0.2566586
5 0.05940594 0.02880288 0.09180918 0.3933394 0.1908191 0.10531054 0.08235824 0.03915392 0.1345635 0.5522052 0.2808281
6 0.05843293 0.03320053 0.09871625 0.4262948 0.2173528 0.12926073 0.09606020 0.03231518 0.1372289 0.6122178 0.2855246
tarsi3_2 tarsi3_3 tarsi3_4 tarsi3_5 tarsi3tot tibia1 tibia2 tibia3 Trochanter1.anterior
1 0.1458247 0.12172829 0.04154549 0.1728292 0.7922725 0.6726215 0.7349398 1.0793519 0.14291649
2 0.1658076 0.10438144 0.03651203 0.1507732 0.7418385 0.6065292 0.6808419 0.9746564 0.09879725
3 0.1305399 0.07896857 0.03505237 0.1543110 0.6112006 0.6176470 0.6458501 1.0209508 0.08944399
4 0.1513317 0.09564165 0.04317999 0.1452785 0.6920904 0.6432607 0.7171106 0.9196933 0.10290557
5 0.1588659 0.09675968 0.04095410 0.1332133 0.7106211 0.7011701 0.7803781 1.0756077 0.09315932
6 0.1651173 0.10358565 0.03497123 0.1412129 0.7304117 0.7348384 0.7290836 1.0624170 0.09517486
Trochanter1.posterior Trochanter1.average Trochanter2.anterior Trochanter2.posterior Trochanter2.average
1 0.13336103 0.13813876 0.15828833 0.1308683 0.1445783
2 0.12070446 0.10975085 0.12070446 0.1271478 0.1239261
3 0.09951651 0.09448025 0.10999194 0.1555197 0.1327558
4 0.11299435 0.10794996 0.09483455 0.1343826 0.1146086
5 0.10531054 0.09923493 0.10711072 0.1512151 0.1291629
6 0.11819388 0.10668437 0.14121292 0.1540505 0.1476317
Trochanter3.anterior Trochanter3.posterior Trochanter3.average
1 0.1819692 0.1321147 0.1570420
2 0.1503436 0.1713917 0.1608677
3 0.1651894 0.1663981 0.1657937
4 0.1315577 0.1335755 0.1325666
5 0.1480648 0.1624663 0.1552655
6 0.1460823 0.1677733 0.1569278
dput
structure(list(Species.Name = c("Sialis.itasca.Ross", "Sialis.itasca.Ross",
"Sialis.itasca.Ross", "Sialis.itasca.Ross", "Sialis.itasca.Ross",
"Sialis.itasca.Ross"), Code = structure(c(6L, 6L, 6L, 6L, 6L,
6L), levels = c("A.adnixa", "A.modesta", "A.bicolor", "A.plomleyi",
"C.rastricornis", "S.itasca", "S.mohri", "C.fitchi", "C.simplicior",
"S.flinti", "S.vicaria", "C.areolaris", "O.fulvicephalus", "D.macleodi",
"N.americanus", "D.binocula", "H.costalis", "H.stigma", "S.angustus",
"M.tasmaniae", "L.banksi", "L.squamosa", "S.pavida", "D.sayi",
"C.tenuistriga", "C.cincta", "A.eureka", "C.collaris", "P.prasinus",
"C.coloradensis", "N.myrmeleonoides", "A.occidens", "P.capicola",
"P.immensus", "P.libelluloides", "U.macleayanus", "U.floridanus",
"U.quadripunctatus", "U.bicolor", "L.longicornis", "L.coccajus",
"D.speciosus", "C.pusillus", "B.mexicanus", "B.californicus",
"B.abdominalis", "C.abdominalis", "C.schwarzi", "M.trigrammus",
"M.californicus", "M.exitialis", "P.hageni", "V.fallax", "S.carrizonus",
"S.dissimilis", "S.eiseni", "B.furcatus", "B.lethalis", "E.sinuatum",
"E.ornatum", "E.arizonense", "G.luniger", "M.bilineatus", "C.plumbeus",
"D.tetragrammicus"), class = "factor"), claw1 = c(0.0457000398959275,
0.045103090158027, 0.0459306989564186, 0.0419693321653473, 0.0472547265893557,
0.0447100492179136), claw2 = c(0.045284584153096, 0.0511168382615714,
0.051168411852526, 0.042372881410651, 0.0522052218973023, 0.050464806029534
), claw3 = c(0.0535936807297095, 0.050257730039612, 0.0447219967552032,
0.0464083960590078, 0.0544554479373681, 0.0500221314070853),
Totleglength1 = c(2.080805936746, 2.02663219508693, 1.90491528797122,
1.94592417110508, 2.04882996069499, 2.31850370337949), Totleglength2 = c(2.3975902975308,
2.3487971821018, 2.35032225197969, 2.22861185065265, 2.42821795709869,
2.48849039363661), Totleglength3 = c(3.10822595137736, 2.90721641469161,
2.83118434974866, 2.7300243220427, 2.95139534984782, 3.0110667765838
), Coxa1.anterior = c(0.347735766263887, 0.331185569221734,
0.291297323563015, 0.282485879299417, 0.328082812807204,
0.333333333333333), coxa1.posterior = c(0.316992102366229,
0.314432977364315, 0.253827544849914, 0.286117841877611,
0.335283548106612, 0.31961043951507), Coxa1average = c(0.332363934522785,
0.322809273078248, 0.272562434407915, 0.28430186079029, 0.33168318068193,
0.326471886424202), Coxa2.anterior = c(0.340257575356567,
0.378436407168337, 0.335213529057563, 0.27441486170569, 0.281278142496969,
0.343072135629241), coxa2.posterior = c(0.348566665701357,
0.362542936849028, 0.323126490526473, 0.283696541563174,
0.309630989611699, 0.341301463699871), Coxa2.average = c(0.344412120321235,
0.370489672008682, 0.329170009993469, 0.279055701634432,
0.295454566279356, 0.342186799664556), Coxa3.anterior = c(0.293726629791346,
0.291666666612973, 0.282836418227029, 0.2655367278651, 0.273627368020151,
0.300575476345173), coxa3.posterior = c(0.32239302120667,
0.348797230641319, 0.322723594896146, 0.286924958124474,
0.310531068416563, 0.359451064344658), Coxa3.average = c(0.308059825499008,
0.320231948412369, 0.302780006360137, 0.276230843196563,
0.292079218218357, 0.330013270123579), femur1 = c(0.53344412311015,
0.594501676537536, 0.530217536295495, 0.514527850716328,
0.523402362157819, 0.724214250276451), femur2 = c(0.624844166341973,
0.62242266239383, 0.687751788591478, 0.595238122698798, 0.67101716194329,
0.657370505792677), femur3 = c(0.771499768530334, 0.709621950616875,
0.73045925924984, 0.709443126916381, 0.71782183270357, 0.731296991557455
), Forewing.length = c(3.90569163653097, 3.71735396284475,
3.70870245967632, 3.67271997731286, 3.89468979918273, 3.91102248411048
), Forewing.width = c(1.14083920932507, 1.24054979613491,
1.22159545808208, 1.1424536620426, 1.29973004580049, 1.10004419021568
), Forewingsurice.area = c(10.7250294361749, 10.7357182857541,
11.2447860996532, 10.3974705849124, 11.2478641830568, 9.71889046379367
), tarsi1_1 = c(0.14790195113684, 0.127147764272682, 0.137389192375109,
0.132364817915656, 0.131413146374404, 0.149623723140197),
tarsi1_2 = c(0.0851682561130301, 0.0816151169968028, 0.0777598691430841,
0.0762711871041436, 0.0819081932949372, 0.086321375636013
), tarsi1_3 = c(0.05899459957015, 0.0618556656924223, 0.0612409299273872,
0.0613397899673706, 0.0594059432453148, 0.0584329328546814
), tarsi1_4 = c(0.0340673036084858, 0.0300687276311245, 0.0273972594295365,
0.0298627938699947, 0.0288028831418247, 0.0332005316106093
), tarsi1_5 = c(0.0781055209485422, 0.0923539508709525, 0.0862207865660963,
0.0960452026260472, 0.0918091839108305, 0.0987162455869307
), tarsi1tot = c(0.404237631377048, 0.393041225034431, 0.390008037038313,
0.395883791483213, 0.393339350417356, 0.426294808828432),
tarsi2_1 = c(0.179891974784803, 0.185996557201992, 0.183319900195347,
0.194915264093515, 0.190819089619718, 0.217352803588656),
tarsi2_2 = c(0.0905691687216469, 0.121134019176011, 0.117244156225387,
0.108958845465276, 0.10531053520073, 0.129260729462848),
tarsi2_3 = c(0.0889073519821446, 0.0837628811084026, 0.0753424647406533,
0.0750605365433736, 0.0823582392230224, 0.0960601978522388
), tarsi2_4 = c(0.0319900282179677, 0.0356529186168164, 0.0342465741861955,
0.0294592417998321, 0.039153916085443, 0.032315182365712),
tarsi2_5 = c(0.157457414941948, 0.124570439606804, 0.144641410417212,
0.114205004217583, 0.134563461120325, 0.137228859386712),
tarsi2tot = c(0.548815938233055, 0.551116815710026, 0.554794505764795,
0.522598892523131, 0.552205241699284, 0.612217772213493),
tarsi3_1 = c(0.310344810480925, 0.284364252740063, 0.212328761485435,
0.256658594428061, 0.280828103319559, 0.285524552019457),
tarsi3_2 = c(0.145824678654506, 0.165807558229931, 0.130539881647459,
0.151331723647517, 0.158865888131613, 0.165117302168043),
tarsi3_3 = c(0.12172829459396, 0.104381440634743, 0.0789685681210926,
0.0956416505558846, 0.0967596828191374, 0.103585653153654
), tarsi3_4 = c(0.0415454916076207, 0.0365120268387758, 0.0350523743106695,
0.0431799855509762, 0.0409540966474686, 0.0349712270016878
), tarsi3_5 = c(0.172829247098504, 0.150773196132581, 0.154311026818233,
0.145278460351334, 0.133213330086744, 0.141212924791317),
tarsi3tot = c(0.792272522435516, 0.741838474576093, 0.61120061278579,
0.692090414533774, 0.710621101004522, 0.730411659134159),
tibia1 = c(0.672621484952058, 0.606529166301326, 0.617647027480212,
0.64326070605379, 0.701170139665048, 0.734838388979717),
tibia2 = c(0.734939761208523, 0.680841920542057, 0.645850109596671,
0.717110574280138, 0.780378064142149, 0.729083625085317),
tibia3 = c(1.07935188194521, 0.974656351266629, 1.02095076737815,
0.9196933462701, 1.07560766416314, 1.06241701109683), Trochanter1.anterior = c(0.142916494686509,
0.0987972496490506, 0.0894439939133073, 0.102905570062555,
0.0931593216950861, 0.0951748552474476), Trochanter1.posterior = c(0.133361030881401,
0.120704458621732, 0.0995165119881685, 0.112994354060364,
0.10531053520073, 0.118193883379276), Trochanter1.average = c(0.138138762783955,
0.109750854135391, 0.0944802527492875, 0.10794996206146,
0.0992349286729306, 0.106684369313362), Trochanter2.anterior = c(0.158288326427611,
0.120704458621732, 0.109991937780383, 0.0948345464155595,
0.107110718913071, 0.141212924791317), Trochanter2.posterior = c(0.130868296424412,
0.127147764272682, 0.155519737883267, 0.1343825722132, 0.151215127156145,
0.154050456084472), Trochanter2.average = c(0.144578311426012,
0.123926111447207, 0.132755838033276, 0.114608559516156,
0.129162923034608, 0.147631690437894), Trochanter3.anterior = c(0.181969248928957,
0.150343635578303, 0.165189354284288, 0.131557713775331,
0.148064812410224, 0.146082338998146), Trochanter3.posterior = c(0.132114657421083,
0.171391742772324, 0.166398053665197, 0.133575468072875,
0.162466255556294, 0.167773349902735), Trochanter3.average = c(0.157041952967292,
0.16086768939009, 0.165793703974743, 0.132566591125879, 0.155265534208282,
0.156927844671778), Overall.body.Size.Estimator = c(1, 1,
1, 1, 1, 1)), row.names = c(NA, 6L), class = "data.frame")

compare multiple signals using FFT in R

I want to analyse multiple signals using Fast fourier transform and try to group the ones with similar patterns.
I'd like to know how to approach this problem.
A subset of my data:
df <- dput(tst1)
structure(list(var_1 = c(0.238942, 0.265, 0.190338, 0.245714,
0.208872, 0.266648, 0.1909, 0.291751, 0.259681, 0.270592), var_2 = c(0.236594,
0.262115, 0.188282, 0.243209, 0.206064, 0.26483, 0.187436, 0.289571,
0.256675, 0.268209), var_3 = c(0.234762, 0.260603, 0.188161,
0.240466, 0.204413, 0.262256, 0.1863, 0.288058, 0.254225, 0.266186
), var_4 = c(0.232489, 0.258214, 0.186727, 0.238468, 0.201748,
0.260584, 0.184533, 0.285398, 0.251934, 0.263722), var_5 = c(0.230015,
0.255756, 0.186592, 0.235875, 0.199746, 0.258097, 0.18314, 0.283392,
0.249769, 0.262319), var_6 = c(0.227892, 0.253624, 0.186194,
0.233518, 0.197826, 0.255778, 0.181736, 0.281578, 0.247566, 0.260859
), var_7 = c(0.225756, 0.251379, 0.185813, 0.231679, 0.195496,
0.253272, 0.180961, 0.27873, 0.244901, 0.259456), var_8 = c(0.223464,
0.249673, 0.185515, 0.229863, 0.193899, 0.251128, 0.180393, 0.276851,
0.243248, 0.257856), var_9 = c(0.221471, 0.24726, 0.184834, 0.227454,
0.191849, 0.248769, 0.179127, 0.273859, 0.240625, 0.255606),
var_10 = c(0.21952, 0.245511, 0.184278, 0.225988, 0.190593,
0.246434, 0.178072, 0.271144, 0.238321, 0.253885), var_11 = c(0.218228,
0.243789, 0.184485, 0.224337, 0.189168, 0.245093, 0.177002,
0.268688, 0.23696, 0.251804), var_12 = c(0.216438, 0.241876,
0.184569, 0.222695, 0.187973, 0.243475, 0.175195, 0.266073,
0.235168, 0.250305), var_13 = c(0.215116, 0.240005, 0.184283,
0.220832, 0.186319, 0.24159, 0.173557, 0.263756, 0.232819,
0.248114), var_14 = c(0.213016, 0.237224, 0.18444, 0.21831,
0.18518, 0.240112, 0.17209, 0.261131, 0.230609, 0.245875),
var_15 = c(0.211184, 0.23517, 0.18475, 0.216627, 0.183275,
0.238314, 0.171204, 0.258135, 0.228459, 0.243731), var_16 = c(0.208855,
0.232755, 0.184906, 0.215249, 0.181248, 0.236821, 0.169593,
0.256136, 0.226637, 0.241915), var_17 = c(0.207139, 0.230857,
0.185459, 0.21385, 0.180094, 0.235208, 0.168155, 0.254205,
0.22486, 0.240045), var_18 = c(0.205077, 0.228666, 0.185522,
0.211764, 0.178778, 0.233662, 0.166491, 0.251451, 0.222678,
0.237376), var_19 = c(0.203173, 0.226569, 0.185825, 0.209949,
0.176726, 0.231828, 0.165068, 0.248426, 0.220556, 0.235003
), var_20 = c(0.201251, 0.224366, 0.186176, 0.207974, 0.175703,
0.230081, 0.163141, 0.246262, 0.218654, 0.232062), var_21 = c(0.199265,
0.221885, 0.186458, 0.205793, 0.174502, 0.228247, 0.161569,
0.24376, 0.216408, 0.229642), var_22 = c(0.197004, 0.219585,
0.186486, 0.203886, 0.173065, 0.226032, 0.160078, 0.241633,
0.214141, 0.227404), var_23 = c(0.19512, 0.216987, 0.186782,
0.201754, 0.171262, 0.223991, 0.158268, 0.239415, 0.212232,
0.225068), var_24 = c(0.193056, 0.21441, 0.186593, 0.199443,
0.169317, 0.221896, 0.156727, 0.237254, 0.209865, 0.222927
), var_25 = c(0.190861, 0.211877, 0.186553, 0.19689, 0.168172,
0.219797, 0.155611, 0.235068, 0.207387, 0.220559)), row.names = c(22743L,
6535L, 59032L, 61113L, 16944L, 60773L, 3235L, 19567L, 20560L,
42516L), class = "data.frame")
Each row in the data is 1 signal and I'd like to group the signals with same patterns.
FFT on this data:
f <- apply(df, 1, function(x){abs(fft(x))})
How do I go about from here to finding similar patterns? Does removing the peaks and reconstructing the inverse FFT help here?

Understanding why I get an error in computations when removing certain columns gives zero error: library(lpSolve)

I understand that this question has been asked before but I could not solve the question with the current solutions after searching.
I am running into an error:
Error in solve.default(covs) :
system is computationally singular: reciprocal condition number = 1.08804e-18
Code: (which give the error)
library(lpSolve)
retbar <- colMeans(rets, na.rm = T)
covs <- var(rets, na.rm = T) # calculates the covariance
invS <- solve(covs)
Other:
> det(covs)
[1] 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003458185
> qr(covs)$rank
[1] 20
However when I remove some variables and run the code it works....
Code2: (which works)
rets$B6 <- NULL
rets$M6 <- NULL
rets$R6 <- NULL
rets$Q6 <- NULL
retbar <- colMeans(rets, na.rm = T)
covs <- var(rets, na.rm = T) # calculates the covariance
invS <- solve(covs)
> det(covs)
[1] 0.000000000000000000000000000000000000000000000000000000000000000000000000003514001
> qr(covs)$rank
[1] 20
I just want to understand why removing "X6" variable from my data allows me to solve the cov matrix. I have seen that "X6" (X here is B,M,R,Q) is correlated with other variables - "X6" is calculated as "X5 - X1" (or: B5 -B1, M5 - M1, R-5 - R1, Q5 - Q1") - I would like to idealy keep all columns in the data.
Data:
EDIT: New df
rets <- structure(list(B1 = c(0.0201596769556875, 0.00796992085297743,
0.0492147329548896, 0.019344865533839, 0.0215214485329025, 0.0207218693128776,
0.0103862072924815, 0.0140747415980048, 0.0261785500777131, 0.0373946762995772,
-0.00684759663692184, -0.0524902194742576, 0.00315800118629925,
0.0311087399558667, 0.0296245772665513, -0.0714423815378389,
-0.00828133058937649, -0.0474562526488911, -0.027177578320533,
-0.0150494495620104, 0.0348119470955449, 0.026557944400082, -0.0948970420281616,
0.020249494359762, 0.0362642768918328, -0.108930302464037, -0.209399350620045,
-0.131078973014079, 0.0340021699340833, -0.0392411420552388,
-0.104669817843903, 0.126868769506696, 0.180232948671053, 0.0769264211043898,
0.019176729939273, 0.0993469049194573, 0.0738823618605167, 0.0686517377053094,
-0.0438445535170806, 0.0291731714634921, 0.074704119945333, -0.00156713313391479,
0.041919134266091, 0.0718713711298, 0.0616824041447802, -0.0694331912797978,
-0.0664994905875237, -0.0637350113576239, 0.0995459645599069,
0.0350470019423567), B2 = c(0.0159402689787551, 0.0162507344633192,
0.0740337591014227, 0.0384769820770539, 0.0091777285515574, 0.0266077913225889,
0.0135757617808849, 0.00407485086602279, 0.024561373325238, 0.0369076019690258,
-0.0111998096779211, -0.0550216348217377, 0.00296776607315141,
0.0155911183644963, 0.0127829585460845, -0.0686988206697129,
-0.0120169929067047, -0.0379441518196964, -0.00997556953482333,
-0.0157591765829324, 0.0259378688367708, 0.0348720134553493,
-0.0864851422178537, 0.0243151482365286, 0.054450975569433, -0.105384283400191,
-0.244132080369671, -0.149214851674911, 0.0642730083371614, -0.0732165541787947,
-0.132146613068358, 0.117037257468365, 0.243486361548774, 0.127689400206569,
0.0507680353897798, 0.0918127231182545, 0.057623460462537, 0.0664555639592365,
-0.0637209916042463, 0.0351111011481844, 0.0774253568342104,
-0.0208447613007578, 0.0464411219167523, 0.088343873921378, 0.0845804848931461,
-0.0672340736611374, -0.063074008563108, -0.0552850698211716,
0.118020745550881, 0.0350453682926441), B3 = c(0.0254691625247841,
0.0122239330016886, 0.0446599436180717, 0.0289436320423226, 0.00984126934358344,
0.0248495851877287, 0.0070023062540998, 0.00867717868910234,
0.0198468884639984, 0.0423526987264829, -0.00673483175868612,
-0.0536716292198917, 0.00702602564601019, 0.0161515106339872,
0.00881414723751897, -0.0704128768108256, -0.0118703057246587,
-0.0654796158401091, -0.0214858440189339, -0.0287089650155394,
0.0375015423973781, 0.0669904486938052, -0.0941557378605896,
0.0153425838301645, 0.0209397917472626, -0.101627763946357, -0.226324878317675,
-0.141233587277128, 0.0562599340844954, -0.0426624056954274,
-0.101409613365061, 0.095072163016385, 0.19560509325657, 0.153377825232805,
0.0250685160313996, 0.0912032732747058, 0.0514030426458047, 0.0803912808233686,
-0.0604690113263003, 0.0268422517753881, 0.10412185199629, -0.0227046178907074,
0.045247514742643, 0.080985450832222, 0.0646318077059794, -0.0703469469216747,
-0.0487479424020042, -0.0677789445266782, 0.102936536920121,
0.0372798264656416), B4 = c(0.0219191738217161, 0.0176853257846887,
0.0456353457446462, 0.0341367113786865, 0.0224113039756616, 0.0198275955536373,
0.00679047712618314, 0.00326894704835364, 0.0279149805055439,
0.0270857608217435, -0.00413393714898988, -0.0566739462091404,
-0.0114439339594225, 0.011077534748248, 0.0166466370578447, -0.0733647442632695,
-0.0100085083715353, -0.0525145185232886, -0.0326582904953551,
-0.0193272575954162, 0.028187178228298, 0.037490075562138, -0.0740065271333753,
0.0376882236271473, 0.0170308927355229, -0.0991359056176541,
-0.224423397219161, -0.118318357393019, 0.0765578429241032, -0.0580225262433487,
-0.110441975119102, 0.101623526281797, 0.208245933500372, 0.0931300452658907,
0.0371493076663389, 0.109834174058939, 0.0451845252205385, 0.0922986324245771,
-0.0604417879228685, 0.0176772270368012, 0.0760699055274017,
-0.0219431067610276, 0.0363180693269241, 0.10978144288715, 0.0703026600940392,
-0.0827017008478804, -0.0577866241297221, -0.0682246277864018,
0.112824937430707, 0.042166109959073), B5 = c(0.0393541248460465,
0.00956169994553254, 0.045506941231113, 0.022679161458704, 0.0071175687346599,
0.0245724846722118, -0.00486326015007488, 0.00977777199018314,
0.0372227348807343, 0.0421686696514302, -0.00729705359364536,
-0.0420398232585704, -0.00198560837531052, 0.0191012049979939,
0.0151182378767174, -0.0720890664222317, -0.0145999296151926,
-0.0549852597740717, -0.0357418224487, -0.00858510372461121,
0.0371052230990963, 0.0358706764622103, -0.0797211143737148,
0.0133179042163717, 0.0227502855968991, -0.0960364954219236,
-0.20877985810845, -0.125247884467955, 0.0582827803341161, -0.0546479539249937,
-0.127419512889315, 0.161520030974712, 0.213080660094016, 0.108923963868525,
0.0216324723000225, 0.123493437786137, 0.0643989332634697, 0.065803254107272,
-0.0624072744596408, 0.0370168039973202, 0.0836690142031841,
-0.0128692586306809, 0.0506633041324735, 0.0963571736706436,
0.0704426407884252, -0.0733420360542838, -0.0710357171347283,
-0.0688377671567964, 0.132571567141589, 0.0447762558807919),
B6 = c(0.019194447890359, 0.00159177909255511, -0.0037077917237766,
0.00333429592486495, -0.0144038797982426, 0.00385061535933419,
-0.0152494674425564, -0.00429696960782166, 0.0110441848030212,
0.00477399335185296, -0.000449456956723525, 0.0104503962156872,
-0.00514360956160977, -0.0120075349578728, -0.0145063393898339,
-0.00064668488439279, -0.00631859902581606, -0.00752900712518056,
-0.00856424412816701, 0.00646434583739916, 0.00229327600355132,
0.00931273206212835, 0.0151759276544468, -0.00693159014339035,
-0.0135139912949337, 0.0128938070421132, 0.000619492511594932,
0.00583108854612438, 0.0242806104000329, -0.0154068118697549,
-0.0227496950454118, 0.0346512614680161, 0.0328477114229624,
0.0319975427641352, 0.00245574236074952, 0.0241465328666802,
-0.00948342859704696, -0.00284848359803735, -0.0185627209425603,
0.0078436325338281, 0.00896489425785109, -0.0113021254967661,
0.00874416986638248, 0.0244858025408436, 0.008760236643645,
-0.00390884477448601, -0.00453622654720459, -0.00510275579917252,
0.0330256025816826, 0.00972925393843514), M1 = c(0.0113396747037768,
-0.036155735142529, 0.0550687853246927, 0.0269238017499447,
0.00982287898659706, 0.00809061527252197, -0.047512024641037,
-0.016009446233511, -0.00278357416391373, -0.00628054095432162,
-0.0609199032187462, -0.0494923722396639, 0.00698078286246139,
0.00983662394804645, 0.0380059639114982, -0.0652908706460783,
-0.00563693966137906, -0.0491752210641838, -0.0214304637710383,
-0.0153438172807354, 0.0203537379326515, 0.0421207453446271,
-0.083814601712769, 0.0152837951106913, 0.031787003709805,
-0.107241585677281, -0.210874717399826, -0.115555851834153,
0.0599437241751638, -0.0587498251989018, -0.0995314111424103,
0.104148721637336, 0.182319135902193, 0.105787461175244,
0.033689877375748, 0.0966363048202885, 0.0640538126301515,
0.0640782744095522, -0.0440799278693556, 0.0303018999590801,
0.0841023643583563, -0.0176897923202359, 0.0382914170044418,
0.0759079900327234, 0.0738894489211014, -0.0566797658200011,
-0.0592523659979936, -0.0605415574124922, 0.108837738508142,
0.0311480459267166), M2 = c(0, 0.0369318500161171, 0.05479446798563,
0.0441558659076691, 0.0063580423593521, -0.0073090447112918,
-0.0191763313487172, -0.00646415911614895, 0.0458552502095698,
0.0275424104183912, -0.0487805381417274, -0.0400584393734526,
-0.00416827541765468, 0.0212708574224962, 0.0174144436427715,
-0.0674113624348997, -0.0125841060695098, -0.0558416555270291,
-0.0163345211185515, -0.0219548647100168, 0.0504916901610439,
0.0417230815077788, -0.0769711063634779, 0.0167976787218786,
0.0430265647426742, -0.123826423650743, -0.234415110641567,
-0.130708167875127, 0.0554669174895657, -0.0450817684669273,
-0.12032524188012, 0.154298987141929, 0.236011380184834,
0.114111615690755, 0.0275421794934158, 0.0938332458107501,
0.0953365754115465, 0.0847282442055681, -0.0712375521873279,
0.0174096324909712, 0.0755245202122583, -0.00762107035320276,
0.0428905926947967, 0.0972422302671232, 0.076027299598966,
-0.0788738990751014, -0.0621384863719475, -0.0624743295694587,
0.116711918883773, 0.0476898780038488), M3 = c(0.0359311569482088,
-0.139999955892563, 0.0209301561117172, 0.104783609509468,
-0.0721649304032326, 0.397777765989304, -0.0111288027837873,
0.00482318503782153, 0.14879997074604, 0.16648281365633,
-0.0580596011132003, -0.047679182583228, 0.0114269531841602,
0.0317433578864438, 0.00775221147687179, -0.061602244912588,
-0.0158776681251565, -0.0648263710640019, -0.0240124892502704,
-0.0177448932428571, 0.0379559719894449, 0.0344511040566261,
-0.0775795445422815, 0.027065822418437, 0.0251577377516715,
-0.108475149947571, -0.235411574529894, -0.144522154940724,
0.0449754514928253, -0.0489695645129837, -0.123624581783743,
0.11508095146038, 0.211242172822533, 0.145198421859061, 0.0179784820325099,
0.0982173541566308, 0.0555486086463638, 0.0736606557016785,
-0.0583725513432673, 0.0363466235082538, 0.0690110039168571,
-0.0160342605855651, 0.0540222033909931, 0.0862467848463471,
0.0633677104077289, -0.0850614424954192, -0.0535852042349274,
-0.0603007163253751, 0.113070077846931, 0.0408424520012463
), M4 = c(-0.155844137072563, -0.0610789265483618, 0.0988630047067999,
-0.0086556291207671, 0.0815064907073975, -0.0185706592164934,
-0.0207591075450184, 0.105547562241554, -0.107201084494591,
0.0113929212093353, -0.022529099136591, -0.0441186886312525,
0.00195441980877977, 0.016870060442579, 0.00759373951839394,
-0.0769912599379698, -0.0171198804233096, -0.0417608516722064,
-0.0238246997368977, -0.0177104066632295, 0.0235756050630395,
0.0269268993848493, -0.0967296211775303, 0.0324606583258286,
0.0290416693746976, -0.092120191410525, -0.230766838669409,
-0.140616977306715, 0.0699212552919189, -0.0613821172279649,
-0.129080012361016, 0.115632295353163, 0.241743159430643,
0.0945421887374065, 0.0330785879111653, 0.114030935722985,
0.0394783260686381, 0.0637947810755577, -0.060909434465672,
0.0323739642311314, 0.0841339563067396, -0.0184345132038895,
0.0495400154798214, 0.0976821368464078, 0.0614972022290451,
-0.0706658855287132, -0.070385725555342, -0.073441507572736,
0.109315224489104, 0.0374856931309638), M5 = c(-0.12346476316452,
-0.0105703119188547, 0.092919297516346, 0.136621922254562,
-0.0155999753624201, 0.0682649463415146, -0.0922404378652573,
0.0620875768363475, -0.0615064632147553, 0.143709745258093,
0.0756230279803276, -0.0617075127175431, -0.00360911323150503,
0.0112366336242249, 0.0154406559539872, -0.0787746054515343,
-0.00269523979941826, -0.0526490888305032, -0.0326128715360069,
-0.0167875265945536, 0.0288873225335168, 0.0437001503452364,
-0.0850432923719407, 0.0182440995488183, 0.0238926558011993,
-0.0957959717629556, -0.215013577753659, -0.144644269534711,
0.0501889619753152, -0.05768291939606, -0.128211720987334,
0.127069415092379, 0.216602876296358, 0.113530188173674,
0.0468711288658715, 0.122424450357045, 0.0374143540121529,
0.0871767761121666, -0.0567737247714127, 0.0360353329323981,
0.103461599696569, -0.0225164942232245, 0.0415910101081693,
0.0918531230749919, 0.0755528541988306, -0.0728917148203065,
-0.0657610368590244, -0.0564028779478209, 0.122215778161083,
0.045920382671152), M6 = c(-0.134804437868297, 0.0255854232236743,
0.0378505121916533, 0.109698120504617, -0.0254228543490172,
0.0601743310689926, -0.0447284132242203, 0.0780970230698586,
-0.0587228890508416, 0.149990286212415, 0.136542931199074,
-0.0122151404778793, -0.0105898960939664, 0.00140000967617841,
-0.0225653079575109, -0.0134837348054559, 0.00294169986196079,
-0.00347386776631942, -0.0111824077649687, -0.00144370931381818,
0.00853358460086529, 0.00157940500060929, -0.00122869065917164,
0.00296030443812702, -0.0078943479086057, 0.011445613914325,
-0.00413886035383279, -0.0290884177005585, -0.00975476219984855,
0.00106690580284179, -0.0286803098449235, 0.0229206934550435,
0.0342837403941652, 0.00774272699843015, 0.0131812514901235,
0.0257881455367569, -0.0266394586179985, 0.0230985017026144,
-0.0126937969020571, 0.00573343297331802, 0.0193592353382127,
-0.00482670190298854, 0.00329959310372758, 0.0159451330422685,
0.00166340527772912, -0.0162119490003055, -0.0065086708610308,
0.00413867946467136, 0.0133780396529413, 0.0147723367444354
), Q1 = c(0.0265621797051281, 0.0121992440563654, 0.0340947461024625,
0.0114726169959482, 0.0244721697934678, 0.0304556573852703,
-0.00256444356341105, 0.00372350399549636, 0.0237739984235116,
0.0270033285140239, -0.00704723803210073, -0.0476901397804718,
0.0071129609034004, 0.0323939519651734, 0.00323882454019589,
-0.0622794850397196, -0.0119234506451499, -0.0399236912960561,
-0.0436079844051925, -0.0261022150048638, 0.0291371183325865,
0.0563959058031636, -0.0907071155080928, 0.013374178530945,
0.0681693173169967, -0.0880869802416643, -0.218258767247561,
-0.138316280509299, 0.0411314660955931, -0.066409005195869,
-0.139430000425292, 0.101716784591166, 0.199285888061083,
0.0893195469347605, 0.0207835902897264, 0.0819590143972909,
0.0428754482336569, 0.0804621560497635, -0.0576983031786784,
0.026600132264742, 0.0760024661290204, -0.0281950326994129,
0.0424528139477703, 0.0865725399565793, 0.077255839460645,
-0.0690729842646359, -0.0617721764311835, -0.0619110102090971,
0.0975149637737052, 0.0422298654882387), Q2 = c(0.0265492763632932,
0.0222894305734672, 0.0476030515586719, 0.0257378459646134,
0.0255000609197377, 0.0300794550319551, 0.0133745468006092,
0.0187672452778894, 0.0248004048250247, 0.0205707288256205,
-0.00587681182154011, -0.0630040478242402, 0.000107261570787615,
0.00467345834692457, 0.0213892270033362, -0.0937099313495658,
0.00251645909947125, -0.0632956599325149, -0.00132090380066074,
-0.031540190910209, 0.0415217259003839, 0.0196243224662538,
-0.0976611527880924, 0.01713131867179, 0.0206693921571488,
-0.10984720875515, -0.23604335413059, -0.123298519500156,
0.102579391798905, -0.0619608930031467, -0.122741970750742,
0.107440420011137, 0.258562571065352, 0.0831288756533286,
0.0380738103365828, 0.102122914387041, 0.0771691647838361,
0.0869058388988892, -0.0542813220308744, 0.0351488706963522,
0.0846733840829011, -0.0167029370619785, 0.0380128870131627,
0.0954233112213096, 0.059146453231235, -0.0675340663722515,
-0.0772898672570218, -0.0756378709511565, 0.134937047612454,
0.0226618044495643), Q3 = c(0.0249571957657415, 0.0296065641893266,
0.0516467535933711, 0.0204032773069533, 0.00564130011432592,
0.0224283534635712, 0.00301239166268108, -0.000150963898842058,
0.0229134533635214, 0.0424657574061316, -0.00777680567175671,
-0.0445223698536066, 0.00394081997679386, 0.0240830812307228,
0.0124971211046563, -0.0795800732459543, -0.00881168550209076,
-0.0584900388668757, -0.0263079088348604, -0.0200931730088996,
0.0449965138077459, 0.0368462420389372, -0.114047989403222,
0.0267671234829322, 0.0151821869391063, -0.111191677522722,
-0.204383997931583, -0.126313542632778, 0.0672104859243762,
-0.0666682464928415, -0.0980276147276163, 0.109471163679627,
0.194550998802703, 0.0833334999543796, 0.0343969262838429,
0.0992981119758178, 0.0528223219283973, 0.0674760505087006,
-0.0665537698263506, 0.0342528662929908, 0.0958234167504998,
-0.0294131255411294, 0.0476092755160584, 0.0909138728225699,
0.0727903652909526, -0.0637077652670556, -0.0656483788804145,
-0.0551227529131964, 0.116486035743042, 0.0356988697476277
), Q4 = c(0.0327908558900147, -0.00581402105550901, 0.0471795087541677,
0.0316287353740667, 0.0154292859732494, 0.0321233577293451,
0.0178516903431687, 0.0297250315289144, 0.0497392455796797,
0.0539487711478713, 0.00185283865199054, -0.0550304813356512,
0.0242636750567233, 0.0215392546950305, 0.0293588232816546,
-0.0724868968014562, -0.000755860281788007, -0.0471606758364942,
-0.0207128138943517, -0.0165231425832055, 0.0434456925169798,
0.0391054884659545, -0.0742084088275147, 0.017590121803775,
0.0469003681911008, -0.096158440258061, -0.226202925207553,
-0.115346873402837, 0.0553655066805321, -0.0526318049432673,
-0.0854428438991429, 0.154789113362523, 0.20641849783792,
0.178990423471939, 0.0210107589738628, 0.1585673924883, 0.0698894288055367,
0.109538887119296, -0.0571717024643894, 0.0429703488688447,
0.0646785154424408, -0.0175924605503971, 0.0516479415292585,
0.106135927417663, 0.0894213136540906, -0.0842766439587239,
-0.0607679109495784, -0.064878143379156, 0.12349074462156,
0.0383776279423885), Q5 = c(0.0277489582011476, 0.0194428538125939,
0.0464771821653864, 0.0257204433555745, -0.000805859957640792,
0.0258752236753201, 0.00169526561907242, 0.00845686232849219,
0.0248138846673567, 0.0499029147276336, -0.026119026588276,
-0.0506759613875208, -0.0186567955284256, 0.00666071759448302,
0.00540296976899718, -0.0716488022451813, -0.0217757529500649,
-0.0338310975042987, -0.0341928029469273, -0.0223690567604255,
0.02094411401049, 0.0387905936222523, -0.0834270093258965,
0.0341064407380287, 0.00713508490452064, -0.127295832074014,
-0.237585142941304, -0.13633100805025, 0.0404317628621166,
-0.0701342930682682, -0.154994464337936, 0.137138389891867,
0.266473867978314, 0.149346235523739, 0.0512020926289552,
0.0972987430985086, 0.046678198308291, 0.0691887409841002,
-0.0483228606644157, 0.0438380166785084, 0.108567878481663,
-0.022344000031356, 0.0458931252688222, 0.0821382803979602,
0.0776712501269335, -0.0782288163911569, -0.0717866494829638,
-0.0441555801962854, 0.113855257071555, 0.0431730594966379
), Q6 = c(0.00118677849601953, 0.00724360975622851, 0.0123824360629239,
0.0142478263596263, -0.0252780297511086, -0.00458043370995016,
0.00425970918248347, 0.00473335833299583, 0.00103988624384509,
0.0228995862136097, -0.0190717885561753, -0.00298582160704901,
-0.025769756431826, -0.0257332343706903, 0.00216414522880129,
-0.00936931720546169, -0.00985230230491503, 0.00609259379175739,
0.00941518145826525, 0.00373315824443837, -0.00819300432209647,
-0.0176053121809113, 0.00728010618219631, 0.0207322622070837,
-0.0610342324124761, -0.0392088518323502, -0.0193263756937437,
0.00198527245904931, -0.00069970323347647, -0.00372528787239923,
-0.0155644639126446, 0.0354216053007016, 0.0671879799172312,
0.0600266885889786, 0.0304185023392288, 0.0153397287012177,
0.00380275007463411, -0.0112734150656633, 0.00937544251426276,
0.0172378844137663, 0.0325654123526421, 0.00585103266805692,
0.00344031132105193, -0.00443425955861904, 0.000415410666288515,
-0.00915583212652102, -0.0100144730517803, 0.0177554300128117,
0.0163402932978495, 0.000943194008399206), R1 = c(0.0182182283776942,
0.0133596019044421, 0.0432659004262889, 0.0221001061009796,
0.0105907624828407, 0.0239597644983188, 0.000582050596458943,
0.014147774983186, 0.0234533732901644, 0.0317608721171364,
-0.0166806564027188, -0.052434190706138, 0.0100713259540498,
0.0101734290645623, 0.0288354928293034, -0.0605050812338745,
-0.0117308063666151, -0.0572323586752662, -0.0272877553780779,
-0.0120147655606391, 0.0419646855503247, 0.0324565952813083,
-0.0993208162860145, 0.0395097806733453, 0.0238556437261408,
-0.114658174673633, -0.2195395447872, -0.137508094828707,
0.074964741726552, -0.0604685437878159, -0.111606039290815,
0.136833144806414, 0.222703023385423, 0.0841373058009376,
0.0141210132573047, 0.0945658775885383, 0.0720258311603175,
0.072218863181222, -0.0464783244216175, 0.0196372191978457,
0.0764585826402174, -0.0109085058330569, 0.0359374463515418,
0.0818041172339742, 0.0660486282980199, -0.0707042835229565,
-0.0683338724528508, -0.0610787198706517, 0.10245202132339,
0.0336024502788171), R2 = c(0.0191115892525381, 0.0213770552106516,
0.0495591080020083, 0.0217964101541805, 0.0144038778845475,
0.0184814835192124, 0.0105638044882981, 0.0169188201074749,
0.0276594408901124, 0.0348981320533056, -0.00601471285249273,
-0.0742367928195745, 0.00395378441574753, 0.0204693427515786,
0.0119432134599844, -0.0874038103063021, -0.0151874175793209,
-0.0472985114867765, -0.0280096128634695, -0.0160812378016462,
0.0321308743545342, 0.040546940059076, -0.0948356372283535,
0.0107826096321911, 0.0257959865133892, -0.111356276103297,
-0.231763659704638, -0.114593808207563, 0.0521066918649241,
-0.0585007082261173, -0.109123376446412, 0.126602824255329,
0.173736381165564, 0.199924017362175, 0.0481556947170322,
0.0973811981639015, 0.0359796749373038, 0.0813126198664245,
-0.0512295355950761, 0.0279254079344163, 0.086866979370594,
-0.0192548779536499, 0.0447691648075989, 0.0862634325791489,
0.0697143276875948, -0.0692263805833664, -0.0500105867630836,
-0.0588590458196327, 0.106730721635263, 0.0421188281435415
), R3 = c(0.0127029458612358, 0.0018533759915124, 0.0760172229180238,
0.0367249979117247, 0.0150598922914917, 0.0336805265497945,
0.00793725637078958, 0.00747404394924289, 0.0274879617237065,
0.043333103669918, -0.00161559239160282, -0.0455316266423957,
-0.00214711870702203, 0.0248726461836401, 0.00653189279270605,
-0.0578474430051428, -0.00753182224084245, -0.0497961950688571,
-0.0215957843383809, -0.0186999944968934, 0.0484307593124901,
0.0311984415753566, -0.0821598079518168, 0.0100672285713556,
0.0372802787529577, -0.104028042014104, -0.222058497109385,
-0.147313185333738, 0.058569009115331, -0.044662665977512,
-0.109997225946555, 0.0740040206123078, 0.240124115068233,
0.0658274676989834, 0.0230167129023561, 0.0893684046831913,
0.0691791022696998, 0.0935037055760548, -0.0623467636644952,
0.0443609426523667, 0.0841050150254741, -0.010595198663421,
0.0531204943650837, 0.0889886676318655, 0.0717397607923485,
-0.0666121329043526, -0.0679554782502061, -0.0619185083705071,
0.113668574986972, 0.0426805703464197), R4 = c(0.0380760367129327,
0.0177375553170367, 0.0434032638099822, 0.0288078728030292,
0.00992978596216649, 0.0292202896891021, 0.0000603359551190975,
0.0159922639270591, 0.0343884360605202, 0.0439464803116257,
-0.0138187383575441, -0.0420847227142335, -0.00232802864713809,
0.0234398999431073, 0.0192280943826554, -0.0652622771727051,
-0.0129287081223056, -0.0621169225429621, -0.0188534586231707,
-0.0144850139328243, 0.0297268555763311, 0.0285599283377065,
-0.0822735971636855, 0.0204183204990269, 0.032745768708656,
-0.105603577501441, -0.221743181027705, -0.13083768618741,
0.0451022094242408, -0.0511348958540317, -0.117597592112605,
0.135103916679692, 0.220409599165432, 0.123643858561056,
0.0412763113887445, 0.114076890036475, 0.0618001339957569,
0.0751807434389775, -0.0761590390584388, 0.0367453217535741,
0.0741501663098758, -0.0209351147382463, 0.0423510899687777,
0.100368821441917, 0.0695076535685885, -0.0721797128413838,
-0.0600897558968101, -0.0664215180686919, 0.128039957194454,
0.0470262161757679), R5 = c(0.0392411376774867, 0.0154176355104196,
0.040917916701852, 0.0218273582628919, 0.0129334794884874,
0.0272767829214404, 0.00362824471430165, -0.000676154777673734,
0.0324915392070016, 0.0312519866611661, -0.00752454226284161,
-0.0479068156734558, 0.00623306676125675, 0.0175638068591043,
0.0180622711059288, -0.0716966531562826, -0.0105557651114313,
-0.0470363381042701, -0.0319284024370003, -0.0274867890109039,
0.0328552378238075, 0.0503210109454812, -0.0847538417074522,
0.0213618251884607, 0.0268119067996639, -0.0900801570280097,
-0.229113867007717, -0.128659614134882, 0.0757805549254453,
-0.0540399315416828, -0.121830787213285, 0.122317733604241,
0.218198170804459, 0.0991190501510919, 0.0380010340764608,
0.119750604540555, 0.0560657704951905, 0.0599450854028368,
-0.0472973800122937, 0.0261746785776476, 0.0965835597718561,
-0.025910690013656, 0.0420420706295301, 0.101981995863621,
0.0648998978320577, -0.0930218340085276, -0.0682703531336771,
-0.0717185642128733, 0.123732482524253, 0.0358365680790375
), R6 = c(0.0210229092997925, 0.00205803360597752, -0.0023479837244369,
-0.000272747838087638, 0.00234271700564669, 0.00331701842312161,
0.00304619411784271, -0.0148239297608598, 0.00903816591683728,
-0.000508885455970276, 0.00915611413987719, 0.00452737503268219,
-0.00383825919279309, 0.00739037779454201, -0.0107732217233747,
-0.0111915719224081, 0.00117504125518384, 0.0101960205709961,
-0.00464064705892239, -0.0154720234502648, -0.00910944772651717,
0.0178644156641729, 0.0145669745785623, -0.0181479554848846,
0.00295626307352316, 0.024578017645623, -0.00957432222051705,
0.00884848069382546, 0.000815813198893262, 0.00642861224613316,
-0.0102247479224694, -0.0145154112021735, -0.00450485258096373,
0.0149817443501543, 0.0238800208191561, 0.0251847269520169,
-0.015960060665127, -0.0122737777783852, -0.000819055590676188,
0.00653745937980193, 0.0201249771316388, -0.0150021841805991,
0.0061046242779883, 0.020177878629647, -0.00114873046596223,
-0.0223175504855711, 0.0000635193191737132, -0.0106398443422216,
0.0212804612008627, 0.00223411780022038)), row.names = c(NA,
-50L), class = "data.frame")
Firstly, nothing in the question has anything to do with lpSolve or with retbar so please remove this junk from the question.
covs is singular so it cannot be inverted. Note the essentially zero eigenvalues below. Evidently the columns that are linearly dependent on the remaining columns are those set to NULL so removing them eliminates the singularity. If a Moore-Penrose generalized inverse is sufficient then MASS::ginv(covs) could be used.
covs <- var(rets, na.rm = TRUE)
eigen(covs)$values
giving the following eigenvector which includes 4 near zeros:
[1] 1.147251e-01 4.508339e-03 3.566784e-03 9.437460e-04 6.489510e-04
[6] 4.975564e-04 3.300602e-04 2.840001e-04 2.674243e-04 2.202487e-04
[11] 1.428033e-04 9.985863e-05 9.513909e-05 7.955750e-05 6.892488e-05
[16] 5.715785e-05 4.055359e-05 3.127846e-05 2.710167e-05 6.273551e-06
[21] 6.322894e-19 2.240421e-19 -3.041137e-19 -9.827006e-19

How to plot the forecasted values against actual values observed later in R?

We used the R library forecast to make predictions for the next 24 hours. We have the following:
fore_cast=forecast.tbats(model,h=24,level=90)
fore_cast
Point Forecast Lo 90 Hi 90
5.380952 6270.778 5389.089 7296.643
5.386905 5458.096 4557.375 6536.743
5.392857 5219.995 4248.967 6412.814
5.398810 5187.102 4126.390 6520.328
Now we have 2 problems:
We need 'time' (in hour e.g. 01,23,19 etc) instead of 'point'.
We wish to plot the trendline against time showing the actual observed
values against these predicted values. We have loaded actual observed
values from a CSV file.
We tried:
actual_data = read.csv('actualdata.csv')
plot(actual_data,fore_cast)
Doesn't work, and using plot(actual_data) just shows some points in a straight line instead of curved trendline.
EDIT:
Sample output of fore_cast from dput:
structure(list(model = structure(list(lambda = 0.000438881055939422,
alpha = 0.65694875480321, beta = -0.0983972877836753, damping.parameter = 0.800419363290521,
gamma.one.values = c(-0.00150031474145603, -0.00124696854910294
), gamma.two.values = c(0.0023600487982342, -0.002465549595849
), ar.coefficients = NULL, ma.coefficients = NULL, likelihood = 13202.294346586,
optim.return.code = 0L, variance = 0.00855092137349485, AIC = 13258.294346586,
parameters = structure(list(vect = c(0.000438881055939422,
0.65694875480321, 0.800419363290521, -0.0983972877836753,
-0.00150031474145603, -0.00124696854910294, 0.0023600487982342,
-0.002465549595849), control = structure(list(use.beta = TRUE,
use.box.cox = TRUE, use.damping = TRUE, length.gamma = 4L,
p = 0, q = 0), .Names = c("use.beta", "use.box.cox",
"use.damping", "length.gamma", "p", "q"))), .Names = c("vect",
"control")), seed.states = structure(c(7.44188559667267,
0.00357069100887873, -0.0664300680553579, 0.0229067500159256,
0.00460111570469819, -0.00772324725408007, -0.000610110386029883,
0.00568378752162509, -0.0084050648066819, -0.0324093004247092,
-0.000720936399990958, -0.00705790547321605, -0.00738992950838566,
0.00180424326179638, -0.00107745502434416, 0.00242014705705761,
-0.01824679745657, 0.0123019701003545, -0.0245935735677402,
0.0181321397860132), .Dim = c(20L, 1L)), fitted.values = structure(c(1598.57443298879,
1435.74973092922, 1397.92464316794, 1296.90202189518, 1440.3201303663,
1544.11695101118, 1777.97079874181, 1766.50571671645, 1925.27360388028,
1863.26963233038, 1773.08363764691, 1887.26580055295, 1887.48006609474,
1841.66200850472, 1991.90290660363, 2233.04775631848, 2081.30246965768,
1872.12639817609, 1899.38583561568, 2213.43437455052, 2214.00832820531,
1745.36311914995, 1678.67975050944, 1502.35472259274, 1512.27350460399,
1456.14165844166, 1464.3803467642, 1517.99443293857, 1484.54280422369,
1382.37041287489, 1452.43700910726, 1545.16934543365, 1440.50974319508,
1475.59742668699, 1544.88546424501, 1790.95280713647, 1916.4267023671,
1928.72804180587, 1819.15839770808, 1916.43079357329, 1836.80043977753,
1720.25638746452, 1730.03629161412, 1614.6048115754, 1599.23641723244,
1635.86950932066, 1543.46360784778, 1641.35066985679, 1608.60556151299,
1651.47649465456, 1475.15006990464, 1403.67294742438, 1507.58932406857,
1666.3170708439, 1696.06132797576, 1543.32187293056, 1704.58043626911,
1914.72424191575, 2109.33624862625, 2092.98934458578, 2222.13355258602,
2084.68677709368, 1962.9230489947, 2045.61547393981, 2140.30565941261,
2097.46130996426, 2126.07936955385, 2226.18935508502, 2269.54492801286,
2300.37314952852, 2398.48786829541, 2303.31270702723, 2332.74139979969,
2146.51487558643, 2101.27480789243, 2111.61910899422, 2053.57840714969,
2046.56606362537, 2073.82870990658, 2094.88831798868, 2334.85185938782,
2541.72156227893, 2502.36031483721, 2398.12240784327, 2266.35832277135,
2151.05248890962, 2266.88803633019, 2366.19453856405, 2399.97570044332,
2341.74959623409, 2144.33465155869, 2102.91952061083, 2214.48622101851,
2179.48115699957, 2288.28092735955, 2224.55218736155, 2195.1506809087,
2163.94619334319, 2161.41843642149, 2134.75060670667, 2138.77895768654,
2142.84680080931, 2258.55072549978, 2297.90237035988, 2314.94197015208,
2300.99928929609, 2277.39754662665, 2291.06980363364, 2487.04257346235,
2381.05768214413, 2509.40078456481, 2657.61336243367, 2528.65026804303,
2434.2722174014, 2366.04811963942, 2270.6647135766, 2231.33965004538,
2376.51043520344, 2249.42861599343, 2193.98771109322, 2252.12327312365,
2210.76969838623, 2180.50451255189, 2221.92898123682, 2537.84678083006,
2329.57350097532, 2252.82349908982, 2143.92033677754, 2092.3142840022,
2084.70304624685, 2111.18929138546, 2160.05383108999, 2280.94409931504,
2118.22029344747, 2214.65738250204, 2269.05911898631, 2084.26658709038,
2016.04764576402, 2095.57091797435, 2161.07354463394, 2427.77607700887,
2333.91103594967, 2234.23838054763, 2250.71557301013, 2186.97925802073,
2129.51096829218, 2115.40228652934, 2094.89231085691, 2086.41044567131,
2180.94542608489, 2105.38187642016, 2459.45788915933, 2292.36325639374,
2410.75372754831, 2375.56640249604, 2491.11938114866, 2470.51372278037,
2464.95765202085, 2600.85929020727, 2709.48518695182, 2779.77558137814,
2518.29927341458, 2344.06621605191, 2391.56719713269, 2368.68842788795,
2199.93530349068, 2113.92970206565, 2458.96718445444, 3121.97852988865,
2559.40932439262, 2331.12829078836, 2238.54586985577, 2241.91440620202,
2225.29804576634, 2154.14147781021, 2060.57980596908, 2037.30100544426,
2215.93410789353, 2364.42668160056, 2518.72871618042, 2537.34279365294,
2473.76096855791, 2623.63387707374, 2589.08335304697, 2577.0563838788,
2349.53279218826, 2305.52193868551, 2232.63712180453, 2167.50003597208,
2320.23187534213, 2281.86365949586, 2281.21119271599, 2323.2014703372,
2185.94404743238, 2140.21863271207, 2011.67723856012, 1966.52063119589,
2002.67344212857, 1952.41101080662, 1988.37461163105, 2126.75137749373,
2239.14722292367, 2320.98046489603, 2444.91847853015, 2431.69548763034,
2514.73820659393, 2505.85249387343, 2888.19773974179, 2853.20690693738,
2502.20865871069, 2524.56894781003, 2659.52271740553, 2615.9025930681,
2923.69327019152, 2754.76074569658, 2784.59488335761, 2874.24378479002,
2683.41908597168, 2733.83011888159, 2774.1325162997, 2906.41593326865,
2726.06821502751, 2460.21579967528, 2450.8035097605, 2547.39389733175,
2625.60323572861, 2827.94083526683, 2971.92012845614, 3042.90981987278,
2835.00811374845, 2846.98066660519, 2871.21876763166, 2901.99696373824,
2627.47532996657, 2583.75084300313, 2602.68041642846, 2632.8054092953,
2667.85374690972, 2639.10586730146, 2466.95799545022, 2381.06823502402,
2531.32611053776, 2407.14812148706, 2342.75701798463, 2401.73791085847,
2365.50645844524, 2404.50408575777, 2452.57343738519, 2613.15332739214,
2665.50965844576, 2723.8237337447, 2915.09266385617, 2890.17498445896,
2853.6278331055, 2868.1228183545, 2917.07803535669, 2876.59409770233,
2577.82035337979, 2581.91435020803, 2520.20342021937, 2603.37973251208,
2536.03988578365, 2510.83398648802, 2472.80606784857, 2425.51212342113,
2442.02863541673, 2465.73405821711, 2384.42988766816, 2555.51500549788,
2737.77091706275, 2425.00224845814, 2460.17325671183, 2639.16650619329,
2816.37024420397, 2755.69999167982, 2802.64991688288, 2685.12803367301,
2521.77568128564, 2500.99980614696, 2620.41659854805, 2529.25134423133,
2590.14804885984, 2318.80485234464, 2341.88940012276, 2460.21008281205,
2513.70688167177, 2437.71670675479, 2383.29782281743, 2499.36244454453,
2472.98602901478, 2491.10649022417, 2350.1405559119, 2362.78308814045,
2431.3911847573, 2321.15216823049, 2355.74203614213, 2429.60523843166,
2355.61947983433, 2346.3751018515, 2453.82214513707, 2542.98125962684,
2342.43364707529, 2302.17741211575, 2388.93541944219, 2435.41878657221, ....
Sample output from dput for actual observed values:
structure(list(index12 = c(6297.416944, 5406.865556, 4718.355556,
5304.729167, 4968.014722, 5081.130833, 5544.955, 4655.009444,
4269.023056, 4346.588333, 4511.455833, 5102.57, 4818.673333,
4862.343056, 4785.176667, 5385.005278, 6469.080833, 7166.025278,
7010.708333, 511.114167)), .Names = "index12", class = "data.frame", row.names = c(NA,
-20L))
The value of Point is unusual in spite of hour unit data. I think you failed to make a model.
Here is my example:
actual_data <- structure(list(index12 = c(6297.416944, 5406.865556, 4718.355556,
5304.729167, 4968.014722, 5081.130833, 5544.955, 4655.009444,
4269.023056, 4346.588333, 4511.455833, 5102.57, 4818.673333,
4862.343056, 4785.176667, 5385.005278, 6469.080833, 7166.025278,
7010.708333, 511.114167)),
.Names = "index12", class = "data.frame", row.names = c(NA, -20L))
# I suppose that actual_data was taken per hour.
num_actual <- as.numeric(actual_data[,1])
model <- bats(num_actual)
fore_cast <- forecast(model, h=24, level=90)
fore_cast # Point is from 21 to 44 because of length(actual_data)=20 and demanding predictions for the next 24 hours
# Point Forecast Lo 90 Hi 90
# 21 5063.207 2902.187 7224.226
# 22 5108.114 2946.988 7269.241
# :
# 44 5108.114 2944.629 7271.600
# plot() has forecast method. It draws actual_data and prediction, and paints Lo90-Hi90.
plot(fore_cast, main="")

Resources