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
Related
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
I am using the SVM model for the classification of the data given below, but I don't know why I am getting this error. I have tried using two methods but both are not working. Please help me I am stuck for a very long. I have seen many posts here and tried to specify my model for classification but no results.
My data:
structure(list(pCAMKII_N = c(-0.145868903106222, -0.0757245672281776,
0.23642582674556, 0.148460249143042, -0.00305230227892469, 0.0585561745843138,
-0.148682825543474, -0.21730129212525, 0.459967321113158, 0.422894418061546,
-0.0575744512697957, -0.127564153510276, -0.242697988154887,
-0.095402375827381, 0.0140296834402993, -0.0497934688280284),
pCREB_N = c(-0.0825121744625299, -0.026500034184616, 0.0674710705932882,
-0.171872159375326, 0.0599673008600893, 0.20274815322096,
-0.138321776880784, -0.179229652914255, -0.031683391484602,
-0.107073356219089, 0.0795112065683711, 0.0230878800052553,
-0.101810049763974, 0.141596706516054, 0.175052271845758,
0.0962492148671607), pMEK_N = c(-0.011827795918493, 0.0651085636651456,
0.0372073300493682, -0.0758375679929981, 0.038855171657283,
0.162735732819232, -0.129245969397597, -0.10183076411972,
-0.030313508584495, -0.0402009321267793, 0.0265091904210039,
0.0384635318143068, -0.145082961476379, -0.00383809286152744,
0.00274224616628268, 0.0325875706999738), pNR2A_N = c(-0.040694436939677,
-0.126422726919893, 0.327029496785507, 0.11289764061805,
0.00949037400844992, -0.0370143413154391, -0.0445050341199518,
-0.0875679863319538, -0.0318024269145471, -0.0990796159280345,
0.114103842731325, 0.0684955162565601, -0.0517765103296767,
0.0262937180568668, 0.0186704564656926, -0.069607116867091
), pPKCAB_N = c(-0.0732668154024626, 0.259508683035786, -0.156388727351903,
-0.128555140589917, 0.233485439385613, -0.109922421599626,
-0.230899862755971, -0.275680739843144, 0.202586893320354,
0.128569221313288, -0.187404269824716, -0.123823456903658,
-0.0510954627942524, 0.224263475958852, -0.110903224987034,
-0.0622911739357286), pRSK_N = c(-0.0830647198678661, 0.171345235902955,
-0.00771685629829743, -0.153792422272828, 0.0775638466765593,
0.0562653498716256, -0.138802407016646, -0.115702091265824,
0.161592613345935, 0.120453263851679, -0.0389173648044295,
-0.0711265266002543, -0.207578315767319, -0.0270749356104633,
0.0589442953743869, 0.0144541906539012), AKT_N = c(0.0481798874438209,
-0.0923315388558725, -0.108885641561443, -0.105416833062579,
0.144880510212411, 0.00523331467580219, 0.0328578246677392,
0.0571445022606188, -0.0209256486347021, -0.0730029998614634,
0.0440023583125468, 0.0717278333163182, 0.0196560602422922,
0.0988713938163715, 0.0527286790966814, 0.0229037502299382
), BRAF_N = c(-0.00321939692704801, 0.0962073093317588, -0.0677402898524546,
-0.067209980101031, -0.0192180601759131, 0.0499710838529006,
-0.0685860451987449, -0.0621210254646294, 0.0464452196252293,
0.0717595906404571, -0.0808646010953599, -0.070139309127312,
0.0260226905885634, 0.0307477583500104, -0.0495839406552054,
-0.0605696564634389), CREB_N = c(0.0633377024959499, 0.0719351180508572,
0.0554860017614535, -0.0754709592333137, -0.051730811130647,
0.0770585706175764, -0.119490365368989, -0.101979827161643,
0.0390935428793637, 0.0334190803939948, -0.0231648718807617,
0.175244016989004, -0.199464488371739, -0.0830526740916612,
-0.0236000029056659, -0.0555939459680455), ERK_N = c(0.113758147959477,
-0.0935376622896181, -0.194533549084613, -0.202343017546552,
0.368811506067506, 0.0211924441765911, -0.166177103411079,
-0.239377414372715, 0.0512242092661902, -0.030723497203822,
0.00664926832340125, -0.105494671248667, 0.143740808738886,
0.306473059519756, 0.068383724577022, 0.0171957013321164),
GSK3B_N = c(0.0496851372868314, 0.0965673122890421, -0.122194260011564,
-0.113614901308566, 0.147165890990766, -0.0568100186969033,
-0.150554531109297, -0.188598927874271, 0.0729314311629536,
0.0534454310403283, -0.0530979322493377, -0.108715383018256,
0.0774398337859832, 0.133178525946526, 0.00917139328707758,
0.00415362892452407), JNK_N = c(0.084671436503407, 0.091451395958942,
-0.0735719764555032, -0.128089296490928, 0.0482424225269525,
0.136559678562216, -0.0983547253737015, -0.0994914255127194,
0.00287013911408683, -0.0207264777165356, -0.0425235674499462,
-0.0328911666055918, -0.102415581508767, 0.0426548346554378,
-0.0453706640514963, 0.0837146521123543), MEK_N = c(0.0415145904202766,
0.000112891679066114, -0.0947656593375573, -0.161573116350825,
0.217458153608386, 0.132508968100251, -0.177468380610068,
-0.18842935475728, 0.00445721815704893, -0.0539245065836939,
-0.00307155552655238, 0.0116656936964918, -0.100533579935951,
0.19149971269713, 0.15252996223312, 0.0956503457831564),
RSK_N = c(0.0191395815813382, 0.0714942086955356, 0.0161998863368589,
-0.184560332102979, -0.0264979202843543, 0.298908704096619,
-0.0968942910305665, -0.0189051673871464, 0.0861641375591587,
0.0160470100470935, -0.0682290713635209, -0.0518589639648677,
-0.23241046414349, -0.0542963774080875, -0.0873418795312474,
0.0210347924349621), APP_N = c(-0.0806791681338731, -0.0704201146133004,
-0.190200351582733, -0.162718360121692, 0.0303369406177179,
-0.0860104704967967, -0.162468694656265, -0.186756215303488,
0.149403011555697, 0.0234829670280346, 0.0759128457278766,
0.0934903179979386, 0.105907786308873, 0.361038543968712,
0.0786334044736174, 0.0784404724592734), Bcatenin_N = c(-0.0609377198837611,
-0.111471497502357, -0.0866850028872295, -0.134271109042703,
0.197879694030571, -0.025717790316679, -0.114779722205815,
-0.215166874658, 0.093663448787465, -0.0106410825979063,
0.0856165346234392, -0.0915811784652404, -0.0313801262102451,
0.220238809782054, 0.13789742580927, 0.141644968613549),
SOD1_N = c(-0.123838690502292, -0.144130158837663, 0.0727560720797953,
-0.0681671745118475, -0.123567494179754, -0.117023734873497,
0.253293745880715, 0.185224720298962, -0.11802985927293,
-0.143547249900102, 0.47503997511273, 0.434217391632064,
-0.15212803487222, -0.106940962031447, 0.100783205025425,
0.363303202025603), P38_N = c(0.0135880916776172, -0.0645721208196919,
0.0948843285406695, 0.159312513843406, -0.0770493007707386,
-0.107486334544236, 0.150819778231829, 0.217491472288877,
-0.121236098381148, -0.130587965985436, 0.0116164053669351,
0.144776197754908, -0.158244000282848, -0.13848656873568,
0.0539113322660321, -0.0721957070846476), DSCR1_N = c(0.0873105225377593,
-0.0399938541478373, -0.0423959808617725, 0.0615326056646092,
-0.0290529787358271, 0.0522204008570095, -0.0475227862097225,
0.0308446987929902, -0.0305665225181376, -0.0607456490874483,
0.0279790218604084, 0.100583918291236, -0.0206748799372295,
0.010415281028328, -0.0414425004790977, -0.0489198196614915
), NR2B_N = c(0.106299550498296, -0.0381078612482542, -0.00101679889831333,
0.0267320329216243, 0.112439396399247, -0.064052196844109,
-0.00641666140192624, 0.0613191854808411, 0.0168607292707449,
-0.0487573287523953, -0.0439584530719966, 0.00809905456774659,
-0.0667726467406412, 0.0694971401183639, -0.000212905759537097,
0.0163350414150324), pNUMB_N = c(0.202564418361944, -0.00200124352888242,
-0.0998561853278869, 0.037524195854859, 0.149886434896155,
0.195128273020257, -0.195094705493063, -0.140281085662283,
0.0590093896988644, 0.00582004770130322, -0.0546687365873218,
0.0551625036706637, 0.0777195935539914, 0.036101539026412,
0.0107519309923, -0.103469871374173), TIAM1_N = c(0.058847821102376,
-0.159760016471791, -0.0979806570256097, 0.0531257042802172,
0.103564419565561, -0.0238368367628548, -0.0729210307202995,
-0.06325777516333, -0.0281144756311353, -0.0884600747007959,
0.00512281704622422, 0.0615056543435742, -0.00313409869767671,
0.0899369569840853, 0.120845861658354, -0.00443043623680605
), pP70S6_N = c(-0.217859954507296, 0.243521933127221, 0.0425412592499045,
0.0832466388027541, -0.0874992096268626, -0.14876403578688,
-0.00476984544201101, 0.0106283984338779, 0.114328759061199,
0.125171996276406, -0.0925437220067121, -0.0570200090555343,
-0.252313164764891, -0.183959220656612, 0.189234923062614,
0.179602221371295), NUMB_N = c(0.0507161136495314, -0.0428893884462266,
-0.0737803369486708, -0.125816787402445, 0.157329290628144,
-0.0618269592229841, -0.121271771020323, -0.208391773663935,
0.0398518709801874, -0.015557253715229, -0.0686033888733257,
-0.146899366608736, 0.229868831769603, 0.328004434107362,
0.262082754277244, 0.270980403077601), P70S6_N = c(-0.0467645544881666,
-0.0513422563937406, 0.0806193466797829, -0.097604174996586,
0.169381505159102, -0.10953472581413, -0.0762873839439222,
-0.137957724239911, -0.0404929923772219, -0.112679782727059,
0.0478687778434949, -0.135047834380878, 0.235505540876976,
0.101996139976229, 0.0881984401256723, 0.0308682316870565
), pGSK3B_N = c(0.0726318660370534, 0.0113934692941635, -0.0784493639363762,
-0.129201494480153, 0.157796847802845, 0.23002474684606,
-0.156189105610425, -0.139272331325838, 0.118225045060094,
0.100304800513178, -0.0300757618933809, 0.0285299986456296,
-0.0120541561865572, 0.0908216848045133, -0.0023908457607024,
0.0089400750177918), pPKCG_N = c(-0.286386712047411, 0.265957237376396,
0.0737964172058239, -0.0759384400199, -0.0177238455253068,
-0.261634570955355, -0.253741047251584, -0.256650485194398,
0.134270402692566, 0.120849091119421, -0.146949388514596,
-0.142381255596242, -0.324527167558674, 0.195095873727953,
0.208752130225386, 0.246345320116692), CDK5_N = c(0.0835756577065185,
0.00364250782584705, -0.0635878598042922, -0.0665527642492147,
0.0498548879577531, -0.0037462363944042, -0.0709716342392349,
-0.109665096982383, -0.00693856902849091, 0.0043142382793781,
-0.00379427922410826, 0.0233969910641444, -0.000723497291038827,
0.106033840892453, 0.029827781661049, 0.0297508490072604),
S6_N = c(0.168888926042562, 0.230803056253277, -0.154902829994192,
-0.269491504226569, 0.142290171760069, 0.252241256219668,
-0.23854742286132, -0.264415247456924, 0.290083441282089,
0.238143298906295, -0.198459186518937, -0.263240335960755,
0.238832926146062, 0.35530004861393, 0.427790444668465, 0.360513465094153
), ADARB1_N = c(0.224098318811728, 0.0338977810779033, 0.116024199822639,
-0.00457055801051897, 0.530704385640093, -0.178020136682188,
-0.113465216543545, -0.173452014027142, 0.00633272386184758,
-0.0237300986226981, 0.139970553648416, 0.00713778435199307,
0.356303393951797, 0.328108176871799, -0.103822560250247,
-0.160096407917707), RRP1_N = c(0.00159121579454942, -0.0299422881516384,
0.0173826784335047, 0.0386298578057867, -0.022152469642015,
0.0369774839239829, -0.0197907278638186, -0.0201116884888817,
-0.016726870724063, -0.0138128805216459, 0.00747529027834608,
0.0385018374429109, -0.0165448322480326, -0.00614007382478539,
-0.00733137421781927, 0.0183421735187617), BAX_N = c(0.0348507900184639,
-0.169715973558917, 0.0312101948023616, 0.0728175524004573,
0.179257945173096, -0.00628218585999311, -0.114699647957541,
-0.213302817321221, -0.0219721111119517, -0.0411959352332957,
0.0140823449452806, 0.00562779088047583, -0.0465748954281123,
0.166914376799791, 0.121181906942324, 0.0465930748380351),
ERBB4_N = c(0.226825268882082, -0.124939501170309, -0.0779332590062461,
-0.18657539448526, 0.186503290026721, -0.209722491963456,
-0.0376960514068148, 0.0222951541745705, -0.058799632488138,
-0.106621802599657, 0.037095159045507, -0.0713172478048624,
0.0826014680466721, 0.0644672868926184, -0.022902877277575,
0.0811348220744181), nNOS_N = c(-0.0597607386610167, 0.0694317666060796,
0.0267840157110256, -0.0466611419857235, -0.0427174888142891,
-0.312236651256378, -0.010954182164099, -0.152991551731999,
-0.0500742377998905, -0.112776761155327, -0.0702701990622843,
-0.158725995917858, -0.170582110044521, -0.195995554048211,
0.270601021309697, 0.164312802991015), Tau_N = c(-0.0295470448997678,
-0.0135843635099774, -0.0532058617661047, -0.0555870385379599,
0.0413976507530296, -0.134898190226349, -0.0588315550075754,
-0.0795207957893949, -0.00171411389248874, -0.0482028991095779,
-0.132181492884161, -0.16272346727488, 0.0684355887357164,
0.0845081538871629, 0.17928411442039, 0.399425311619017),
GFAP_N = c(0.1022369732202, -0.0375872399271431, 0.0389750353783662,
-0.0504675751546967, 0.0274358635290079, 0.1734228779599,
-0.0412006018348187, -0.0716080720004096, 0.00463136477041947,
0.0395185137074335, -0.0488608095557386, 0.133429595736969,
-0.0456410825935039, -0.0308800819276867, -0.0205041295367554,
0.00291773400108061), GluR3_N = c(-0.030610619693228, -0.0419884945813332,
-0.0215878967844794, 0.13788987742286, 0.0097421522245054,
-0.185481343626263, 0.039394235524668, -0.0423606094227236,
-0.0300386175931323, -0.0704781156851588, 0.149635559983053,
0.194784934048682, 0.0579351879333201, -0.029201096262343,
0.035471474252518, 0.0130390262499429), GluR4_N = c(-0.0645767955225773,
-0.051538941109314, -0.0313732251039657, -0.0141460065921882,
-0.00417582031288004, -0.029593478043205, -0.0337244128285424,
-0.0473718497413239, -0.0076614057457667, -0.0274641649555311,
0.0567450285050144, 0.131417882380042, 0.0167002653120917,
0.0102756570041332, 0.0589477012145904, 0.0282615479355968
), IL1B_N = c(0.0271273847003715, -0.105491449847318, 0.0437609140660753,
-0.100682647720751, -0.0220718458071589, -0.255060461104892,
0.136556106808522, 0.171611061468201, -0.107978458154497,
-0.138468912721386, 0.0906412612736424, 0.103367168201442,
-0.0471777535915392, -0.0996457367924041, -0.0253085398636734,
0.0972606458616279), P3525_N = c(0.282068129966564, -0.00165311433635766,
-0.0922619335624527, -0.153415327839175, 0.123335275814776,
-0.217141845924011, -0.0794347237762894, -0.0633312926140292,
-0.0550134841848069, -0.0335943662560428, -0.172561096964795,
-0.0591245566896425, -0.0903407471772672, 0.0672553394698634,
0.277963667780744, 0.280422376361652), pCASP9_N = c(-0.0809064432825608,
-0.0137019165208861, 0.177743120582825, -0.0475158803923548,
0.193740256728041, -0.234087587902465, -0.13810712700627,
-0.123144569174683, -0.159086554429722, -0.196839206663645,
0.272409729812092, 0.163528529740624, 0.094264422008515,
0.0323567060275672, 0.132123054461642, -0.0232714678908218
), PSD95_N = c(0.0540563342629853, -0.0442860567878406, 0.192681249153854,
-0.0499306400945902, -0.0256836260381356, -0.130320516544179,
-0.0318622026430037, -0.05550691698767, -0.0550237612521986,
-0.0975383913984803, 0.0610109420236561, -0.016528638117965,
-0.0355453200230897, 0.0361199546017388, -0.0438265148666351,
0.15961796487275), SNCA_N = c(0.10038812821577, -0.203187652543977,
0.132600250445984, 0.0870009029169576, -0.16121896139518,
0.00675222688338345, 0.201408060453561, 0.166171601944603,
-0.244202510820346, -0.184881118438059, 0.0158087569191595,
0.163733417301441, -0.19931602328197, -0.0822025824650802,
0.0270161636801945, -0.0311533368903992), Ubiquitin_N = c(0.113890598772724,
-0.0571595522614428, 0.251655448625955, 0.0290662757157521,
-0.113226757122626, -0.118822873950306, -0.0895156964787369,
-0.115101576386724, -0.0883300072975741, -0.0451690155410069,
0.0356232623609365, 0.10502000854939, -0.242738889727437,
-0.000642607498821009, 0.023342908881478, -0.000996135171924353
), pGSK3B_Tyr216_N = c(0.171426581336935, 0.21964402951554,
-0.146777292906524, -0.180066591627815, 0.0607373096178199,
-0.338285372919054, -0.192946966367207, -0.179745246639312,
-0.0202782074462171, -0.0754752662878523, -0.0458616948609926,
-0.0702022161357589, -0.0329854942199789, 0.103988666502327,
0.160536360262989, 0.130136693548004), SHH_N = c(0.167413839912217,
0.177150215231475, -0.11706030681231, -0.103724722509818,
-0.105962891517635, -0.163445660332417, 0.26057121922903,
0.323113244273389, -0.154575367677723, -0.203841975554592,
-0.196762498711561, -0.0810430316565208, -0.164628664080618,
-0.0670952384804719, 0.0701383687380666, 0.0664763199521191
), BAD_N = c(1.38627815493717e-17, 0.108885085055258, 1.38627815493717e-17,
0.204958164782363, -0.109706654809739, 1.38627815493717e-17,
-0.0384428632142642, 0.113022480455563, -0.0230560609956582,
0.00709971300305052, 0.0944175354012559, 0.258234547510358,
-0.172555989304076, -0.115571199147466, -0.0361880642339753,
0.0555296363853341), BCL2_N = c(0.174830527318015, -0.0351916650236411,
4.47594455930353e-17, 0.16122241936817, -0.153630588784925,
4.47594455930353e-17, 0.0259483341117695, 0.10217304978238,
-0.113426224559798, -0.0493655879422875, 4.47594455930353e-17,
4.47594455930353e-17, -0.176439561319639, 0.00332642384209326,
-0.112281307284837, 4.47594455930353e-17), pS6_N = c(0.0544957045743841,
-0.215498231280905, 0.176330539472927, -0.0180427806336791,
0.0405134698307664, -0.196511194503692, 0.0896380150212792,
-0.00178437398723737, -0.111094705650147, -0.164447287557879,
0.0171495879982054, 0.17357748138507, -0.0854290326165926,
-0.136862309389642, 0.0486149936008245, 0.0468734606012612
), pCFOS_N = c(-3.94541709971541e-17, 0.144688662108845,
-0.0523244997808654, 0.183632906884199, -0.0943286515483249,
-0.154870867441355, 0.0273962871834048, -0.0446413560661544,
-0.151142681858317, -0.142540841364996, -0.0409951996945863,
0.209594994520851, -0.07067492413067, -0.0951447007727713,
0.0510274910486943, -0.10813485862325), SYP_N = c(0.1699192032091,
-0.007408249850341, 0.105706192867166, 0.030169211570003,
0.264311270468507, -0.174104272666862, -0.0320510372603059,
-0.146577591364027, 0.0748281855773365, 0.0921704540339964,
0.125632959616699, 0.101821683371461, -0.0991623357830543,
0.24508774982114, -0.0514314977651764, -0.0356173972612358
), H3AcK18_N = c(0.00318526058246947, 0.030516867974744,
0.0458325444094067, 0.0823406614957822, 0.0655800040015427,
1.34928358031281e-17, -0.066090760307071, -0.0164952261270702,
0.0193438095162109, 0.0214199163861949, 1.34928358031281e-17,
1.34928358031281e-17, -0.18204363595328, 0.0122967495407723,
-0.0057641327038032, 0.315397204575443), EGR1_N = c(0.22091436521792,
-0.0418899558545117, 4.08083728048395e-18, 4.08083728048395e-18,
-0.132192787939268, 4.08083728048395e-18, 0.170088635236541,
0.14416021675064, -0.136632103055064, -0.105975572333308,
0.157046871143272, 0.390639305517813, -0.135156681648399,
-0.14858326296597, -0.0787741349821091, -0.00864723924102435
), H3MeK4_N = c(2.39945987461847e-17, 2.39945987461847e-17,
2.39945987461847e-17, 0.0613111993676987, -0.0735063751409676,
2.39945987461847e-17, -0.0518102234068636, -0.0134739460741966,
-0.0578126454640219, 0.0237615758984536, 2.39945987461847e-17,
2.39945987461847e-17, -0.176488012336739, -0.119630246017519,
-0.139100793400124, 0.159811180815282), CaNA_N = c(0.228323127723045,
0.156499372224674, -0.218869345925655, -0.347696517405393,
0.258547187716627, 0.0491641323435211, -0.275043873926982,
-0.280621847419711, 0.221404071790851, 0.213771806346338,
-0.138770962441139, -0.179432243201944, 0.104799593812621,
0.247597575511052, -0.0575169171888767, 0.0268368286591718
), class = c("c-CS-m", "c-CS-m", "c-SC-m", "c-SC-m", "c-CS-s",
"c-CS-s", "c-SC-s", "c-SC-s", "t-CS-m", "t-CS-m", "t-SC-m",
"t-SC-m", "t-CS-s", "t-CS-s", "t-SC-s", "t-SC-s")), row.names = c(NA,
-16L), class = c("tbl_df", "tbl", "data.frame"))
my code:
# Splitting the data
trainX <- createDataPartition(np_2$class ,p=0.8,list=FALSE)
train <- np_2[trainX,]
test <- np_2[-trainX,]
Model 1:
svm1 <- svm(class~., data = train, type = "C", kernal="radial",
gamma=0.1, cost=10)
Model 2:
x <- subset(np_2, select = -class)
y <- np_2$class
model <- svm(x, y, probability = TRUE)
pred_prob <- predict(model, x, decision.values = TRUE, probability = TRUE)
Error:
Error in svm.default(x, y, probability = TRUE) :
Need numeric dependent variable for regression.
Here you go. Next time try to include the libraries:
Just transform your class to a factor. In that case, the svm will convert it to numeric for you:
np_2 <- transform(np_2, class = factor(class))
trainX <- caret::createDataPartition(np_2$class ,p=0.8,list=FALSE)
train <- np_2[trainX,]
test <- np_2[-trainX,]
e1071::svm(class~.,data =train, type = "C", kernal="radial",gamma=0.1,cost=10)
which outputs:
Call:
svm(formula = class ~ ., data = train, type = "C", kernal = "radial", gamma = 0.1, cost = 10)
Parameters:
SVM-Type: C-classification
SVM-Kernel: radial
cost: 10
Number of Support Vectors: 16
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?
I have a homework assignment where I need to take a CSV file based around population data around the United States and do some data analysis on the data inside. I need to find the data that exists for my state and for starters run a Linear Regression Analysis to predict the size of the population.
I've been studying R for a few weeks now, went through a LinkedIn Learning training, as well as 2 different trainings on pluralsight about R. I have also tried searching for how to do a Linear Regression Analysis in R and I find plenty of examples for how to do it when the data is perfectly laid out in a table in just the right way to Analyze.
The CSV file is laid out so that each state is defined on a single line/row so I used the filter function to grab just the data for my State and put it into a variable.
Within that dataset the population data is defined across several columns with the most important data being the Population Estimates for each year from 2010 to 2018.
library(tidyverse)
population.data <- read_csv("nst-est2018-alldata.csv")
mn.state.data <- filter(population.data, NAME == "Minnesota")
I'm looking for some help to get headed in the right direction my thought is that I will need to create to containers of data 1 having each year from 2010 to 2018 and one that contains the population data for each of those years. And then use the xyplot function with those two containers? If you have some experience in this area please help me think this through I'm not looking for anybody to do the assignment for me just want some help trying to think it through.
Edit: Here is the results of the
dput(head(population.data))
command:
structure(list(SUMLEV = c("010", "020", "020", "020", "020",
"040"), REGION = c("0", "1", "2", "3", "4", "3"), DIVISION = c("0",
"0", "0", "0", "0", "6"), STATE = c("00", "00", "00", "00", "00",
"01"), NAME = c("United States", "Northeast Region", "Midwest Region",
"South Region", "West Region", "Alabama"), CENSUS2010POP = c(308745538L,
55317240L, 66927001L, 114555744L, 71945553L, 4779736L), ESTIMATESBASE2010
= c(308758105L,
55318430L, 66929743L, 114563045L, 71946887L, 4780138L), POPESTIMATE2010 =
c(309326085L,
55380645L, 66974749L, 114867066L, 72103625L, 4785448L), POPESTIMATE2011 =
c(311580009L,
55600532L, 67152631L, 116039399L, 72787447L, 4798834L), POPESTIMATE2012 =
c(313874218L,
55776729L, 67336937L, 117271075L, 73489477L, 4815564L), POPESTIMATE2013 =
c(316057727L,
55907823L, 67564135L, 118393244L, 74192525L, 4830460L), POPESTIMATE2014 =
c(318386421L,
56015864L, 67752238L, 119657737L, 74960582L, 4842481L), POPESTIMATE2015 =
c(320742673L,
56047587L, 67869139L, 121037542L, 75788405L, 4853160L), POPESTIMATE2016 =
c(323071342L,
56058789L, 67996917L, 122401186L, 76614450L, 4864745L), POPESTIMATE2017 =
c(325147121L,
56072676L, 68156035L, 123598424L, 77319986L, 4875120L), POPESTIMATE2018 =
c(327167434L,
56111079L, 68308744L, 124753948L, 77993663L, 4887871L), NPOPCHG_2010 =
c(567980L,
62215L, 45006L, 304021L, 156738L, 5310L), NPOPCHG_2011 = c(2253924L,
219887L, 177882L, 1172333L, 683822L, 13386L), NPOPCHG_2012 = c(2294209L,
176197L, 184306L, 1231676L, 702030L, 16730L), NPOPCHG_2013 = c(2183509L,
131094L, 227198L, 1122169L, 703048L, 14896L), NPOPCHG_2014 = c(2328694L,
108041L, 188103L, 1264493L, 768057L, 12021L), NPOPCHG_2015 = c(2356252L,
31723L, 116901L, 1379805L, 827823L, 10679L), NPOPCHG_2016 = c(2328669L,
11202L, 127778L, 1363644L, 826045L, 11585L), NPOPCHG_2017 = c(2075779L,
13887L, 159118L, 1197238L, 705536L, 10375L), NPOPCHG_2018 = c(2020313L,
38403L, 152709L, 1155524L, 673677L, 12751L), BIRTHS2010 = c(987836L,
163454L, 212614L, 368752L, 243016L, 14227L), BIRTHS2011 = c(3973485L,
646265L, 834909L, 1509597L, 982714L, 59689L), BIRTHS2012 = c(3936976L,
637904L, 830701L, 1504936L, 963435L, 59070L), BIRTHS2013 = c(3940576L,
635741L, 830869L, 1504799L, 969167L, 57936L), BIRTHS2014 = c(3963195L,
632433L, 836505L, 1525280L, 968977L, 58907L), BIRTHS2015 = c(3992376L,
634515L, 837968L, 1545722L, 974171L, 59637L), BIRTHS2016 = c(3962654L,
628039L, 831667L, 1541342L, 961606L, 59388L), BIRTHS2017 = c(3901982L,
616552L, 816177L, 1519944L, 949309L, 58259L), BIRTHS2018 = c(3855500L,
609336L, 804431L, 1499838L, 941895L, 57216L), DEATHS2010 = c(598691L,
110848L, 140785L, 228706L, 118352L, 11073L), DEATHS2011 = c(2512442L,
470816L, 586840L, 962751L, 492035L, 48818L), DEATHS2012 = c(2501531L,
460985L, 584817L, 960575L, 495154L, 48364L), DEATHS2013 = c(2608019L,
480032L, 605188L, 1011093L, 511706L, 50847L), DEATHS2014 = c(2582448L,
470196L, 597078L, 1006057L, 509117L, 49692L), DEATHS2015 = c(2699826L,
488881L, 626494L, 1052360L, 532091L, 51820L), DEATHS2016 = c(2703215L,
480331L, 619471L, 1058173L, 545240L, 51662L), DEATHS2017 = c(2779436L,
501022L, 620556L, 1092949L, 564909L, 53033L), DEATHS2018 = c(2814013L,
506909L, 621030L, 1109152L, 576922L, 53425L), NATURALINC2010 = c(389145L,
52606L, 71829L, 140046L, 124664L, 3154L), NATURALINC2011 = c(1461043L,
175449L, 248069L, 546846L, 490679L, 10871L), NATURALINC2012 = c(1435445L,
176919L, 245884L, 544361L, 468281L, 10706L), NATURALINC2013 = c(1332557L,
155709L, 225681L, 493706L, 457461L, 7089L), NATURALINC2014 = c(1380747L,
162237L, 239427L, 519223L, 459860L, 9215L), NATURALINC2015 = c(1292550L,
145634L, 211474L, 493362L, 442080L, 7817L), NATURALINC2016 = c(1259439L,
147708L, 212196L, 483169L, 416366L, 7726L), NATURALINC2017 = c(1122546L,
115530L, 195621L, 426995L, 384400L, 5226L), NATURALINC2018 = c(1041487L,
102427L, 183401L, 390686L, 364973L, 3791L), INTERNATIONALMIG2010 =
c(178835L,
45723L, 25158L, 68742L, 39212L, 928L), INTERNATIONALMIG2011 = c(792881L,
206686L, 116948L, 285343L, 183904L, 4716L), INTERNATIONALMIG2012 =
c(858764L,
207584L, 120995L, 344198L, 185987L, 5874L), INTERNATIONALMIG2013 =
c(850952L,
194103L, 126681L, 329897L, 200271L, 5111L), INTERNATIONALMIG2014 =
c(947947L,
222685L, 134310L, 365281L, 225671L, 3753L), INTERNATIONALMIG2015 =
c(1063702L,
227275L, 142759L, 429088L, 264580L, 4685L), INTERNATIONALMIG2016 =
c(1069230L,
236718L, 144859L, 436795L, 250858L, 5950L), INTERNATIONALMIG2017 =
c(953233L,
215872L, 126013L, 404582L, 206766L, 3190L), INTERNATIONALMIG2018 =
c(978826L,
229700L, 127583L, 418418L, 203125L, 3344L), DOMESTICMIG2010 = c(0L,
-32918L, -50873L, 90679L, -6888L, 1238L), DOMESTICMIG2011 = c(0L,
-159789L, -186896L, 335757L, 10928L, -2239L), DOMESTICMIG2012 = c(0L,
-205314L, -181285L, 336615L, 49984L, 59L), DOMESTICMIG2013 = c(0L,
-216273L, -123814L, 293443L, 46644L, 2641L), DOMESTICMIG2014 = c(0L,
-274391L, -182730L, 373439L, 83682L, -755L), DOMESTICMIG2015 = c(0L,
-339996L, -234823L, 452879L, 121940L, -1553L), DOMESTICMIG2016 = c(0L,
-372953L, -228200L, 442633L, 158520L, -1977L), DOMESTICMIG2017 = c(0L,
-316879L, -161387L, 364465L, 113801L, 2065L), DOMESTICMIG2018 = c(0L,
-292928L, -157048L, 345132L, 104844L, 5718L), NETMIG2010 = c(178835L,
12805L, -25715L, 159421L, 32324L, 2166L), NETMIG2011 = c(792881L,
46897L, -69948L, 621100L, 194832L, 2477L), NETMIG2012 = c(858764L,
2270L, -60290L, 680813L, 235971L, 5933L), NETMIG2013 = c(850952L,
-22170L, 2867L, 623340L, 246915L, 7752L), NETMIG2014 = c(947947L,
-51706L, -48420L, 738720L, 309353L, 2998L), NETMIG2015 = c(1063702L,
-112721L, -92064L, 881967L, 386520L, 3132L), NETMIG2016 = c(1069230L,
-136235L, -83341L, 879428L, 409378L, 3973L), NETMIG2017 = c(953233L,
-101007L, -35374L, 769047L, 320567L, 5255L), NETMIG2018 = c(978826L,
-63228L, -29465L, 763550L, 307969L, 9062L), RESIDUAL2010 = c(0L,
-3196L, -1108L, 4554L, -250L, -10L), RESIDUAL2011 = c(0L, -2459L,
-239L, 4387L, -1689L, 38L), RESIDUAL2012 = c(0L, -2992L, -1288L,
6502L, -2222L, 91L), RESIDUAL2013 = c(0L, -2445L, -1350L, 5123L,
-1328L, 55L), RESIDUAL2014 = c(0L, -2490L, -2904L, 6550L, -1156L,
-192L), RESIDUAL2015 = c(0L, -1190L, -2509L, 4476L, -777L, -270L
), RESIDUAL2016 = c(0L, -271L, -1077L, 1047L, 301L, -114L), RESIDUAL2017 =
c(0L,
-636L, -1129L, 1196L, 569L, -106L), RESIDUAL2018 = c(0L, -796L,
-1227L, 1288L, 735L, -102L), RBIRTH2011 = c(12.79898857, 11.646389369,
12.449493906, 13.0753983, 13.564866164, 12.455601786), RBIRTH2012 =
c(12.589173852,
11.454833676, 12.353389372, 12.900715293, 13.172754439, 12.287820829
), RBIRTH2013 = c(12.511116578, 11.384582534, 12.318197145, 12.770698648,
13.1250523, 12.012410502), RBIRTH2014 = c(12.493440163, 11.301146646,
12.363692308, 12.814734, 12.993051496, 12.179749675), RBIRTH2015 =
c(12.493175596,
11.324209532, 12.357461907, 12.843808208, 12.92441189, 12.301816868
), RBIRTH2016 = c(12.309933949, 11.20434042, 12.242454436, 12.663079639,
12.619264908, 12.222387438), RBIRTH2017 = c(12.039095529, 10.996948983,
11.989119413, 12.357287884, 12.333939366, 11.962999487), RBIRTH2018 =
c(11.820984126,
10.863177115, 11.789576855, 12.078306222, 12.128940451, 11.720998206
), RDEATH2011 = c(8.0928244199, 8.4846099623, 8.7504877826, 8.3388830191,
6.7917918366, 10.187095914), RDEATH2012 = c(7.9990857588, 8.2779015368,
8.6968381072, 8.2343067033, 6.7700904074, 10.060744313), RDEATH2013 =
c(8.2803198685,
8.5962112289, 8.9723230665, 8.5807898649, 6.9298356343, 10.542582104
), RDEATH2014 = c(8.1408206164, 8.4020820365, 8.8249187702, 8.4524499397,
6.8267702932, 10.274434632), RDEATH2015 = c(8.4484528254, 8.7250748685,
9.2388679994, 8.7443343664, 7.0592978512, 10.689339673), RDEATH2016 =
c(8.3975028099,
8.5692003816, 9.1188486402, 8.6935469035, 7.1552465339, 10.632332792
), RDEATH2017 = c(8.5756150392, 8.9363320099, 9.1155717285, 8.8857783149,
7.3396052849, 10.889883997), RDEATH2018 = c(8.6277792774, 9.0371195009,
9.1016891619, 8.9320830002, 7.4291216994, 10.944391939), RNATURALINC2011 =
c(4.7061641498,
3.161779407, 3.6990061239, 4.7365152812, 6.7730743272, 2.2685058724
), RNATURALINC2012 = c(4.5900880929, 3.1769321388, 3.656551265,
4.66640859, 6.402664032, 2.2270765159), RNATURALINC2013 = c(4.2307967093,
2.7883713049, 3.3458740787, 4.1899087829, 6.1952166656, 1.4698283977
), RNATURALINC2014 = c(4.3526195469, 2.89906461, 3.5387735378,
4.3622840605, 6.1662812026, 1.9053150433), RNATURALINC2015 =
c(4.0447227708,
2.5991346635, 3.1185939072, 4.0994738414, 5.8651140389, 1.6124771946
), RNATURALINC2016 = c(3.912431139, 2.6351400388, 3.123605796,
3.969532736, 5.4640183742, 1.5900546466), RNATURALINC2017 =
c(3.4634804902,
2.0606169731, 2.8735476848, 3.4715095687, 4.9943340813, 1.0731154898
), RNATURALINC2018 = c(3.1932048488, 1.8260576141, 2.687887693,
3.1462232219, 4.6998187519, 0.7766062675), RINTERNATIONALMIG2011 =
c(2.5539481982,
3.7247036946, 1.7438348531, 2.4715029092, 2.5385138982, 0.9841112772
), RINTERNATIONALMIG2012 = c(2.7460490726, 3.7275831375, 1.7993217139,
2.9505576333, 2.5429438207, 1.2219173785), RINTERNATIONALMIG2013 =
c(2.7017267715,
3.4759149144, 1.8781318506, 2.7997195452, 2.7121923767, 1.0597112344
), RINTERNATIONALMIG2014 = c(2.988275652, 3.9792291689, 1.9851256285,
3.0689308523, 3.0260314993, 0.7759790947), RINTERNATIONALMIG2015 =
c(3.3285982753,
4.0561842059, 2.1052580818, 3.5654043717, 3.5102060089, 0.9664136698
), RINTERNATIONALMIG2016 = c(3.3215493142, 4.2230961065, 2.1323795548,
3.5885415898, 3.2920380658, 1.2245437674), RINTERNATIONALMIG2017 =
c(2.9410856198,
3.8503376372, 1.8510505744, 3.2892897676, 2.6864164429, 0.6550398799
), RINTERNATIONALMIG2018 = c(3.0010858795, 4.0950670621, 1.8698304564,
3.3695510667, 2.6156748143, 0.685035969), RDOMESTICMIG2011 = c(0,
-2.879569389, -2.786843372, 2.9081645678, 0.1508443529, -0.467223314
), RDOMESTICMIG2012 = c(0, -3.686820778, -2.69589683, 2.8855541222,
0.6834160664, 0.0122732593), RDOMESTICMIG2013 = c(0, -3.872925953,
-1.835626629, 2.4903472978, 0.6316815776, 0.5475831286), RDOMESTICMIG2014
= c(0,
-4.903180146, -2.700781819, 3.1374707924, 1.1220952977, -0.156105573
), RDOMESTICMIG2015 = c(0, -6.067919504, -3.462920156, 3.7630900106,
1.6177886489, -0.320350145), RDOMESTICMIG2016 = c(0, -6.653555548,
-3.359190761, 3.6365043774, 2.0802759896, -0.40687782), RDOMESTICMIG2017 =
c(0,
-5.651919379, -2.370672066, 2.963134779, 1.4785645494, 0.4240305179
), RDOMESTICMIG2018 = c(0, -5.222289092, -2.301663494, 2.7793734944,
1.350093835, 1.1713623417), RNETMIG2011 = c(2.5539481982, 0.845134306,
-1.043008519, 5.379667477, 2.6893582511, 0.516887963), RNETMIG2012 =
c(2.7460490726,
0.0407623599, -0.896575116, 5.8361117555, 3.2263598871, 1.2341906378
), RNETMIG2013 = c(2.7017267715, -0.397011039, 0.0425052219,
5.2900668429, 3.3438739543, 1.6072943629), RNETMIG2014 = c(2.988275652,
-0.923950977, -0.71565619, 6.2064016447, 4.148126797, 0.6198735214
), RNETMIG2015 = c(3.3285982753, -2.011735298, -1.357662074,
7.3284943823, 5.1279946578, 0.6460635248), RNETMIG2016 = c(3.3215493142,
-2.430459441, -1.226811206, 7.2250459672, 5.3723140554, 0.8176659475
), RNETMIG2017 = c(2.9410856198, -1.801581742, -0.519621492,
6.2524245465, 4.1649809923, 1.0790703978), RNETMIG2018 = c(3.0010858795,
-1.12722203, -0.431833037, 6.1489245611, 3.9657686492, 1.8563983107
)), .Names = c("SUMLEV", "REGION", "DIVISION", "STATE", "NAME",
"CENSUS2010POP", "ESTIMATESBASE2010", "POPESTIMATE2010",
"POPESTIMATE2011",
"POPESTIMATE2012", "POPESTIMATE2013", "POPESTIMATE2014",
"POPESTIMATE2015",
"POPESTIMATE2016", "POPESTIMATE2017", "POPESTIMATE2018", "NPOPCHG_2010",
"NPOPCHG_2011", "NPOPCHG_2012", "NPOPCHG_2013", "NPOPCHG_2014",
"NPOPCHG_2015", "NPOPCHG_2016", "NPOPCHG_2017", "NPOPCHG_2018",
"BIRTHS2010", "BIRTHS2011", "BIRTHS2012", "BIRTHS2013", "BIRTHS2014",
"BIRTHS2015", "BIRTHS2016", "BIRTHS2017", "BIRTHS2018", "DEATHS2010",
"DEATHS2011", "DEATHS2012", "DEATHS2013", "DEATHS2014", "DEATHS2015",
"DEATHS2016", "DEATHS2017", "DEATHS2018", "NATURALINC2010",
"NATURALINC2011",
"NATURALINC2012", "NATURALINC2013", "NATURALINC2014", "NATURALINC2015",
"NATURALINC2016", "NATURALINC2017", "NATURALINC2018",
"INTERNATIONALMIG2010",
"INTERNATIONALMIG2011", "INTERNATIONALMIG2012", "INTERNATIONALMIG2013",
"INTERNATIONALMIG2014", "INTERNATIONALMIG2015", "INTERNATIONALMIG2016",
"INTERNATIONALMIG2017", "INTERNATIONALMIG2018", "DOMESTICMIG2010",
"DOMESTICMIG2011", "DOMESTICMIG2012", "DOMESTICMIG2013",
"DOMESTICMIG2014",
"DOMESTICMIG2015", "DOMESTICMIG2016", "DOMESTICMIG2017",
"DOMESTICMIG2018",
"NETMIG2010", "NETMIG2011", "NETMIG2012", "NETMIG2013", "NETMIG2014",
"NETMIG2015", "NETMIG2016", "NETMIG2017", "NETMIG2018", "RESIDUAL2010",
"RESIDUAL2011", "RESIDUAL2012", "RESIDUAL2013", "RESIDUAL2014",
"RESIDUAL2015", "RESIDUAL2016", "RESIDUAL2017", "RESIDUAL2018",
"RBIRTH2011", "RBIRTH2012", "RBIRTH2013", "RBIRTH2014", "RBIRTH2015",
"RBIRTH2016", "RBIRTH2017", "RBIRTH2018", "RDEATH2011", "RDEATH2012",
"RDEATH2013", "RDEATH2014", "RDEATH2015", "RDEATH2016", "RDEATH2017",
"RDEATH2018", "RNATURALINC2011", "RNATURALINC2012", "RNATURALINC2013",
"RNATURALINC2014", "RNATURALINC2015", "RNATURALINC2016",
"RNATURALINC2017",
"RNATURALINC2018", "RINTERNATIONALMIG2011", "RINTERNATIONALMIG2012",
"RINTERNATIONALMIG2013", "RINTERNATIONALMIG2014", "RINTERNATIONALMIG2015",
"RINTERNATIONALMIG2016", "RINTERNATIONALMIG2017", "RINTERNATIONALMIG2018",
"RDOMESTICMIG2011", "RDOMESTICMIG2012", "RDOMESTICMIG2013",
"RDOMESTICMIG2014",
"RDOMESTICMIG2015", "RDOMESTICMIG2016", "RDOMESTICMIG2017",
"RDOMESTICMIG2018",
"RNETMIG2011", "RNETMIG2012", "RNETMIG2013", "RNETMIG2014", "RNETMIG2015",
"RNETMIG2016", "RNETMIG2017", "RNETMIG2018"), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
In order to help you out, an example data using dput(head(population.data)) would be helpful. Based on your comments, your data is in what is called 'wide' format, meaning each observation is contained in a column, rather than a row (pupulation 2010, population 2011 etc.).
As i hinted in my comment, a sub-goal within statistical modelling is always to clean and reshape data to a proper format, that will work for running models. In this case the problem is that your format is in an incorrect shape. The most common is likely melting to long format via the reshape2 or data.table package as explained in this link. I personally prefer the data.table package, as it seems to have better large scale performance. Their usage however is identical.
Lets say you have a column 'NAME' for states and 9 columns for population estimates (2010 population estimates, 2011 population estimates and so on), we could then convert these columns into a long format, using melt from either of the two suggested packages (They are identical in use)
require(data.table)
value_columns <- paste(2010:2018, "Population Estimates")
population.data_long <- melt(population.data, id.vars = "NAME",
measure.vars = value_columns, #Columns containing values we (that are grouped by their column names)
variable.name = 'Year (Population Estimate)', #Name of the column which tells us [(Year) Population Estimate]
value.name = 'Population Estimate') #Name of the column with values
population.data_long$year <- as.integer(substr(population.data_long$`Year (Population Estimate)`, 1, 4)) #Create a year column in a bit of a hacky way
Note i have ignored any additional columns, and these should be included in your melt statement. From here on a linear regression should follow any standard example that you have found.
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="")