Related
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
Suppose you have a matrix of time series, where each column is a time series.
Now, suppose you take second differences of this matrix, (so the data is stationary), using this code:
var_train_data <- diff(var_train, differences = 2)
and then you estimate this model:
var_1 <- VAR(y=var_train_data, lag=9, type="const")
Recall that this function VARcomes from vars package.
How can you plot the original data and the fitted(var_1) data? Is there a function to return the fitted data from the VAR to "level"?
I want to do this but with a VAR.
Thanks in advance!!
Here is the data:
> dput(var_train)
structure(c(8.59225428063812, 8.61632381521795, 8.48941975098913,
8.42616336163893, 8.4656261753598, 8.49981580266834, 8.50658473928686,
8.54846279771184, 8.58669260125764, 8.56316032696837, 8.52323490346238,
8.48186742854092, 8.48127581622944, 8.49729119076164, 8.49055049683316,
8.58344453055748, 8.66539149708416, 7.9357662604667, 6.05291235942189,
6.03890804924141, 5.98225560802266, 5.97240914057282, 5.94306180787981,
6.20137810965131, 6.12654161955374, 5.94624694111468, 5.85594359899009,
5.80529348520438, 5.8381279297813, 5.94886540621632, 5.89095336551159,
5.78449385503938, 5.80588769759335, 5.70948049577085, 5.67528501375454,
5.52325929980363, 5.31085745753021, 5.33500450854624, 5.3938341365814,
5.45958551414416, 5.62663959880732, 5.67152161243798, 5.87292229474808,
6.13320939934395, 6.0539450308861, 5.91620206260743, 5.98431404307914,
5.97698522584315, 6.09421451539306, 6.16657264938364, 6.27079937807193,
6.32011405804798, 6.31492735684061, 6.33107810311843, 6.44029387009958,
6.5049295418109, 6.68300329197134, 7.30512711870751, 7.48990882366175,
7.51140038002074, 7.36108949229449, 7.40527167395002, 7.52991897172882,
7.48794703789686, 7.28420343801981, 7.03762657251759, 6.94570770568258,
6.8027650651245, 6.70994292841968, 6.5635196517431, 6.58704241900519,
6.57918807870411, 6.56763428848419, 6.67249919251384, 6.55714884087979,
6.44556863637826, 6.64144323226655, 6.69044694236696, 6.64031146877134,
6.57024614132845, 6.55644009549116, 6.41999492814714, 6.30406385390409,
6.25618617067998, 6.20859002609663, 6.29478035236011, 6.33882450179958,
6.27861522839648, 6.36442286111981, 6.40470239932559, 6.38864543562845,
6.57792182635296, 6.77748387294482, 6.80771392480191, 6.78808230061387,
6.83179944673993, 6.74635337244069, 6.71228769051817, 6.71323231410622,
6.87445699358062, 6.99334898488415, 7.02875008260248, 6.99559171234453,
6.94609768011091, 6.82185333419185, 6.78972221207055, 7.08994524817146,
6.94355669144552, 6.96382050291509, 7.01613754035382, 7.0956860745406,
7.10902496856521, 7.0683268590798, 7.09328003338984, 7.03698767140573,
6.97311732456672, 6.96941465936886, 6.83249279448159, 6.71302370211151,
6.68918458951307, 6.83687286833789, 6.87816384462923, 6.779867793454,
6.6690749885188, 6.68210859744981, 6.63725803128446, 6.47906806746391,
6.63432043737224, 6.57746390143601, 6.63242090143254, 6.51253166492618,
6.61381121689155, 6.59605370068614, 6.52834257739573, 6.38542432810392,
6.40417606373692, 6.39057618124397, 6.38557758480921, 6.40206794670863,
6.38004182339231, 6.33048455580799, 6.31905391015162, 6.18631691346691,
6.16989597138095, 6.18599200958145, 6.15475193126883, 6.10944958256305,
6.07359299021025, 6.30235729839158, 6.21488078851159, 6.19123711209895,
6.13415226194445, 6.10489951928334, 6.10835829857948, 6.17117854049486,
6.20272828827286, 6.14697144970638, 6.11798126273311, 6.09592248164895,
6.04625173074978, 5.99916211737789, 6.01626801829834, 6.07798622087923,
6.06003704039333, 5.96216446139643, 5.8926960131323, 5.91466063648335,
5.87549237085556, 5.89885310338971, 5.9930422492496, 6.02137002988689,
6.01266675475859, 6.15176510875538, 6.27125844671076, 6.34813949104671,
6.50500387674558, 6.50357881390098, 6.4894121494231, 6.48577961874698,
6.65109576407555, 6.55243995455944, 6.52108609966874, 6.61791214295492,
6.73192688164199, 6.82964630649759, 6.7830420348085, 6.67163010253559,
7.35778808496937, 7.68222895818785, 7.65345178297661, 7.75628546245401,
7.62338589734873, 18.0052565534027, 18.0283161481762, 18.0354203734597,
18.071119409619, 18.1057986145642, 18.1434464627582, 18.1679613320011,
18.1724822603554, 18.1626507380013, 18.1735086813587, 18.2048932826437,
18.2692972785199, 18.2533671856288, 18.2415818049433, 18.2496122176447,
18.2718727763864, 18.3010161442641, 18.3291390076371, 18.3572538287519,
18.3507204046193, 18.3600370069532, 18.3939643481435, 18.4165259145903,
18.4908471052973, 18.4867143437776, 18.4804562806922, 18.469238614477,
18.4879629103507, 18.5207111296724, 18.5392075918007, 18.549601058126,
18.5389132074898, 18.5541926126363, 18.5648519425587, 18.6134248798087,
18.6623309458927, 18.6585086859232, 18.6627389755133, 18.6664151651325,
18.7001141293336, 18.7124583930686, 18.7555889295117, 18.7668588119494,
18.7436675451662, 18.7459556596228, 18.7514145615817, 18.7664618044321,
18.8918838160788, 18.8524507901715, 18.8267408416858, 18.8351746759483,
18.8659203733722, 18.8520280137673, 18.8947341990718, 18.8888147953761,
18.8994685106982, 18.9232996525635, 18.8866047503417, 18.9024896904205,
19.0233652386019, 18.987660272875, 18.9544232700339, 18.9334369249929,
18.9449183299094, 18.9631673064947, 18.9933965789268, 18.9872237290741,
18.9873356136058, 19.0123636641398, 19.0206652835947, 19.0270219591515,
19.1598215152463, 19.1409817254047, 19.1376727583276, 19.1107669946426,
19.1241264422661, 19.1370331827589, 19.1912655465102, 19.2115823692113,
19.2158835209359, 19.2414814594526, 19.2701126456528, 19.2843375695361,
19.457274554838, 19.3897327048706, 19.3892248817594, 19.4122218249334,
19.4394604950819, 19.4541631046363, 19.4997359433774, 19.5176831040473,
19.5230181490842, 19.5320146650821, 19.5251016863462, 19.5528663129766,
19.7183358456188, 19.6474484090812, 19.6534432674726, 19.6576920553381,
19.6789279209334, 19.7218625314866, 19.7970056245357, 19.8212720524189,
19.8242227530495, 19.8192388840771, 19.8436023860703, 19.881222941016,
20.0436302759402, 19.9570453168158, 19.9591040082, 19.9740784817898,
19.9751993031549, 19.986022300742, 20.0531114406967, 20.0696985627145,
20.0800828758451, 20.1153963422351, 20.1076549894179, 20.1267044622338,
20.2723835551353, 20.2393724865888, 20.1653637627644, 20.175313365826,
20.1653179028692, 20.2067113730004, 20.2925659543297, 20.2949687148603,
20.3127893925416, 20.3352981379241, 20.3625848609943, 20.4154309157981,
20.5264488163096, 20.4391570088463, 20.4361213999428, 20.4679188013375,
20.4735221776474, 20.5104401429986, 20.5802596472874, 20.5970515415252,
20.6075988336636, 20.6257156522032, 20.6528395142733, 20.7198461324164,
20.7747860368889, 20.739620648921, 20.7095747158136, 20.6824219109357,
20.6683460262695, 20.6916705410586, 20.759196128171, 20.7576642433693,
20.7734082911213, 20.7797650725761, 20.8116082106002, 20.8694893686511,
21.0404672977562, 20.985356981043, 20.9557258620312, 20.9617164802732,
20.9759120662088, 20.9794392421448, 21.0620148226635, 21.0624457124599,
21.0769973151371, 21.0901703250319, 21.098690344787, 21.1226698925968,
21.2711836808076, 21.2200341433781, 21.207193477524, 21.2331394396842,
21.2179204523064, 21.2683699326247, 21.3524515602354, 21.2680244710733,
21.361479141605, 21.3261431820478, 21.26986226303, 21.2991364766223,
21.4762517489448, 21.3298374568077, 21.3331519252179, 21.3667485789704,
21.3885075875912, 21.3906997195313, 21.4381231831175, 21.458826223458,
21.5063778806171, 21.5151033730744, 21.507010374386, 21.5687143378936,
21.7306835559895, 4.44765724836912, 4.47100191330161, 4.54882158610783,
4.5440708847657, 4.51747797566305, 4.55880902228773, 4.58341393701683,
4.64251003043301, 4.67923099142439, 4.67449572095413, 4.61706049834258,
4.66515462150976, 4.68125825810232, 4.66447683681913, 4.67120538921521,
4.75098823360583, 4.7865929014467, 4.76411723853929, 4.80166768795887,
4.80738451939104, 4.72395597727812, 4.70774920353605, 4.73128098441694,
4.7497092825493, 4.70907556418776, 4.76025128174992, 4.78333093429487,
4.83897472963042, 4.84221516595959, 4.84570544645976, 4.86534283142894,
4.83189781246032, 4.88116983304783, 4.93726397688361, 4.9949887298286,
4.99476493720366, 5.03985402500338, 5.08369093771621, 5.14388523087357,
5.18085114132468, 5.24643999990121, 5.29616550395191, 5.31221160299188,
5.19904892834139, 5.11149173059605, 4.91002237688405, 4.74559139066756,
4.62999621355914, 4.65748259587475, 4.62140362369755, 4.62160891785885,
4.64311994758678, 4.72234866533005, 4.80015528005185, 4.76255281172576,
4.81741428916888, 4.78833902844309, 4.84857045098378, 4.88628200385209,
4.90595450753678, 4.94790389478918, 4.92401525818964, 4.95677349014216,
5.01088694769778, 4.9503589208899, 4.92948635242132, 4.93119567690321,
4.95837860539992, 4.97675522372483, 5.02843176452887, 5.06149708771953,
5.11680002731314, 5.15318428207365, 5.18999785496126, 5.22291283107711,
5.27233625060222, 5.23506513572608, 5.22540885753388, 5.23894254044616,
5.2156683767814, 5.20459712839743, 5.16868853558729, 5.18200968431041,
5.1634206717668, 5.17963852108505, 5.21018392350377, 5.23236124392477,
5.21618459500301, 5.15529912255812, 5.08809220037847, 5.1198724394553,
5.14734561157324, 5.15737088983502, 5.14805750597054, 5.13433360782898,
5.13895940081431, 5.16304129678691, 5.17149369912226, 5.1450893326955,
5.12587216446798, 5.11899200918883, 5.10413318074705, 5.1160008826641,
5.13174199954551, 5.1280052744334, 5.11204768607761, 5.10168238434182,
5.12328408372326, 5.11612649122192, 5.14161587137474, 5.13479881416009,
5.14165443688476, 5.12847989418342, 5.13034008951874, 5.11006252539728,
5.07602981399522, 5.04380082747131, 4.9865270245507, 4.93875062722085,
4.83814457466529, 4.73816812891552, 4.76719339629964, 4.73243951213948,
4.7435649612657, 4.77654431271813, 4.75791190194754, 4.69814760133106,
4.63006025665572, 4.62852090719856, 4.62807952037229, 4.56670114439206,
4.50814804330275, 4.44643563505667, 4.47016149299473, 4.53912223957418,
4.57221861050859, 4.61097392628225, 4.63675759989718, 4.63305952571057,
4.63769373351235, 4.63818304039896, 4.66879922486243, 4.65819557081487,
4.71530442638786, 4.75283411765132, 4.75677199897661, 4.70834590013243,
4.70931748325188, 4.68986307689509, 4.66007542691547, 4.68658557879665,
4.71287923105122, 4.74116955758817, 4.75433533727191, 4.79454505679725,
4.80874809318759, 4.86630450704699, 4.84278723259879, 4.83917234051045,
4.85488742314064, 4.89072885950008, 4.88255695031045, 4.86964539401132,
4.85185198871889, 4.88602282140254, 4.89354723701055, 4.80281371512246,
4.75326969467741, 4.7628424628326, 4.77922033722999, 4.78674176423299,
4.81556668261512, 4.79146335227998, 4.74952108237436, 4.77041301487697,
4.71934595594234, 4.74327045521818, 4.7274675891773, 4.76201943815388,
4.78742822435935, 4.7838694829636, 4.70898722458582, 4.54042300123519,
4.43046567457835, 4.51451988598857, 4.60392217055997, 4.635511244447,
4.69067644375465, 4.68405634850711, 4.70605958678574, 4.74618067900467,
4.83260092214898, 4.58877721775886, 4.5853033584615, 4.58186865729406,
4.55644763424071, 4.57312995884514, 4.59141300784382, 4.61405195391224,
4.62539633475001, 4.62855764989542, 4.63775153880854, 4.6400153979937,
4.63484394226681, 4.66244207350167, 4.66434146018009, 4.67076691372282,
4.68407880009055, 4.68958339529632, 4.68622457601331, 4.69208811620889,
4.6940756895394, 4.69428420237835, 4.70035131806994, 4.71249186301022,
4.7271653599702, 4.7349479901132, 4.74160205558268, 4.74031934574645,
4.75062724305051, 4.74555258590119, 4.7562138340694, 4.77117641542375,
4.77731860313779, 4.78678284676528, 4.79153067887926, 4.79406738928742,
4.81477266396795, 4.80529042610458, 4.82344884188224, 4.84012452381554,
4.82978062729767, 4.84653955140898, 4.85661455200409, 4.84934319669535,
4.85983345926684, 4.86432477646786, 4.87752996938969, 4.88896248079701,
4.89778714881147, 4.90781018324614, 4.89428104718603, 4.88909193570591,
4.91223232224708, 4.90441909943736, 4.89184080947695, 4.90838616906774,
4.9120349738912, 4.91193835958192, 4.88849965474606, 4.86952089013496,
4.82754082787148, 4.82297945991404, 4.83636363788566, 4.81537478739995,
4.80170678155239, 4.79837796712813, 4.80808503798778, 4.82809683942688,
4.84168009931907, 4.85375583235012, 4.86250775605786, 4.86576774877652,
4.85101858001533, 4.88095185322792, 4.889979963576, 4.89811535971474,
4.91927159620284, 4.93489213808326, 4.94589827772837, 4.93753721242439,
4.94070114394025, 4.93820671550976, 4.94272951036566, 4.9566005031372,
4.95762163540098, 4.98371534679409, 4.97127518438922, 4.97300329929901,
4.97577277168663, 4.99013444353118, 4.98890830668264, 4.99059253380479,
4.98920233887426, 5.00013814038861, 4.99339203377456, 4.99332756375832,
4.99585549034717, 4.99514277314306, 4.97378016705823, 4.98107090641032,
4.95128483491647, 4.94360774445335, 4.94820569518161, 4.97397566869503,
4.97837258336568, 4.98575124596766, 4.99233525890304, 4.9912972420199,
5.00502716857625, 4.98574031284931, 4.99974886393147, 5.00248006801806,
5.00029210629614, 5.00032426635492, 5.00234130906807, 4.99807143017482,
5.01211153206913, 5.01282969959663, 5.00369558714223, 4.99803646081775,
4.99122145915995, 4.98203245011163, 4.98898183118227, 4.97676031402907,
4.97661306140277, 4.97790228452433, 4.97467881736556, 4.97074319702324,
4.96777121735822, 4.96666260100269, 4.97008836269719, 4.97439822264025,
4.97499263100689, 4.97356254116369, 4.99650332598755, 4.99359641505544,
5.00958842621975, 5.00937803525786, 5.01453325868578, 5.01528247340244,
5.01105287591122, 5.00468878177894, 5.00658901722306, 5.0002693118926,
4.98932483790769, 4.99855492515587, 4.98814720173172, 4.98315862786098,
4.97816073933055, 4.97250227511499, 4.97217034019837, 4.9727134145512,
4.98093640727607, 4.97743699009155, 4.97708205787666, 4.98170032114438,
4.98999371770747, 4.99342868670462, 4.98710032461129, 4.99711328978229,
4.99575482652789, 5.00170349753027, 5.01247168017715, 5.01239395194275,
5.01245423405598, 5.01879001126698, 5.02033652362449, 5.02739033730593,
5.02651459803757, 5.02453819926525, 5.02388052084628, 5.01926462079431,
4.98975208317983, 4.97258722645873, 4.9635436865624, 4.96424225452655,
4.98770778945255, 4.9635436865624, 4.96633503519968, 4.95371214669663,
4.95441761409803, 4.96214508493582, 4.96772779308498, 4.95159275346247,
4.95934199970871, 4.97397130972466, 4.96772779308498, 4.97880057057624,
4.97535347995162, 4.94946885885877, 4.96494033483413, 4.94662996412034,
4.94378298710842, 7.48320429381319, 7.6561645369399, 7.82110610880829,
7.59320189720296, 7.68683478110016, 7.95667983810111, 7.59617632139741,
7.62474227649511, 7.81676325321851, 7.71940521069487, 7.67181853053348,
8.33880996371242, 7.21094058581954, 8.03822762707727, 7.82261070201569,
7.82357158274152, 7.83735667738348, 8.1046367156374, 7.80815635609445,
7.76703032589162, 7.89220083728877, 7.83855143477394, 7.5073939335162,
8.37816256879826, 7.5059752001373, 8.15552853001404, 7.99048020502086,
7.87268970278342, 7.90447413791873, 8.36780891138641, 8.01981945164711,
7.98025535548044, 8.17482965571992, 8.03312420507814, 8.1396225979523,
8.53154436348939, 8.30064119442864, 8.31217764468587, 8.46515718841819,
8.29227902146296, 8.37957956757638, 8.77038284745496, 8.38757448056262,
8.42970131889157, 8.55673020197898, 7.94125019923153, 7.6879198778969,
9.45050056056844, 8.49521672781314, 8.5173342801255, 8.79041321175791,
8.62481679196763, 8.6089805031612, 9.02875849754497, 8.71206191409011,
8.70162108392494, 8.71428574579492, 8.73089101876822, 8.78844251470506,
9.20696012451967, 6.5096550774221, 9.31509857797606, 9.13789797374865,
8.81392733764639, 8.85674985041305, 9.24914586810566, 7.91025892946504,
9.3832351526754, 9.0349150142277, 9.07250596538971, 8.99441603776387,
9.53980564522775, 8.88032246234735, 9.0418287190433, 9.32660204283357,
9.10057585013137, 9.08539025332009, 9.49154546126259, 9.14507434057652,
9.15862717595491, 9.34371391025786, 9.23770140195837, 9.331902300461,
9.84529784537339, 9.22652292064231, 9.36711817060034, 9.45464102264676,
9.43080717829243, 9.48542815127549, 9.80315392429245, 9.46220102483428,
9.49195605787191, 9.58345398545618, 9.63034810064769, 9.62459170291441,
9.97734143922148, 7.7599692507259, 10.24019393111, 9.83720243907435,
9.76324132919314, 9.80448476069629, 10.1429407688952, 9.78954063027604,
9.81148978580127, 9.90999022870695, 9.88337955430856, 9.86638017850479,
10.3500614614058, 8.04569598345531, 10.5137723520267, 10.0317143144973,
10.0016019420988, 10.0649053768744, 10.4518094727319, 10.0925802568863,
10.1154740580661, 10.2417047261218, 10.2102565428829, 9.95096958506337,
10.736142313028, 10.2104846692811, 10.0464027137144, 10.4566501947458,
10.213399969191, 10.4108390826055, 10.7497332163144, 10.3922428157884,
10.3629994803926, 10.5490843518049, 10.5299430900147, 10.5342652815607,
10.903442654213, 10.523826123055, 9.94829558655345, 11.0676534061714,
10.7289541973848, 10.7146558087789, 11.1095150342409, 10.7975434766392,
10.8030323275495, 10.9150557366667, 10.8468764795822, 10.1911966896029,
11.575751749895, 10.8395599835383, 10.9068704738973, 11.155501263489,
11.0291969763111, 11.0962769537602, 11.4469279398172, 11.0612218040278,
11.1062426423224, 11.2517538845846, 11.2333784859651, 10.9841022587667,
11.7991470802475, 11.2598050882812, 11.254649905487, 11.4720292631746,
11.3598860229692, 11.4170427738813, 11.766391720184, 11.4134853828265,
11.4410605118049, 11.5576389232754, 11.5626475736127, 11.5282047555652,
11.9147793383982, 11.4669389639854, 11.5920019692809, 11.7656439584139,
11.5489709584581, 11.6145933534541, 12.0526884789762, 11.5721225093198,
11.5785294086931, 11.9478679038354, 11.7577088515946, 11.644026901156,
12.282699606583, 11.6893399093708, 11.7081194573217, 12.0745898194066,
11.8513909555241, 12.0120697218447, 12.3777829279197, 11.9427908749701,
11.9852440709239, 12.2849763358503, 12.1610242572971, 12.2863478497246,
12.6987948609176, 8.87626014701704, 8.75781187913873, 8.79677757108755,
8.86048921162718, 9.42285091166665, 9.15587149508903, 9.07157541184028,
9.04422296009634, 8.98415367463587, 8.99264229713128, 8.99995926865439,
8.98630888588454, 9.08279027699937, 9.01801415653217, 9.03092644682495,
9.13585333120665, 9.3964555249613, 9.31056129804753, 9.21149824677136,
9.23582853002755, 9.19896921092407, 9.1993094115266, 9.22157244245253,
9.33255711303986, 9.32050974348142, 9.25734511507957, 9.25346237744606,
9.21161756310925, 9.57206242922829, 9.53477519401849, 9.44848135105606,
9.4736925056348, 9.45353618677624, 9.50006144281617, 9.53134203318552,
9.55522920290037, 9.58433205464551, 9.49975115996635, 9.54279990568933,
9.4939629665153, 9.8456088597159, 9.80015328006924, 9.76821638323259,
9.79109456264224, 9.72522763542793, 9.77851709053319, 9.8204171003855,
9.88434452165958, 9.98640258678757, 9.88349657543331, 9.78072105929449,
9.91545274615568, 10.0965440644382, 10.069889220858, 10.1071834236742,
10.0960053864793, 10.0816170924409, 10.0972659507375, 9.98273573064832,
10.0707648293296, 10.0903422031634, 10.0334967498009, 9.988071454218,
10.0452755646408, 10.214325988114, 10.1943936821307, 10.20408926276,
10.1374653682538, 10.1747246925649, 10.1817608649851, 10.1694093867828,
10.2457147073325, 10.2759167729448, 10.2174707468632, 10.2579653028569,
10.3132625062745, 10.5801172770154, 10.5266233798438, 10.5287486381328,
10.4503144592933, 10.481479184849, 10.4934241207427, 10.502542901769,
10.5494285881606, 10.6156346275554, 10.5119074689424, 10.5311093136153,
10.5900727521127, 10.832499150024, 10.7930060469324, 10.775718578877,
10.7531531154054, 10.773311204382, 10.7696395290979, 10.7637570976447,
10.7977938807946, 10.8750990746633, 10.763894326936, 10.7864939948099,
10.8084313558315, 11.0190608163543, 10.9799244653747, 11.0238093735289,
11.0096646409103, 10.9573562063908, 11.0042746906925, 11.0131160377438,
11.0384446615171, 11.0925921149442, 11.016788345678, 11.0067286524726,
11.1218140056974, 11.2613143806394, 11.2211796761646, 11.2935015874788,
11.2367103049134, 11.1817094995799, 11.2157604633905, 11.2061686914688,
11.2392748154291, 11.4109721102435, 11.3043371225574, 11.2735248395737,
11.4375261360429, 11.5623874976603, 11.5247175044255, 11.5814242903823,
11.5093986724378, 11.5000330452891, 11.5579600619228, 11.5311240131655,
11.5954153362326, 11.6738399129326, 11.57644340322, 11.5655204319799,
11.6321174901907, 11.8360148309349, 11.8553639635506, 11.8913520673329,
11.7944527780615, 11.770991474902, 11.8087026529826, 11.7713523360005,
11.884723151518, 11.9993814545919, 11.8115717892501, 11.8332855179777,
11.9237740730483, 12.0455787827743, 12.0702342014546, 12.1012197983564,
12.0183149296719, 12.0336059065465, 12.0269239230024, 12.1132590047525,
12.5264959691571, 12.2615706812812, 12.0565371292502, 12.2657313524817,
12.1439258858968, 12.2359003050756, 12.3309092088311, 12.3771893569204,
12.3071632432092, 12.3196939443778, 12.3000789109455, 12.321469532421,
12.3683550017493, 12.4759510736235, 12.3701719620075, 12.3835321964786,
12.372549767611, 12.5961565138223, 12.6077080727407, 12.5909743980745,
12.5893548765137, 12.5974984744602, 12.6523879936874, 12.6119355657399,
12.6758307918205, 12.8047085707425, 12.7095434517684, 12.7003715885686,
12.7865053255695, 13.0041421782442, 13.0268258741114, 13.0190226032443,
13.0357037893755, 12.9527882182394, 13.0084592868531, 13.0707965999479,
13.1069788399601, 1.04885832686158, 1.06016074629379, 1.0517956106758,
1.02907998600003, 1.05054370620123, 1.07261670636915, 1.0706491823234,
1.0851355199628, 1.08488055975672, 1.08085233559646, 1.081489249884,
1.08587205516048, 1.07249155362154, 1.05497731364761, 1.05675866316574,
1.06428371643968, 1.06065865122313, 1.05621234529568, 1.05339905298902,
1.05787030302435, 1.0658034000068, 1.08707776713932, 1.08626056161822,
1.10238697375394, 1.11390088086972, 1.12120513732074, 1.11937921359653,
1.10341241626668, 1.1156190247407, 1.12376155972358, 1.12411603174635,
1.12183475077377, 1.12994175229071, 1.12956170931204, 1.12199732095331,
1.11645064755987, 1.12481242467782, 1.13066151473637, 1.13028712061827,
1.12694056065497, 1.12382226475179, 1.12352013167586, 1.13391069257413,
1.14763982976838, 1.14481816405703, 1.14852949174863, 1.14182560351963,
1.14086563926171, 1.14491904045717, 1.14897189333479, 1.14616964486707,
1.15074750127031, 1.14681353487065, 1.11151754535415, 1.10497749493861,
1.10963378437214, 1.12415745716768, 1.17507535290893, 1.20285968503846,
1.22784769136553, 1.23940795216891, 1.254741010879, 1.29442450660416,
1.30428779451896, 1.31314618462517, 1.32544236970695, 1.33728107423435,
1.34408499591568, 1.34199331033196, 1.34027541040719, 1.33616830504407,
1.33360421057602, 1.33332422301893, 1.34717794252774, 1.3502492092262,
1.35168291803248, 1.35827816606688, 1.36772644852242, 1.36755741578293,
1.36926148542701, 1.37264481021763, 1.37322962601678, 1.37643913938007,
1.37906284181634, 1.37644362054554, 1.38911039237937, 1.39412557349575,
1.40094895608589, 1.40630864159528, 1.40823485306921, 1.4138446752069,
1.42340582796496, 1.43641264727375, 1.43605231080207, 1.44839810240334,
1.45451041581127, 1.46166006472498, 1.46774816064695, 1.46930608347752,
1.47885183796249, 1.49059366171423, 1.49849145403671, 1.51209667142067,
1.5250141727637, 1.5392257264567, 1.55144303632514, 1.56488453313021,
1.58308777691125, 1.59737589266492, 1.60896279958586, 1.62553339664661,
1.63594174408691, 1.65233080464302, 1.67114336171075, 1.6897476078746,
1.71673790971729, 1.74453973794979, 1.76317526009814, 1.79187692264759,
1.84186982937622, 1.9460629324144, 2.05986108970089, 2.06767436493269,
2.0783176148561, 2.08271855277262, 2.09358626977224, 2.09674958523685,
2.11582742548029, 2.12810020369675, 2.13596929171732, 2.13972610568317,
2.14456803530813, 2.15013985201827, 2.16007349878874, 2.17165498940627,
2.18057666565755, 2.19162746118342, 2.20308765886345, 2.21304799942168,
2.22367586966847, 2.23629862083737, 2.24751866055731, 2.26100586740225,
2.40972893063106, 2.60366275683037, 2.68572993101095, 2.70501080420283,
2.6676315643757, 2.6479269687206, 2.64641010174172, 2.69966594490103,
2.69665303568271, 2.71396750774502, 2.71900427132191, 2.72876269360869,
2.76276620421252, 2.76620189252239, 2.74632816231219, 2.74196673817286,
2.72905831066292, 2.75190757584346, 2.77801573354251, 2.84089580821293,
2.85681823660541, 2.84754572013613, 2.85858396073969, 2.86184353545653,
2.86958309986952, 2.94279115543111, 2.98631808884879, 3.00648449252989,
3.00620698598987, 3.15207693676406, 3.27614511764022, 3.32011714920345,
3.39367422894347, 3.64822360464499, 3.61835354049394, 3.59374251055335,
3.63237359915986, 3.62209957896007, 3.64554153297999, 3.71611226971083,
3.76031231050606, 3.80307769833913, 3.77959145461296, 3.74772344909971,
3.95072671083008, 4.03652777624058, 4.06630193640976, 4.08838169421096,
4.09074775372752), .Dim = c(192L, 7L), .Dimnames = list(NULL,
c("EMBI+", "M2 (pesos)", "Commodity Price index", "emae",
"gasto programas SS", "recursos tributarios", "ex_rate")), .Tsp = c(2004,
2019.91666666667, 12), class = c("mts", "ts", "matrix"))
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.
I'm trying to perform a rolling linear regression, whit overlapping windows and for different window sizes. I want to save the result in two tables, one with window size and slopes and one wiht window size a and intercepts.
My data set is now saved as a xts object. I'm trying to make a for-loop to generate the different window-sizes and then do a rolling regression between the two variables, with a overlapping window using rollapply. Then I would like that the coefficients for every regression get saved as a row in a matrix, that can be built on, so that every window size corresponds to one row. I have looked at a lot of previous questions, but I can not get it right.
I have hourly data for 2 variables, this is the data for the x-variable:
> dput(Xq$x)
structure(c(339.76625, 176.7196875, 142.8063125, 118.5785625,
102.0514375, 86.01156251, 86.99050001, 85.0089375, 380.0010626,
2114.279375, 2157.76875, 2442.575, 2562.6375, 2537.7125, 2581.888125,
1947.7575, 834.7918751, 765.1525001, 989.698125, 1433.2, 429.9081251,
388.333125, 1500.995, 1523.816625, 1529.090126, 439.746875, 1029.03625,
1470.07825, 1454.844813, 1448.8455, 413.7550001, 334.03125, 566.7362501,
1609.184375, 1509.266876, 1403.1425, 1142.695625, 795.138125,
1562.881875, 933.190625, 549.085625, 500.135, 535.83, 444.3493751,
356.386875, 268.1875001, 141.1878125, 119.658875, 162.0425625,
153.6944375, 161.0025, 151.37025, 155.9567501, 123.64825, 145.664125,
141.4480625, 232.2009375, 913.6480001, 2227.08125, 1870.618751,
2190.606251, 1357.81625, 824.555625, 699.99, 703.695, 620.74625,
581.2375001, 393.391875, 349.96625, 188.5445625, 154.03125, 142.0825,
339.7915625, 139.8941875, 154.6279376, 171.6016875, 151.1387501,
159.7665, 168.62025, 180.7596875, 447.2746875, 1550.11625, 1887.275,
1446.883125, 699.590625, 983.9925, 1319.62875, 769.505625, 812.713125,
638.1437501, 585.8312501, 626.7875, 1924.293125, 629.855625,
349.88375, 1038.54875, 1588.82225, 548.3475, 1053.368125, 964.825625,
990.324375, 1327.160625, 395.5862501, 421.8154376, 1308.551875,
1334.045, 1633.408125, 886.2662501, 1618.7975, 1325.59625, 847.0693751,
667.501875, 594.0531251, 249.920625, 210.8869376, 224.3725001,
209.6325, 213.64875, 210.3175001, 194.54, 90.1085625, 71.12575001,
70.69412501, 69.6075, 68.404625, 67.88837501, 67.317125, 67.220375,
67.696625, 273.2732501, 606.475625, 1277.3425, 913.24875, 612.5462501,
571.42125, 503.27375, 316.68375, 208.7436251, 127.283, 126.12375,
102.504625, 78.7938125, 70.0183125, 69.97900001, 77.7586875,
76.60543751, 94.5235625, 103.0095625, 105.1938125, 103.8090625,
104.005625, 104.544875, 105.2036875, 104.6611875, 375.7004375,
793.7725001, 782.544375, 257.065625, 387.1487501, 571.1912501,
356.6406251, 243.404375, 220.698125, 182.5680626, 161.060625,
166.5178125, 137.9805, 129.6253125, 99.4291875, 75.88075001,
65.769875, 62.62937501, 59.697875, 57.68675, 56.67275, 56.69425001,
57.296, 638.95125, 1210.92875, 990.09, 907.895625, 1122.704375,
569.139375, 295.6725, 263.21, 236.3885625, 153.935, 148.0899375,
161.72675, 102.1535, 115.8895, 114.2579375, 95.0023125, 90.72425,
84.2715, 71.06631251, 63.39812501, 75.2416875, 73.9420625, 72.26237501,
402.8870625, 1148.9775, 1058.86875, 896.47875, 890.9687501, 833.645625,
670.310625, 298.576875, 306.538125, 386.403125, 196.8343751,
174.0815, 156.6158126, 117.9345625, 105.095, 90.24362501, 87.08800001,
86.1628125, 105.3179375, 107.312625, 114.089, 104.85825, 95.9281875,
126.2874375, 529.7325626, 1533.605625, 1089.700625, 760.47, 1905.04125,
1744.460625, 1346.120625, 847.90625, 459.4625, 472.11, 474.5068751,
481.83875, 937.3618751, 267.1339376, 137.7895625, 124.0425625,
188.9461875, 108.8915, 111.67825, 84.319125, 127.1240625, 117.519125,
104.16225, 105.2490625, 158.5540625, 1215.278063, 1275.396875,
1301.14375, 1108.9225, 1280.390625, 1434.5225, 1038.926875, 599.3218751,
665.22875, 646.935, 487.604375, 236.8148126, 300.6626876, 830.2973126,
1286.612313, 403.0063751, 405.9081875, 156.5465625, 101.7661875,
100.2301875, 144.424625, 126.781125, 143.940625, 365.5354376,
849.313125, 1729.3175, 1762.6625, 1733.968751, 1275.4375, 1332.930625,
620.5625, 504.115625, 538.4556251, 433.5725, 337.094375, 225.183125,
184.7196251, 156.7545, 130.23325, 134.0796875, 145.196125, 153.243,
141.096375, 414.8042501, 304.7252501, 204.1889375, 129.7909375,
555.0276251, 1734.235625, 1780.209375, 1462.7825, 967.4743751,
1248.791875, 1001.655625, 662.92875, 546.801875, 393.72375, 308.85125,
259.985625, 280.439375, 274.1312501, 310.0375001, 270.3, 201.9288125,
219.6061875, 208.372625, 156.2023125, 162.5355626, 167.823875,
151.3928126, 151.42875, 293.7148125, 434.9101875, 943.9243751,
995.955, 614.055, 1387.864375, 1752.330626, 1238.1725, 1260.93,
565.383125, 253.179375, 275.66625, 280.4912501, 222.684375, 338.079875,
201.9365625, 136.7436875, 146.5479375, 142.794625, 150.3969375,
134.6478125, 88.22068751, 70.6445, 71.73737501, 243.176, 1559.0925,
1527.626876, 1260.648125, 1251.564375, 714.1075001, 1124.58,
901.6018751, 551.9075, 303.1025, 355.435625, 372.32375, 235.62125,
185.39475, 161.7701876, 155.4823751), index = structure(c(1438380000,
1438383600, 1438387200, 1438390800, 1438394400, 1438398000, 1438401600,
1438405200, 1438408800, 1438412400, 1438416000, 1438419600, 1438423200,
1438426800, 1438430400, 1438434000, 1438437600, 1438441200, 1438444800,
1438448400, 1438452000, 1438455600, 1438459200, 1438462800, 1438466400,
1438470000, 1438473600, 1438477200, 1438480800, 1438484400, 1438488000,
1438491600, 1438495200, 1438498800, 1438502400, 1438506000, 1438509600,
1438513200, 1438516800, 1438520400, 1438524000, 1438527600, 1438531200,
1438534800, 1438538400, 1438542000, 1438545600, 1438549200, 1438552800,
1438556400, 1438560000, 1438563600, 1438567200, 1438570800, 1438574400,
1438578000, 1438581600, 1438585200, 1438588800, 1438592400, 1438596000,
1438599600, 1438603200, 1438606800, 1438610400, 1438614000, 1438617600,
1438621200, 1438624800, 1438628400, 1438632000, 1438635600, 1438639200,
1438642800, 1438646400, 1438650000, 1438653600, 1438657200, 1438660800,
1438664400, 1438668000, 1438671600, 1438675200, 1438678800, 1438682400,
1438686000, 1438689600, 1438693200, 1438696800, 1438700400, 1438704000,
1438707600, 1438711200, 1438714800, 1438718400, 1438722000, 1438725600,
1438729200, 1438732800, 1438736400, 1438740000, 1438743600, 1438747200,
1438750800, 1438754400, 1438758000, 1438761600, 1438765200, 1438768800,
1438772400, 1438776000, 1438779600, 1438783200, 1438786800, 1438790400,
1438794000, 1438797600, 1438801200, 1438804800, 1438808400, 1438812000,
1438815600, 1438819200, 1438822800, 1438826400, 1438830000, 1438833600,
1438837200, 1438840800, 1438844400, 1438848000, 1438851600, 1438855200,
1438858800, 1438862400, 1438866000, 1438869600, 1438873200, 1438876800,
1438880400, 1438884000, 1438887600, 1438891200, 1438894800, 1438898400,
1438902000, 1438905600, 1438909200, 1438912800, 1438916400, 1438920000,
1438923600, 1438927200, 1438930800, 1438934400, 1438938000, 1438941600,
1438945200, 1438948800, 1438952400, 1438956000, 1438959600, 1438963200,
1438966800, 1438970400, 1438974000, 1438977600, 1438981200, 1438984800,
1438988400, 1438992000, 1438995600, 1438999200, 1439002800, 1439006400,
1439010000, 1439013600, 1439017200, 1439020800, 1439024400, 1439028000,
1439031600, 1439035200, 1439038800, 1439042400, 1439046000, 1439049600,
1439053200, 1439056800, 1439060400, 1439064000, 1439067600, 1439071200,
1439074800, 1439078400, 1439082000, 1439085600, 1439089200, 1439092800,
1439096400, 1439100000, 1439103600, 1439107200, 1439110800, 1439114400,
1439118000, 1439121600, 1439125200, 1439128800, 1439132400, 1439136000,
1439139600, 1439143200, 1439146800, 1439150400, 1439154000, 1439157600,
1439161200, 1439164800, 1439168400, 1439172000, 1439175600, 1439179200,
1439182800, 1439186400, 1439190000, 1439193600, 1439197200, 1439200800,
1439204400, 1439208000, 1439211600, 1439215200, 1439218800, 1439222400,
1439226000, 1439229600, 1439233200, 1439236800, 1439240400, 1439244000,
1439247600, 1439251200, 1439254800, 1439258400, 1439262000, 1439265600,
1439269200, 1439272800, 1439276400, 1439280000, 1439283600, 1439287200,
1439290800, 1439294400, 1439298000, 1439301600, 1439305200, 1439308800,
1439312400, 1439316000, 1439319600, 1439323200, 1439326800, 1439330400,
1439334000, 1439337600, 1439341200, 1439344800, 1439348400, 1439352000,
1439355600, 1439359200, 1439362800, 1439366400, 1439370000, 1439373600,
1439377200, 1439380800, 1439384400, 1439388000, 1439391600, 1439395200,
1439398800, 1439402400, 1439406000, 1439409600, 1439413200, 1439416800,
1439420400, 1439424000, 1439427600, 1439431200, 1439434800, 1439438400,
1439442000, 1439445600, 1439449200, 1439452800, 1439456400, 1439460000,
1439463600, 1439467200, 1439470800, 1439474400, 1439478000, 1439481600,
1439485200, 1439488800, 1439492400, 1439496000, 1439499600, 1439503200,
1439506800, 1439510400, 1439514000, 1439517600, 1439521200, 1439524800,
1439528400, 1439532000, 1439535600, 1439539200, 1439542800, 1439546400,
1439550000, 1439553600, 1439557200, 1439560800, 1439564400, 1439568000,
1439571600, 1439575200, 1439578800, 1439582400, 1439586000, 1439589600,
1439593200, 1439596800, 1439600400, 1439604000, 1439607600, 1439611200,
1439614800, 1439618400, 1439622000, 1439625600, 1439629200, 1439632800,
1439636400, 1439640000, 1439643600, 1439647200, 1439650800, 1439654400,
1439658000, 1439661600, 1439665200, 1439668800, 1439672400), tzone = "UTC", tclass = c("chron",
"dates", "times")), class = c("xts", "zoo"), .indexCLASS = c("chron",
"dates", "times"), tclass = c("chron", "dates", "times"), .indexTZ = "UTC", tzone = "UTC", .Dim = c(360L,
1L), .Dimnames = list(NULL, "x"))
And my y-variable:
> dput(Xq$y)
structure(c(-0.274050833, -0.236638333, -0.1994325, -0.174091667,
-0.153273333, -0.136978333, -0.124748333, -0.117348333, -0.147061667,
-0.346170833, -0.517939167, -0.575585833, -0.595914167, -0.563639167,
-0.53403, -0.5500525, -0.505650833, -0.471713333, -0.472485833,
-0.547393333, -0.390174167, -0.321545, -0.29781, -0.26912, -0.345084167,
-0.367618333, -0.279933333, -0.256805, -0.2514675, -0.314349167,
-0.3594375, -0.33482, -0.369094167, -0.4801075, -0.554780833,
-0.600498333, -0.604796667, -0.544491667, -0.636653333, -0.568401667,
-0.485494167, -0.453199167, -0.417475, -0.38417, -0.341585833,
-0.2821625, -0.248325, -0.2230575, -0.2449075, -0.2385375, -0.231885,
-0.214125, -0.194190833, -0.178575833, -0.1677675, -0.1615725,
-0.1739675, -0.2432125, -0.402414167, -0.448185833, -0.563599167,
-0.5855025, -0.55586, -0.516350833, -0.47892, -0.4603325, -0.434146667,
-0.37602, -0.320976667, -0.267863333, -0.250915, -0.241764167,
-0.271475, -0.2170225, -0.206605, -0.2088, -0.214511667, -0.2086825,
-0.203060833, -0.192895, -0.212629167, -0.319143333, -0.42647,
-0.4623275, -0.467844167, -0.506395833, -0.507088333, -0.496953333,
-0.511156667, -0.487846667, -0.4455525, -0.398383333, -0.565926667,
-0.429720833, -0.314555, -0.418586667, -0.578256667, -0.414858333,
-0.345411667, -0.3088925, -0.304373333, -0.334221667, -0.305029167,
-0.273269167, -0.315901667, -0.409731667, -0.500245833, -0.505959167,
-0.54742, -0.574725, -0.548458333, -0.5560675, -0.50246, -0.411618333,
-0.35965, -0.331884167, -0.312573333, -0.298478333, -0.289144167,
-0.274429167, -0.2218225, -0.198025833, -0.191955833, -0.1780825,
-0.157910833, -0.135935, -0.116965833, -0.099886667, -0.0864975,
-0.188904167, -0.325656667, -0.444044167, -0.5050425, -0.54236,
-0.547500833, -0.5399775, -0.521490833, -0.444911667, -0.388053333,
-0.327650833, -0.2478, -0.2026775, -0.1693425, -0.140848333,
-0.130440833, -0.103501667, -0.088843333, -0.09344, -0.126231667,
-0.158463333, -0.181145, -0.185095, -0.11657, -0.0349225, -0.223260833,
-0.431800833, -0.516, -0.487566667, -0.49941, -0.541773333, -0.511953333,
-0.4404425, -0.4021125, -0.380635, -0.3301275, -0.302468333,
-0.311290833, -0.2774125, -0.223738333, -0.192925, -0.176034167,
-0.158151667, -0.136234167, -0.117050833, -0.101201667, -0.08872,
-0.0855675, -0.257761667, -0.424794167, -0.528980833, -0.56834,
-0.591263333, -0.56574, -0.53178, -0.5410825, -0.552130833, -0.501294167,
-0.44576, -0.402855833, -0.316163333, -0.2515275, -0.213383333,
-0.186723333, -0.174315833, -0.170100833, -0.154446667, -0.147075833,
-0.169245, -0.188474167, -0.187344167, -0.2586975, -0.440815,
-0.534344167, -0.598391667, -0.613878333, -0.624658333, -0.583091667,
-0.508740833, -0.518310833, -0.51102, -0.4203825, -0.364895833,
-0.31302, -0.27689, -0.254130833, -0.232273333, -0.218198333,
-0.22501, -0.235655833, -0.242728333, -0.260448333, -0.263113333,
-0.243530833, -0.222301667, -0.274098333, -0.3974225, -0.484443333,
-0.506165, -0.6136375, -0.631805, -0.596274167, -0.539795, -0.446769167,
-0.398489167, -0.3986925, -0.4098625, -0.484515833, -0.375961667,
-0.291685, -0.273963333, -0.2621025, -0.2054525, -0.177625833,
-0.1564625, -0.141883333, -0.130685833, -0.121943333, -0.112834167,
-0.136975, -0.3204725, -0.458004167, -0.5262175, -0.527530833,
-0.520574167, -0.5800325, -0.561841667, -0.4909225, -0.4641625,
-0.443126667, -0.405705833, -0.3098625, -0.286379167, -0.30477,
-0.395341667, -0.38505, -0.356219167, -0.263050833, -0.219625833,
-0.197383333, -0.2019775, -0.226838333, -0.2333075, -0.2890475,
-0.3341175, -0.43458, -0.520441667, -0.577875, -0.568123333,
-0.551936667, -0.463691667, -0.468790833, -0.4747725, -0.4125925,
-0.394731667, -0.380213333, -0.308688333, -0.279549167, -0.249766667,
-0.233964167, -0.229904167, -0.244835833, -0.232436667, -0.215466667,
-0.198559167, -0.184533333, -0.185376667, -0.246823333, -0.395918333,
-0.4956775, -0.540474167, -0.5402375, -0.577863333, -0.561466667,
-0.503130833, -0.455221667, -0.4401875, -0.4187675, -0.389215,
-0.345275, -0.3378175, -0.348759167, -0.325149167, -0.29995,
-0.289409167, -0.291635, -0.301183333, -0.274799167, -0.2443375,
-0.2254225, -0.21272, -0.245265, -0.295081667, -0.356848333,
-0.4258325, -0.4329175, -0.487074167, -0.595525, -0.59333, -0.564645,
-0.464548333, -0.4294775, -0.425609167, -0.403769167, -0.353311667,
-0.282888333, -0.2464575, -0.231771667, -0.2275425, -0.224230833,
-0.218419167, -0.1902275, -0.161319167, -0.143495833, -0.133691667,
-0.181291667, -0.36056, -0.46681, -0.5194575, -0.532989167, -0.4899375,
-0.533224167, -0.4976575, -0.428966667, -0.412929167, -0.416463333,
-0.366666667, -0.316356667, -0.3023825, -0.282655, -0.267275833
), index = structure(c(1438380000, 1438383600, 1438387200, 1438390800,
1438394400, 1438398000, 1438401600, 1438405200, 1438408800, 1438412400,
1438416000, 1438419600, 1438423200, 1438426800, 1438430400, 1438434000,
1438437600, 1438441200, 1438444800, 1438448400, 1438452000, 1438455600,
1438459200, 1438462800, 1438466400, 1438470000, 1438473600, 1438477200,
1438480800, 1438484400, 1438488000, 1438491600, 1438495200, 1438498800,
1438502400, 1438506000, 1438509600, 1438513200, 1438516800, 1438520400,
1438524000, 1438527600, 1438531200, 1438534800, 1438538400, 1438542000,
1438545600, 1438549200, 1438552800, 1438556400, 1438560000, 1438563600,
1438567200, 1438570800, 1438574400, 1438578000, 1438581600, 1438585200,
1438588800, 1438592400, 1438596000, 1438599600, 1438603200, 1438606800,
1438610400, 1438614000, 1438617600, 1438621200, 1438624800, 1438628400,
1438632000, 1438635600, 1438639200, 1438642800, 1438646400, 1438650000,
1438653600, 1438657200, 1438660800, 1438664400, 1438668000, 1438671600,
1438675200, 1438678800, 1438682400, 1438686000, 1438689600, 1438693200,
1438696800, 1438700400, 1438704000, 1438707600, 1438711200, 1438714800,
1438718400, 1438722000, 1438725600, 1438729200, 1438732800, 1438736400,
1438740000, 1438743600, 1438747200, 1438750800, 1438754400, 1438758000,
1438761600, 1438765200, 1438768800, 1438772400, 1438776000, 1438779600,
1438783200, 1438786800, 1438790400, 1438794000, 1438797600, 1438801200,
1438804800, 1438808400, 1438812000, 1438815600, 1438819200, 1438822800,
1438826400, 1438830000, 1438833600, 1438837200, 1438840800, 1438844400,
1438848000, 1438851600, 1438855200, 1438858800, 1438862400, 1438866000,
1438869600, 1438873200, 1438876800, 1438880400, 1438884000, 1438887600,
1438891200, 1438894800, 1438898400, 1438902000, 1438905600, 1438909200,
1438912800, 1438916400, 1438920000, 1438923600, 1438927200, 1438930800,
1438934400, 1438938000, 1438941600, 1438945200, 1438948800, 1438952400,
1438956000, 1438959600, 1438963200, 1438966800, 1438970400, 1438974000,
1438977600, 1438981200, 1438984800, 1438988400, 1438992000, 1438995600,
1438999200, 1439002800, 1439006400, 1439010000, 1439013600, 1439017200,
1439020800, 1439024400, 1439028000, 1439031600, 1439035200, 1439038800,
1439042400, 1439046000, 1439049600, 1439053200, 1439056800, 1439060400,
1439064000, 1439067600, 1439071200, 1439074800, 1439078400, 1439082000,
1439085600, 1439089200, 1439092800, 1439096400, 1439100000, 1439103600,
1439107200, 1439110800, 1439114400, 1439118000, 1439121600, 1439125200,
1439128800, 1439132400, 1439136000, 1439139600, 1439143200, 1439146800,
1439150400, 1439154000, 1439157600, 1439161200, 1439164800, 1439168400,
1439172000, 1439175600, 1439179200, 1439182800, 1439186400, 1439190000,
1439193600, 1439197200, 1439200800, 1439204400, 1439208000, 1439211600,
1439215200, 1439218800, 1439222400, 1439226000, 1439229600, 1439233200,
1439236800, 1439240400, 1439244000, 1439247600, 1439251200, 1439254800,
1439258400, 1439262000, 1439265600, 1439269200, 1439272800, 1439276400,
1439280000, 1439283600, 1439287200, 1439290800, 1439294400, 1439298000,
1439301600, 1439305200, 1439308800, 1439312400, 1439316000, 1439319600,
1439323200, 1439326800, 1439330400, 1439334000, 1439337600, 1439341200,
1439344800, 1439348400, 1439352000, 1439355600, 1439359200, 1439362800,
1439366400, 1439370000, 1439373600, 1439377200, 1439380800, 1439384400,
1439388000, 1439391600, 1439395200, 1439398800, 1439402400, 1439406000,
1439409600, 1439413200, 1439416800, 1439420400, 1439424000, 1439427600,
1439431200, 1439434800, 1439438400, 1439442000, 1439445600, 1439449200,
1439452800, 1439456400, 1439460000, 1439463600, 1439467200, 1439470800,
1439474400, 1439478000, 1439481600, 1439485200, 1439488800, 1439492400,
1439496000, 1439499600, 1439503200, 1439506800, 1439510400, 1439514000,
1439517600, 1439521200, 1439524800, 1439528400, 1439532000, 1439535600,
1439539200, 1439542800, 1439546400, 1439550000, 1439553600, 1439557200,
1439560800, 1439564400, 1439568000, 1439571600, 1439575200, 1439578800,
1439582400, 1439586000, 1439589600, 1439593200, 1439596800, 1439600400,
1439604000, 1439607600, 1439611200, 1439614800, 1439618400, 1439622000,
1439625600, 1439629200, 1439632800, 1439636400, 1439640000, 1439643600,
1439647200, 1439650800, 1439654400, 1439658000, 1439661600, 1439665200,
1439668800, 1439672400), tzone = "UTC", tclass = c("chron", "dates",
"times")), class = c("xts", "zoo"), .indexCLASS = c("chron",
"dates", "times"), tclass = c("chron", "dates", "times"), .indexTZ = "UTC", tzone = "UTC", .Dim = c(360L,
1L), .Dimnames = list(NULL, "y"))
My code looks like this:
library(zoo)
mat_slope=matrix(nrow=i)
mat_intercept=matrix(nrow=i)
for(i in seq(from=24, to=240, by=24)){
mov.reg<- rollapplyr(Xq,
width= i,
by=24,
FUN = function(y,x)
{
coefficients(lm(formula=y~x, data = Xq))
},
by.column=FALSE)
mat_slope[i] <- coefficients(mov.reg)[2]
mat_intercept[i] <-coefficients(mov.reg)[1]
mat_intercept=rbind(i,mat_intercept)
mat_slope[n,i]=rbind(i, mat_slope)
}
I either get an empty matrix as result, or the following error message:
Error in merge.xts(res, xts(, idx, attr(data, "frequency"))) :
(list) object cannot be coerced to type 'double'
If anyone have some inputs or ideas it would be very appreciated! Thank's a lot!
mov.reg is not an lm objct, so it does not make sense to take coefficients of it. Also there is a reference to chron in the dput output so we need to load the chron package.
Xq is not specified but rather two separate xts objects are shown so we have assumed that those two are called x and y. Then create a single zoo object z from them. Now define a Coef function which takes a matrix with x and y columns and performs the indicated regression returning the coefficients. Also define roll which takes the width as input and runs rollapplyr with the desired arguments. Now use lapply to run roll with each width producing a list of zoo objects. This list has one component for each element in widths consisting of a zoo object with intercept and slope columns. Finally extract the intercepts from each component in the list and form a zoo object and do the same for the slopes. Note that if L is a list of zoo objects then do.call("merge", L) will produce a single zoo object from it.
library(xts) # this also loads zoo
library(chron)
# inputs are xts objects x and y
z <- cbind(x = as.zoo(x)[, 1], y = as.zoo(y)[, 1])
Coef <- function(m) coef(lm(y ~ x, as.data.frame(m)))
roll <- function(w) rollapplyr(z, w, Coef, by = 24, by.column = FALSE)
widths <- seq(24, 240, 24)
names(widths) <- widths # lapply will use these names for its output
L <- lapply(widths, roll)
intercepts <- do.call("merge", lapply(L, "[", TRUE, 1)) # extract 1st columns
slopes <- do.call("merge", lapply(L, "[", TRUE, 2)) # 2nd columns
Alternately do the rollapplyr twice replacing the last 3 lines with:
intercepts <- do.call("merge", lapply(widths, function(w) roll(w)[, 1]))
slopes <- do.call("merge", lapply(widths, function(w) roll(w)[, 2]))
After merging two unequal time series I want to fill the blanks with a custom function. Lets say my Series1 is daily data and Series2 is monthly data. So now Series1 has for example 30 data points for one month and Series2 only one. If I make a left join Series 2 has 29 NAs which I don't like. Ideally I would like a fill function so that Series 2 takes always the previous value to fill these 29 days.
So for example if the 31. of January has a value of 10 and the 28th of February a value of 15, February 1-27. should have a value of 10 as well. Of course in the beginning this doesn't work (since the first row is probably also a NA), so the first row should take the value of the first row containing a value at all.
At the moment I have this, but still, all NAs are present:
Test<-merge.xts(Series1, Series2, join="left", fill=function(x) x[index(x)-1,])
Series1:
structure(c(1.51762156049755, 1.52103159497526, 1.51401262063846,
1.5226927459172, 1.52933295052158, 1.52409353403389, 1.52292452830189,
1.5268928035982, 1.53555449785816, 1.54004946727549, 1.54031650339111,
1.53987556561086, 1.53733857383492, 1.52781969068276, 1.5303624813154,
1.53149347601615, 1.53200449185851, 1.53034081463009, 1.52689961175818,
1.52616010353115, 1.52004035586536, 1.52604263206673, 1.53170366207736,
1.53332707472775, 1.5400318381871, 1.53717071341521, 1.53998696583186,
1.53676880222841, 1.53316818056702, 1.53512014787431, 1.54153071688263,
1.53692449355433, 1.53382906453686, 1.53159514756473, 1.5344496294263,
1.53717866027826, 1.53445133065986, 1.53503822351656, 1.5306399132321,
1.53633694255827, 1.53748747380887, 1.54019086070839, 1.54068532372772,
1.53600669892073, 1.53977166385926, 1.53468288606184, 1.53986928104575,
1.54024911693623, 1.5402127262549, 1.54151119402985, 1.53934776549289,
1.53958085476343, 1.53900838497995, 1.53818540787939, 1.53465613216017,
1.53500719942405, 1.53537650054565, 1.53317195624888, 1.53192246131958,
1.53136958262882, 1.53666845974538, 1.53503754022167, 1.53098678960901,
1.52377172091382, 1.52796773627915, 1.52584842623527, 1.52760075397182,
1.52793296089385, 1.52820374854273, 1.52947558770344, 1.52752869440459,
1.52590880810595, 1.51771286513362, 1.52378827099884, 1.52171596056488,
1.52387303280875, 1.52663662867745, 1.53114232706069, 1.52827140549273,
1.52923132443161, 1.52939594909482, 1.53232585173925, 1.53195117573147,
1.53853103261361, 1.53776866137519, 1.54085533920156, 1.5410640956972,
1.54313041923661, 1.54222657292872, 1.54302034987504, 1.54211182336182,
1.54181785998761, 1.5424089337942, 1.53578353604795, 1.53286652078775,
1.53120629370629, 1.53219713608012, 1.53192052980132, 1.53522245762712,
1.53543098889476, 1.53283647523016, 1.5296408481177, 1.52531916716648,
1.52295699845811, 1.52777060191165, 1.52890571231934, 1.5233980665583,
1.52386256533288, 1.51978021978022, 1.52140011865412, 1.51797040169133,
1.51707941929974, 1.52089868588385, 1.52408100748809, 1.52491920394625,
1.52068065032432, 1.52637418914305, 1.52848101265823, 1.52656088306313,
1.52858618908214, 1.53068778514246, 1.52826643894108, 1.52470085470085,
1.51927185710623, 1.52041166380789, 1.51975945017182, 1.52318452637941,
1.51831155433287, 1.51966908661151, 1.52143645470753, 1.52183128444256,
1.52286417239331, 1.52149627623561, 1.52065908330545, 1.51957958976098,
1.52554186145346, 1.52094733242134, 1.51794915836482, 1.51173708920188,
1.51222222222222, 1.5101414692347, 1.5068328319725, 1.50393081761006,
1.50417972831766, 1.50391986062718, 1.50638741635526, 1.50589880276151,
1.51000264387063, 1.50961116475029, 1.50934456435904, 1.50983477576711,
1.51314636283961, 1.50903004140604, 1.51011752231157, 1.50968426638366,
1.50718251520226, 1.50750460809269, 1.50457827082233, 1.50718301061836,
1.51371392834807, 1.51775147928994, 1.51589595375723, 1.51878256100905,
1.51964269437608, 1.52107244513819, 1.51828822238478, 1.51868515287852,
1.52112289685443, 1.52031478770132, 1.5218941402322, 1.51964269437608,
1.51789300712069, 1.51745137247773, 1.51548186148772, 1.51610254538819,
1.51619929213177, 1.51333333333333, 1.51241134751773, 1.51200286635614,
1.51837734821672, 1.5163433908046, 1.49981738495252, 1.50498640072529,
1.5011387446479, 1.49350888500138, 1.4836323284631, 1.48080845540515,
1.47762023908813, 1.47091566935708, 1.44464775846295, 1.46478356566398,
1.46516563624619, 1.47632234837995, 1.48080808080808, 1.47685016405396,
1.48288833837967, 1.48791693466875, 1.48385916780979, 1.48779368575624,
1.4842056932966, 1.48020986745214, 1.48406538215688, 1.48219003370684,
1.4840747090138, 1.48181569592562, 1.47840712792072, 1.48482921511628,
1.48070841239722, 1.47882236069719, 1.47693552738063, 1.47952903398448,
1.47818343722173, 1.48081910042028, 1.47554444841128, 1.47437042328987,
1.47387958352196, 1.46947082767978, 1.47113912651959, 1.47202166064982,
1.47102365047843, 1.47226211849192, 1.47248814529838, 1.46853962839961,
1.46421559878636, 1.46491463305623, 1.46394424090787, 1.47141221037794,
1.46876654314452, 1.46473285134897, 1.46621860629643, 1.45898901098901,
1.45649677590319, 1.4541381128097, 1.45816872969889, 1.46286215978929,
1.46461267605634, 1.46386925795053, 1.46151797603196, 1.46911608093717,
1.47140552169236, 1.4750490108715, 1.47230138938368, 1.47392733410322,
1.47497537827917, 1.47591916674085, 1.48151776966242, 1.47590146376294,
1.47583108715184, 1.47547136091502, 1.47256621169665, 1.47307171853857,
1.47527795353882, 1.47582605564059, 1.46818468184682, 1.46878890272097,
1.48522318688065, 1.48453427065026, 1.48568912373404, 1.4814585908529,
1.48118303373771, 1.47687244262587, 1.47909624621953, 1.48514136031072,
1.48368539325843, 1.47950599606229, 1.47334107350183, 1.47758127902822,
1.47985739750446, 1.48092011412268, 1.47403176869534, 1.48108736475007,
1.47305653710247, 1.46450017661604, 1.4681413589495, 1.46912050964431,
1.46845174973489, 1.47360950944735, 1.46758608573436, 1.46957056292263,
1.47418043421849, 1.47130794416681, 1.47095489568003, 1.47372954349699,
1.47756961155036, 1.47673216132368, 1.47682004001044, 1.47401301518438,
1.47194032439934, 1.47180647406892, 1.47518534670737, 1.47624474053296,
1.47794826830338, 1.48057829646403, 1.48357504805172, 1.48148471615721,
1.47989206128134, 1.47923238696109, 1.47960337479342, 1.47915397336583,
1.47995097180879, 1.47630640813842, 1.47675825125281, 1.47637181928337,
1.47504781777082, 1.47135191275749, 1.47813993915689, 1.47672594142259,
1.47480059602069, 1.47183284845279, 1.46386701662292, 1.47050586381936,
1.46995971273428, 1.46776454099509, 1.46059482834701, 1.45992231638418,
1.46362994350282, 1.4642195358687, 1.46497830514478, 1.46292372881356,
1.46326046879115, 1.46075594141892, 1.4626918018413, 1.46522991013001,
1.46767729569611, 1.46556834030683, 1.46354350123283, 1.46293202005101,
1.46216192405955, 1.46279539664412, 1.46416652028807, 1.46635751159332,
1.46744206538021, 1.46897280168999, 1.46536662843025, 1.46557031043884,
1.46789797713281, 1.46835554770942, 1.4694150120203, 1.46747460345749,
1.46710702490404, 1.46860547847741, 1.46663705019991, 1.4664345652562,
1.46345186781609, 1.46563852813853, 1.46283081925752, 1.45655110310671,
1.45227952506118, 1.45321531791908, 1.4547789396441, 1.45564738292011,
1.45421278931479, 1.45517865219358, 1.45266890970265, 1.45443743716296,
1.45503465888362, 1.45726148569365, 1.45540762356374, 1.45618509746766,
1.45435302779312, 1.45287885766928, 1.45133394664213, 1.45226409852764,
1.45390070921986, 1.45874769797422, 1.45672988399926, 1.46178846689572,
1.4674146797569, 1.4640179910045, 1.46468609865471, 1.47339173024395,
1.47045561296383, 1.47032863849765, 1.47437233538607, 1.47061043494669,
1.47251605591235, 1.47473215132265, 1.47768657420511, 1.47433962264151,
1.47615894039735, 1.47619047619048, 1.47506661591169, 1.47083612680778,
1.47052580800772, 1.4673786407767, 1.46719083673073, 1.46737852664577,
1.4680161147686, 1.47064637280095, 1.46837200079318, 1.47009818506397,
1.46631153201144, 1.46435925090695, 1.46418085731063, 1.46629705281587,
1.47042504706232, 1.47244016287615, 1.46962801741195, 1.46572500987752,
1.47040745514028, 1.46655971122029, 1.46671388101983, 1.46569960713206,
1.46444107233182, 1.45887708649469, 1.45496722138174, 1.4528824285573,
1.45116001194862, 1.4471463022508, 1.44598993785144, 1.45799803729146,
1.45748550083554, 1.45195033727637, 1.44973909618982, 1.44844597927972,
1.45353852185846, 1.45797913446677, 1.45808966861598, 1.46286266924565,
1.45828482731859, 1.4618320610687, 1.46203029706866, 1.46219309400372,
1.46284480219888, 1.46597735105859, 1.46784424709671, 1.4689243417833,
1.46860898567785, 1.47238907188529, 1.47246010120669, 1.47172011661808,
1.46688286163522, 1.46971327918583, 1.47072714749582, 1.47229862475442,
1.47179285222014, 1.46633416458853, 1.46399523903987, 1.46048587010412,
1.45797329143755, 1.45885579937304, 1.45979140267083, 1.46490971205466,
1.46888496270122, 1.46831875607386, 1.46836546846236, 1.46927047823123,
1.46807470421433, 1.462829499457, 1.46497003046084, 1.46442900479499,
1.46273932253314, 1.46406951767233, 1.4673116388156, 1.46543100912033,
1.45540647198106, 1.46271003242606, 1.45876085240726, 1.45973718012054,
1.46011549378487, 1.46333792018872, 1.46617056692451, 1.46380829785127,
1.4638067061144, 1.46371087192653, 1.46229022704837, 1.46666666666667,
1.4661108386464, 1.46767617938264, 1.46891393044492, 1.47142439879272,
1.46808094632906, 1.46796059689847, 1.46733815763739, 1.46692037470726,
1.4646265866378, 1.46480534801416, 1.46492177506642, 1.4623687858982,
1.46242774566474, 1.46307385229541, 1.4626074785043, 1.4633068968979,
1.46385298869144, 1.46180344478217, 1.46254927726675, 1.46241896272285,
1.46647171523646, 1.46721558389397, 1.46642431586388, 1.46720484359233,
1.46822373696872, 1.46890958245719, 1.46962101463806, 1.47268740031898,
1.47340742210756, 1.47341746993938, 1.47524262230145, 1.47560369671072,
1.47479367604653, 1.47198963317384, 1.47108097327483, 1.47302572315084,
1.4712827696618, 1.47083753784057, 1.47290739991913, 1.47313237221494,
1.47367359289893, 1.47733523479678, 1.47741935483871, 1.47505622572071,
1.46778337272634, 1.46253469010176, 1.46209942481512, 1.46357003391224,
1.45595482546201, 1.45030384179627, 1.45351356929109, 1.45500778412039,
1.44706984490476, 1.45556604763404, 1.45198866617693), .indexTZ = "UTC", .indexCLASS = "Date", tclass = "Date", tzone = "UTC", class = c("xts",
"zoo"), index = structure(c(978307200, 978393600, 978480000,
978566400, 978652800, 978912000, 978998400, 979084800, 979171200,
979257600, 979516800, 979603200, 979689600, 979776000, 979862400,
980121600, 980208000, 980294400, 980380800, 980467200, 980726400,
980812800, 980899200, 980985600, 981072000, 981331200, 981417600,
981504000, 981590400, 981676800, 981936000, 982022400, 982108800,
982195200, 982281600, 982540800, 982627200, 982713600, 982800000,
982886400, 983145600, 983232000, 983318400, 983404800, 983491200,
983750400, 983836800, 983923200, 984009600, 984096000, 984355200,
984441600, 984528000, 984614400, 984700800, 984960000, 985046400,
985132800, 985219200, 985305600, 985564800, 985651200, 985737600,
985824000, 985910400, 986169600, 986256000, 986342400, 986428800,
986515200, 986774400, 986860800, 986947200, 987033600, 987120000,
987379200, 987465600, 987552000, 987638400, 987724800, 987984000,
988070400, 988156800, 988243200, 988329600, 988588800, 988675200,
988761600, 988848000, 988934400, 989193600, 989280000, 989366400,
989452800, 989539200, 989798400, 989884800, 989971200, 990057600,
990144000, 990403200, 990489600, 990576000, 990662400, 990748800,
991008000, 991094400, 991180800, 991267200, 991353600, 991612800,
991699200, 991785600, 991872000, 991958400, 992217600, 992304000,
992390400, 992476800, 992563200, 992822400, 992908800, 992995200,
993081600, 993168000, 993427200, 993513600, 993600000, 993686400,
993772800, 994032000, 994118400, 994204800, 994291200, 994377600,
994636800, 994723200, 994809600, 994896000, 994982400, 995241600,
995328000, 995414400, 995500800, 995587200, 995846400, 995932800,
996019200, 996105600, 996192000, 996451200, 996537600, 996624000,
996710400, 996796800, 997056000, 997142400, 997228800, 997315200,
997401600, 997660800, 997747200, 997833600, 997920000, 998006400,
998265600, 998352000, 998438400, 998524800, 998611200, 998870400,
998956800, 999043200, 999129600, 999216000, 999475200, 999561600,
999648000, 999734400, 999820800, 1000080000, 1000166400, 1000252800,
1000339200, 1000425600, 1000684800, 1000771200, 1000857600, 1000944000,
1001030400, 1001289600, 1001376000, 1001462400, 1001548800, 1001635200,
1001894400, 1001980800, 1002067200, 1002153600, 1002240000, 1002499200,
1002585600, 1002672000, 1002758400, 1002844800, 1003104000, 1003190400,
1003276800, 1003363200, 1003449600, 1003708800, 1003795200, 1003881600,
1003968000, 1004054400, 1004313600, 1004400000, 1004486400, 1004572800,
1004659200, 1004918400, 1005004800, 1005091200, 1005177600, 1005264000,
1005523200, 1005609600, 1005696000, 1005782400, 1005868800, 1006128000,
1006214400, 1006300800, 1006387200, 1006473600, 1006732800, 1006819200,
1006905600, 1006992000, 1007078400, 1007337600, 1007424000, 1007510400,
1007596800, 1007683200, 1007942400, 1008028800, 1008115200, 1008201600,
1008288000, 1008547200, 1008633600, 1008720000, 1008806400, 1008892800,
1009152000, 1009238400, 1009324800, 1009411200, 1009497600, 1009756800,
1009843200, 1009929600, 1010016000, 1010102400, 1010361600, 1010448000,
1010534400, 1010620800, 1010707200, 1010966400, 1011052800, 1011139200,
1011225600, 1011312000, 1011571200, 1011657600, 1011744000, 1011830400,
1011916800, 1012176000, 1012262400, 1012348800, 1012435200, 1012521600,
1012780800, 1012867200, 1012953600, 1013040000, 1013126400, 1013385600,
1013472000, 1013558400, 1013644800, 1013731200, 1013990400, 1014076800,
1014163200, 1014249600, 1014336000, 1014595200, 1014681600, 1014768000,
1014854400, 1014940800, 1015200000, 1015286400, 1015372800, 1015459200,
1015545600, 1015804800, 1015891200, 1015977600, 1016064000, 1016150400,
1016409600, 1016496000, 1016582400, 1016668800, 1016755200, 1017014400,
1017100800, 1017187200, 1017273600, 1017360000, 1017619200, 1017705600,
1017792000, 1017878400, 1017964800, 1018224000, 1018310400, 1018396800,
1018483200, 1018569600, 1018828800, 1018915200, 1019001600, 1019088000,
1019174400, 1019433600, 1019520000, 1019606400, 1019692800, 1019779200,
1020038400, 1020124800, 1020211200, 1020297600, 1020384000, 1020643200,
1020729600, 1020816000, 1020902400, 1020988800, 1021248000, 1021334400,
1021420800, 1021507200, 1021593600, 1021852800, 1021939200, 1022025600,
1022112000, 1022198400, 1022457600, 1022544000, 1022630400, 1022716800,
1022803200, 1023062400, 1023148800, 1023235200, 1023321600, 1023408000,
1023667200, 1023753600, 1023840000, 1023926400, 1024012800, 1024272000,
1024358400, 1024444800, 1024531200, 1024617600, 1024876800, 1024963200,
1025049600, 1025136000, 1025222400, 1025481600, 1025568000, 1025654400,
1025740800, 1025827200, 1026086400, 1026172800, 1026259200, 1026345600,
1026432000, 1026691200, 1026777600, 1026864000, 1026950400, 1027036800,
1027296000, 1027382400, 1027468800, 1027555200, 1027641600, 1027900800,
1027987200, 1028073600, 1028160000, 1028246400, 1028505600, 1028592000,
1028678400, 1028764800, 1028851200, 1029110400, 1029196800, 1029283200,
1029369600, 1029456000, 1029715200, 1029801600, 1029888000, 1029974400,
1030060800, 1030320000, 1030406400, 1030492800, 1030579200, 1030665600,
1030924800, 1031011200, 1031097600, 1031184000, 1031270400, 1031529600,
1031616000, 1031702400, 1031788800, 1031875200, 1032134400, 1032220800,
1032307200, 1032393600, 1032480000, 1032739200, 1032825600, 1032912000,
1032998400, 1033084800, 1033344000, 1033430400, 1033516800, 1033603200,
1033689600, 1033948800, 1034035200, 1034121600, 1034208000, 1034294400,
1034553600, 1034640000, 1034726400, 1034812800, 1034899200, 1035158400,
1035244800, 1035331200, 1035417600, 1035504000, 1035763200, 1035849600,
1035936000, 1036022400, 1036108800, 1036368000, 1036454400, 1036540800,
1036627200, 1036713600, 1036972800, 1037059200, 1037145600, 1037232000,
1037318400, 1037577600, 1037664000, 1037750400, 1037836800, 1037923200,
1038182400, 1038268800, 1038355200, 1038441600, 1038528000, 1038787200,
1038873600, 1038960000, 1039046400, 1039132800, 1039392000, 1039478400,
1039564800, 1039651200, 1039737600, 1039996800, 1040083200, 1040169600,
1040256000, 1040342400, 1040601600, 1040688000, 1040774400, 1040860800,
1040947200, 1041206400, 1041292800), tzone = "UTC", tclass = "Date"), .Dim = c(522L,
1L), .Dimnames = list(NULL, "Series1"))
Series2:
structure(c(100, 100.32, 100.57, 100.82, 100.98, 101.01, 101.16,
101.3, 101.75, 102.07, 102.12, 102.3, 102.44, 102.59, 102.62,
102.74, 102.84, 103.09, 103.25, 103.31, 103.35, 103.48, 103.6,
103.72, 103.84, 103.96, 104.1, 104.35, 104.52, 104.69, 104.82,
104.96, 104.9, 105.03, 105.08, 105.27, 105.46, 105.55, 105.78,
105.94, 106.11, 106.36, 106.52, 106.6, 106.7, 106.92, 107.1,
107.27, 107.39, 107.41, 107.54, 107.72, 107.96, 108.13, 108.3,
108.43, 108.56, 108.68, 108.77), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC", class = c("xts",
"zoo"), index = structure(c(1010102400, 1010707200, 1011312000,
1011916800, 1012435200, 1012521600, 1013126400, 1013731200, 1014336000,
1014854400, 1014940800, 1015545600, 1016150400, 1016755200, 1017360000,
1017964800, 1018569600, 1019174400, 1019779200, 1020124800, 1020384000,
1020988800, 1021593600, 1022198400, 1022803200, 1023408000, 1024012800,
1024617600, 1025222400, 1025827200, 1026432000, 1027036800, 1027641600,
1028073600, 1028246400, 1028851200, 1029456000, 1030060800, 1030665600,
1031270400, 1031875200, 1032480000, 1033084800, 1033344000, 1033689600,
1034294400, 1034899200, 1035504000, 1036022400, 1036108800, 1036713600,
1037318400, 1037923200, 1038528000, 1039132800, 1039737600, 1040342400,
1040947200, 1041292800), tzone = "UTC", tclass = "Date"), .Dim = c(59L,
1L), .Dimnames = list(NULL, "Series2"))
na.locf() will do the job:
Test<-merge.xts(Series1, Series2, join="left", fill=na.locf())
This function "Last Observation Carried Forward" fills the NA with the last knowne value.
Hope this helps people landing here, years after you asked the question.