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

What library/package does ro() live in ?
as an aside, you can clean up / drop returnedValues1 <- as it serves no purpose for you
see:

(x<- data.frame(a=1:2,
               b=3:4))

apply(x, 2, function(x){ list(returnedValues1  <- mean(x))}) 
$a
$a[[1]]
[1] 1.5

$b
$b[[1]]
[1] 3.5

simplified

# drop the returnvalue <- stuff
apply(x, 2, function(x){ list(mean(x))}) 
$a
$a[[1]]
[1] 1.5

$b
$b[[1]]
[1] 3.5
1 Like

Hey, I made the changes as you told and it runs perfectly thanks a lot.

x <- data2
x %<>% dplyr::select(-Date)
ourCall <- "predict(arima(x=data,order=c(1,0,0)),n.ahead=h)"
ourValue <- c("pred")
ar_ro_model_4 = apply(x, 2, function(x){ return(list(ro(x, h=4, origins = 68,
                                                 call=ourCall, value=ourValue)))})

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.