Related
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 downloaded some raw data on inflation which said in the description that it has not been seasonally adjusted. Therefore I assumed that there is some seasonality present. I did not check if this is indeed true. What is the common way of checking a time-series for the presence of seasonality?
Nevertheless, I still tried to apply the procedure, but the before and after result are exactly the same; nothing has changed.
The code:
if (!require("tis")) {install.packages("tis"); library('tis')} # Load time series library
if (!require("seasonal")) {install.packages("seasonal"); library('seasonal')}
inflation.start <- c(1960,1)
inflation.end <- c(2018,1)
inflation.raw <- "rawData/germany_inflation.csv"
inflation.table <- read.table(inflation.raw, skip = 1, header = F, sep = ',', stringsAsFactors = F)
inflation.ger <- ts(inflation.table[,2], start = inflation.start, frequency = 4)
# ts.plot(inflation.ger)
inflation.seasadj <- final(seas(as.ts(naWindow(inflation.ger),freq=4))) # seasonal adjustment
inflation.seasadj.ger <- ts(inflation.seasadj, start = inflation.start, frequency = 4)
So apparently, inflation.ger and inflation.seasadj.ger are the exact same time-series. What could have gone wrong?
The data:
dput(inflation.ger)
structure(c(2.22222222222224, 1.244019138756, 0.75973409306742,
1.80608365019013, 1.98487712665404, 2.64650283553874, 2.73327049952876,
3.36134453781511, 3.15106580166824, 2.39410681399631, 2.47706422018348,
3.25203252032522, 2.87511230907457, 2.42805755395685, 3.31244404655327,
2.27471566054242, 2.09606986899562, 2.72168568920105, 2.2530329289428,
2.05303678357573, 3.07955517536358, 3.84615384615386, 3.98305084745763,
4.10729253981556, 4.06639004149377, 3.04526748971191, 2.93398533007336,
2.49597423510466, 1.8341307814992, 1.75718849840257, 1.10847189231985,
1.49253731343286, 1.25293657008615, 1.33437990580847, 1.80109631949884,
1.62538699690402, 2.01082753286931, 2.09140201394268, 1.92307692307691,
2.89413556740292, 3.33586050037907, 3.5660091047041, 4.00000000000001,
4.44115470022204, 5.06236243580337, 5.78754578754579, 5.66037735849054,
5.31537916371368, 4.88826815642457, 5.47091412742381, 6.25000000000001,
6.46029609690444, 7.39014647137152, 6.9599474720946, 7.30446024563674,
7.45891276864728, 7.06757594544325, 6.99815837937383, 6.44578313253009,
5.88235294117648, 6.25361899247252, 6.08146873207113, 5.43293718166383,
5.22222222222223, 4.30517711171662, 3.78583017847487, 3.70370370370372,
3.80147835269271, 3.81400208986417, 3.85617509119333, 3.46790890269152,
3.00101729399797, 2.86864620030195, 2.50878073256398, 2.50125062531265,
2.91358024691356, 3.27788649706457, 4.650024473813, 5.31966813079548,
5.51823416506719, 5.92136428233066, 5.19176800748362, 5.14365152919371,
5.72987721691677, 5.81395348837209, 6.66963094708762, 7.13970912296167,
5.89247311827958, 5.36770921386304, 5.08545227177989, 4.648292883587,
4.06173842404549, 3.28920978740473, 3.13367711225704, 2.71226415094341,
2.84933645589384, 2.83495145631071, 1.88461538461538, 2.06659012629162,
2.31499051233397, 2.30362537764349, 2.076255190638, 1.57480314960629,
0.741839762611279, 0, -0.332840236686399, -0.922849760059066,
-0.515463917525782, 0.0369139904023732, 0.519480519480511, 0.968703427719836,
0.962250185048109, 1.14391143911439, 1.29198966408267, 1.69741697416972,
2.4193548387097, 2.88215979569498, 2.80612244897959, 3.01161103047896,
2.72011453113812, 2.3049645390071, 2.72952853598016, 3.02923564635434,
2.84251480582282, 3.29915972330998, 4.51351791825871, 5.50437317784258,
5.9108527131783, 6.09404990403073, 4.95750708215298, 3.33642261353105,
4.66605672461115, 4.38715513342377, 4.5434098065677, 4.30493273542601,
2.97202797202796, 2.77296360485268, 2.58175559380379, 2.45055889939811,
2.07979626485568, 1.7284991568297, 1.5520134228188, 1.46873688627781,
1.45530145530146, 1.45047658516367, 1.36307311028499, 1.53019023986766,
1.76229508196721, 1.55228758169937, 2.32273838630808, 2.11812627291242,
1.24848973016513, 1.36765888978277, 0.597371565113501, 0.438771439968094,
0.198886237072386, 0.515873015873038, 0.673000791765629, 0.953137410643369,
1.54823342596267, 1.10540860639556, 1.37632717263074, 1.73092053501181,
1.72009382329947, 2.53807106598985, 2.01706749418153, 1.6627996906419,
1.99846272098384, 1.29474485910129, 1.21673003802282, 1.17915557246102,
1.13036925395631, 0.789473684210527, 1.05184072126221, 1.16541353383457,
0.968703427719814, 1.86497575531517, 1.82156133828996, 2.0066889632107,
1.62361623616237, 1.24496521420726, 1.64293537787514, 1.67577413479055,
1.70660856935367, 1.84448462929475, 1.4727011494253, 1.28986026513793,
1.7850767583006, 2.05965909090908, 2.26548672566371, 3.0774672798019,
2.94633461943178, 2.88796102992346, 3.08065074420214, 1.61290322580647,
0.81771720613288, 0.270544470747383, -0.235057085292139, 0.405268490374862,
0.811084825954715, 1.11298482293424, 1.11073712554695, 1.37907837201482,
1.87730472678512, 2.00133422281521, 2.19707057256989, 2.22295952222959,
2.13886146758801, 1.86396337475473, 2.01954397394136, 2.01233365790325,
1.54639175257732, 1.50882825040129, 1.62835249042147, 1.33630289532296,
1.20558375634519, 1.07526881720429, 0.848256361922726, 0.50235478806906,
0.0313479623824208, 0.469336670838559, 0.124610591900319, 0.312402374258052,
0.250705108116592, 0.0934288383680993, 0.466708151835709, 1.12114606041732,
1.87558612066271, 1.68014934660859, 1.73428305977082, 1.66307360640589,
1.50352868978214), .Tsp = c(1960, 2017.75, 4), class = "ts")
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]))
I have been working on a text mining project. I have performed some LDA topic modelling and now I have my topic probabilities. I would like to use the cluster package so that I can get the euclidean distances between documents so I can create a network graph, but I keep on getting an error. Any recommendation for good visualisation techniques would also be warmly welcomed :)
library(cluster)
FundDist <- as.matrix(daisy(EUTopicNetworks, metric = "euclidean", stand = TRUE))
Error in daisy(EUTopicNetworks, metric = "euclidean", stand = TRUE) : invalid type character for column numbers 1
In addition: Warning messages:
1: In data.matrix(x) : NAs introduced by coercion
2: In daisy(EUTopicNetworks, metric = "euclidean", stand = TRUE) :
with mixed variables, metric "gower" is used automatically
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
I have never uploaded reproducible data on this website using the dput() function before. So I hope I have done this correct. I have copied and pasted the output below. Thank you for taking the time to read my problem.
EUTopicNetworks <- structure(list(Filename = c("AT_Burenland_2007.txt", "AT21_Kaernten_07.txt",
"AT12_LowerAustria_07_13.txt", "AT_Nat_2007.txt", "AT34_Salzburg_07.txt",
"AT22_Steiermark_07.txt", "AT36_Tirol_07.txt", "UpperAustria2007.txt",
"AT13_Vienna_07.txt", "vorarlberg2007.txt", "AT_Austria_1.txt",
"AT11_Burgenland_1", "lowe austria 2014.txt", "AT13_Vienna2_14.txt",
"AT21_Kaernten_14.txt", "AT22_Steiermark_14.txt", "AT31_UpperAustria_14.txt",
"AT35_Salzburg_14.txt", "AT36_Tirol_14.txt", "AT37_Vorarlberg_14.txt",
"abbruzzo2007-2013.txt", "calabria2007-2013.txt", "campania2007-2013.txt",
"emiliaromagna2007-2013.txt", "sicily2007.txtt", "friuli2007-2013.txt",
"lazio2007-2013.txt", "liguria2007.txt", "lombardy2007-2013.txt",
"piemonte2007-2013.txt", "puglia2007-2013.txt", "sardinia2007-2013.txt",
"Bolzano_07.txt", "umbria 2007-2013.txt", "valledaosta 2007-2013.txt",
"tuscany2007.txt", "VENETO2007-2013.txt", "abruzzo2014-2020.txt",
"basilicata2014-2020.txt", "calabria2014-2020.txt", "campania2014-2020.txt",
"emiliaromagna2014-2020.txt", "sicily2014.txt", "friuli2014-2020.txt",
"lazio2014.txt", "liguria2014.txt", "lombardia2014-2020.txt",
"piemonte2014-2020.txt", "puglia_14.txt", "sardinia2014.txt",
"Bolzano_14.txt", "umbria2014.txt", "valledaosta 2014-2020.txt",
"tuscany2014.txt", "molise_14.txt", "molise_07.txt", "trento2007.txt",
"trento2014.txt", "ITALIANSTRATEGICPLAN2007-2013.txt", "italyinnovationstrategy2014-2020.txt",
"veneto2014-2020.txt", "aquitanie2014-2020.txt", "aquitanie2007.txt",
"auvergne2014-2020.txt", "auvergne_07.txt", "bretagne2014-2020.txt",
"bretagne_07.txt", "centre2014-2020.txt", "centre2007.txt", "champagne-ardenne 2007.txt",
"champagne-ardenne 2014.txt", "PICARDIE2007.txt", "picardie2014.txt",
"bassenormandie 2007.txt", "bassenormandie 2014.txt", "bourgogne2014.txt",
"bourgogne_07.txt", "midi-pyrenees2007.txt", "midipyrennes14.txt",
"franche-comte2014-2020.txt", "franche-comte_2007.txt", "hautenormandie2007.txt",
"hautenormandie2014-2020.txt", "limousine2014-2020.txt", "limousine2007.txt",
"loire2007.txt", "loire2014-2020.txt", "lorraine2014-2020.txt",
"lorraine2007.txt", "nordpasdecalais2007.txt", "nordpasdecalais2014-2020.txt",
"rhonealpes2014-2020.txt", "rhone-alpes2007.txt", "poitou-charenter2007.txt",
"poituou-charentes2014.txt", "corse2007.txt", "corsica.txt",
"bretagne_07.txt", "bretagne2014-2020.txt", "Baden-Wu_07.txt",
"Baden-wu14.txt", "bavaria2007.txt", "BAVARIA_14.txt", "BERLIN2014-2020.txt",
"Berlin_07.txt", "bradenburgh2014.txt", "Bradenburgh2007.txt",
"bremen2007.txt", "bremen2014.txt", "hamburg_07.txt", "HAMBURGO2014-2020.txt",
"Hessen_07.txt", "Hessian1.txt", "LowerSaxony2_07.txt", "LOWERSAXONY2014-2020.txt",
"Mecklenburg_07.txt", "MECKPOMM2014-2020.txt", "rheinland2014-2020.txt",
"RhinelanPlatz_07.txt", "saarland2014-2020.txt", "saarland_07.txt",
"sachsen-anhalt2014-2020.txt", "sachsen-anhelt2007.txt", "saxony_07.txt",
"saxony_14.txt", "Schleswig-Holstein2020.txt", "Schleswig-Holstein_07.txt",
"thuringia2007.txt", "THURINGIA2014-2020.txt", "Andalucia_2007-2013.txt",
"Andalusia_14.txt", "Aragon_14.txt", "Aragon_2007.txt", "Asturias_2007.txt",
"ES12_Asturias.txt", "Baleares_2007.txt", "Balears_14.txt", "Canarias_07.txt",
"Canaries_14.txt", "Cantabria_2007.txt", "ES13_Cantabria_14.txt",
"Castillala_Mancha_2007.txt", "ES42_Castilla-la_mancha.txt",
"CastillayLeon_dic_2007.txt", "ES41_Castilla-Leon.txt", "ES51_Catalonia_14.txt",
"catalonia2007.txt", "Madrid_2007-13.txt", "Madrid_14.txt", "Murcia_14.txt",
"murcia2007.txt", "Valencia_14.txt", "Valenciana_2007.txt", "laRioja2007.txt",
"CombiEngland_07.txt", "EastWales_07.txt", "NorthernIreland_07.txt",
"Scotland_07.txt", "WestWales_07.txt", "EastWales_14.txt", "England_14.txt",
"Northern_Ireland14.txt", "Scotland14.txt", "Westwales_14.txt",
"malta2007-2013.2.txt", "malta2014-2020.txt2.txt"), Funds = c(0.028649302,
0.036198106, 0.041060412, 0.036543709, 0.047044295, 0.01659907,
0.019221094, 0.056763265, 0.052615278, 0.045216842, 0.048176521,
0.038976137, 0.027341846, 0.037721688, 0.049252945, 0.05918185,
0.05440539, 0.017412537, 0.029307636, 0.022385126, 0.019737738,
0.027626844, 0.0334503, 0.043976555, 0.042856083, 0.021046234,
0.018061427, 0.014983543, 0.067145641, 0.019741648, 0.019018285,
0.030614714, 0.019666862, 0.028158874, 0.026009936, 0.019330949,
0.023088856, 0.044273539, 0.021168401, 0.017627883, 0.030486684,
0.017509486, 0.034035728, 0.034106673, 0.043486846, 0.029087254,
0.050564915, 0.047219925, 0.051437475, 0.029694445, 0.008588781,
0.045469371, 0.060967658, 0.049260664, 0.015106536, 0.026186649,
0.023254401, 0.053579943, 0.031056644, 0.045125396, 0.057680642,
0.01125217, 0.042532521, 0.041545015, 0.047940862, 0.036641552,
0.072252939, 0.035679102, 0.067488953, 0.008492444, 0.021052205,
0.020152732, 0.040564092, 0.02921307, 0.018565646, 0.022775302,
0.011711217, 0.019967731, 0.00877454, 0.022250866, 0.003696986,
0.011277284, 0.007740289, 0.02790784, 0.008134596, 0.014931457,
0.03269353, 0.041386999, 0.066164327, 0.011440048, 0.006215758,
0.010688796, 0.003811851, 0.003303556, 0.023094521, 0.010550119,
0.018023822, 0.022757839, 0.017667203, 0.02073341, 0.013537221,
0.011950717, 0.009010298, 0.019796088, 0.011314152, 0.01098032,
0.008832217, 0.040330019, 0.005822583, 0.006599734, 0.016338338,
0.013906508, 0.010973094, 0.010448791, 0.003723683, 0.013769165,
0.007583811, 0.009724543, 0.00237987, 0.005005899, 0.005048481,
0.013000829, 0.012671508, 0.003054379, 0.03508621, 0.012981055,
0.021982606, 0.009448894, 0.014883524, 0.018772709, 0.006068872,
0.018122102, 0.020449118, 0.015102835, 0.005449833, 0.011014679,
0.016602374, 0.006482356, 0.009969209, 0.002646448, 0.01205523,
0.04659564, 0.010866707, 0.0144986, 0.046946229, 0.028629168,
0.034634807, 0.059078927, 0.002919951, 0.016168915, 0.024403654,
0.09171777, 0.009978063, 0.015196456, 0.015174811, 0.047399696,
0.015303701, 0.011753077, 0.014862118, 0.01487099, 0.011742448,
0.018346786, 0.010785336, 0.010421162, 0.013791872, 0.026389358
), Biotech = c(0.024814541, 0.005668351, 0.017716491, 0.00853945,
0.015916015, 0.03888657, 0.001333459, 0.017368849, 0.023781704,
0.051278428, 0.005484117, 0.021759003, 0.027973849, 0.002774256,
0.005744201, 0.004244159, 0.00468969, 0.000581776, 0.022734494,
0.03445351, 0.000800523, 0.000362683, 0.026945766, 0.006823146,
0.005847249, 0.000630851, 0.020794353, 0.035979974, 0.006165474,
0.027793267, 0.00504312, 0.018927097, 0.000760576, 0.012289583,
0.002109001, 0.000442817, 0.000594334, 0.00037428, 0.06596126,
0.027988907, 0.019067461, 0.024872467, 0.015379713, 0.015295277,
9.36e-05, 0.000117979, 4e-05, 0.031220784, 0.001357913, 0.040951957,
0.000438858, 0.038880733, 0.00115553, 0.041152387, 0.042576251,
0.002254845, 0.022345729, 0.002596388, 0.022562024, 0.000243528,
0.000885187, 0.013339204, 0.001418329, 0.028089687, 0.002057198,
0.000244579, 0.000140129, 0.051721762, 0.014989271, 0.001673642,
0.04500578, 0.001615416, 0.00010688, 8.18e-05, 0.000526549, 0.024849247,
0.032961749, 0.033875354, 0.032145136, 0.012619383, 0.003522134,
0.012225185, 0.043464039, 0.077400519, 0.056308327, 0.020638077,
0.049992043, 0.038864222, 0.039459316, 0.034937031, 0.037406742,
0.029987413, 0.002413193, 0.000584526, 0.004584848, 0.012491496,
0.031710331, 0.017858395, 0.030812232, 0.003435739, 0.02648106,
0.006927007, 0.030785802, 0.044329986, 0.009838859, 0.002951219,
0.030722621, 0.020511401, 0.013623405, 0.081263322, 0.029623712,
0.003790876, 0.00335598, 0.018842609, 0.008430911, 0.032611226,
0.057455638, 0.004304486, 0.015733474, 0.043981231, 7.95e-05,
0.004054158, 0.045173701, 0.016378658, 0.015906368, 2.92e-05,
0.00057313, 0.00079682, 0.013209159, 0.039911915, 0.000237856,
0.022373161, 0.015821272, 0.026750309, 0.048698356, 0.041430357,
0.00287091, 0.007965338, 0.034481633, 0.001543219, 0.022152119,
0.041801127, 0.017463336, 0.038010604, 0.050393079, 0.045031199,
0.043613378, 0.037411148, 0.00186188, 0.018962051, 0.043254408,
0.018666636, 0.027696462, 0.024293257, 0.062711642, 0.000519461,
0.001056595, 0.031300324, 0.024742217, 0.024718682, 0.000780182,
0.01862668, 0.000973041, 0.000542227, 0.001011475, 0.011077226
), Transfers = c(0.00473547, 0.00038783, 0.000424567, 0.000695775,
0.000135175, 0.010334213, 0.000106781, 0.003008423, 0.000608193,
0.010326284, 0.000934925, 0.031277279, 0.00572826, 0.000260722,
0.001021529, 0.000154104, 0.000220061, 4.32e-05, 0.018335222,
0.013011634, 2.49e-05, 4.83e-05, 0.021935677, 0.000390414, 0.000130749,
3.77e-05, 0.009460382, 0.146681735, 7.44e-05, 0.082389135, 0.000592343,
0.000562132, 1.53e-05, 0.020403948, 1.31e-05, 2.46e-05, 5.51e-05,
0.000321357, 0.037377138, 0.006516009, 0.022055996, 0.041838049,
0.002549792, 0.00271147, 8.55e-05, 0.001550897, 0.001094715,
0.002059784, 2.73e-05, 0.012813067, 9.84e-06, 0.009924993, 8.74e-05,
0.004619721, 0.013069859, 2.14e-05, 0.053722696, 5.79e-05, 0.006753522,
1.18e-05, 0.005116721, 0.000108002, 2.73e-05, 0.003596542, 2.79e-05,
0.00438903, 8.31e-05, 0.026310482, 0.001005592, 0.000428282,
0.049529581, 1.93e-05, 8.57e-05, 0.001610554, 9.92e-06, 0.094923027,
0.031919217, 0.13955002, 0.083229087, 0.000284159, 0.000267466,
0.000349366, 0.056697448, 0.049064161, 0.075636951, 0.004204928,
0.006115066, 0.007264789, 0.002044115, 0.043477142, 0.046506897,
0.082070827, 0.00035585, 0.010126049, 0.000178782, 0.000133394,
0.019258021, 9.19e-05, 0.069771158, 0.164961859, 0.030302868,
0.008376654, 0.095394069, 0.069931231, 0.000553351, 0.000544636,
0.095332857, 0.001748097, 0.000288915, 0.049584358, 0.095331287,
0.000598831, 0.001574565, 0.124263691, 3.34e-05, 0.107925558,
0.087354139, 0.000618826, 0.000110399, 0.035831715, 5.52e-06,
0.003000538, 0.076722556, 0.001625612, 0.00057855, 2.15e-05,
6.78e-05, 0.000268523, 0.000567245, 0.04113056, 1.71e-05, 0.03401376,
0.001848523, 0.029357767, 0.078771496, 0.05552954, 0.068487283,
0.001617493, 0.045003856, 0.000170027, 0.102169304, 0.033286348,
0.000645582, 0.123061518, 0.024437451, 0.002628661, 0.013120533,
0.002000205, 0.000545963, 0.103891281, 0.01547252, 0.004918401,
0.032767954, 0.084638687, 0.093356166, 0.000156201, 0.000752217,
0.109659324, 0.208642497, 0.208474925, 0.000404265, 0.078084401,
0.000538784, 0.012066067, 0.018067282, 0.000205862), Collab = c(0.030001488,
0.036707564, 0.01458121, 0.026231048, 0.018525526, 0.011553297,
0.058634057, 0.001686141, 0.001348074, 0.006757227, 0.013508918,
0.003715637, 0.002921306, 0.009278328, 0.004626478, 0.002879119,
0.055770088, 0.095661212, 0.017193222, 0.004260887, 0.0994825,
0.094794299, 0.00236101, 0.05708391, 0.070789976, 0.093534164,
0.001109712, 0.009766358, 0.033402635, 0.011669702, 0.06682796,
0.001608723, 0.076258585, 0.0177607, 0.081032098, 0.094412392,
0.105163053, 0.000130001, 0.000308904, 0.000673957, 0.000108183,
0.006185235, 0.001417778, 0.001392482, 0.001763266, 4.19e-05,
0.000316372, 0.000538187, 0.057255911, 0.000888558, 0.117687659,
0.002003037, 0.068194122, 0.000653657, 0.000152612, 0.089555908,
0.002829031, 0.032391752, 0.000114824, 0.001213285, 0.000386851,
0.015705495, 0.049863754, 0.000186015, 0.036288112, 0.000121075,
0.001514642, 0.00150885, 0.000594681, 0.139375952, 0.002323917,
0.075647519, 0.002870689, 3.77e-05, 0.077144908, 0.026437255,
0.000115174, 0.00227099, 0.004700389, 0.041492391, 0.122675327,
0.020817113, 6.89e-05, 0.000303617, 0.000137477, 0.001432608,
0.000184365, 0.001050974, 0.000709209, 0.000270104, 0.000303001,
0.018320147, 0.099247105, 0.082998488, 0.000888759, 0.016183068,
0.006294048, 0.002853816, 0.019514895, 0.038458183, 0.002923949,
0.106293548, 0.011739459, 0.000128574, 0.007004556, 0.114129525,
0.012154148, 0.00942754, 0.009594396, 1.79e-05, 0.003734627,
8.05e-06, 0.119908919, 0.018081544, 0.075305864, 0.008538072,
0.000172614, 0.011539718, 0.001156176, 2.3e-05, 0.06492041, 0.12754611,
0.00024379, 0.006267908, 0.00306844, 0.001193837, 0.013286424,
0.113241894, 0.00550093, 0.000513184, 0.164987722, 0.008430982,
0.01127053, 0.00073653, 0.000330426, 0.002238095, 0.104762755,
0.010050252, 0.000469937, 0.145991698, 0.016278919, 0.000640692,
0.005282822, 0.005445685, 0.00014593, 0.000589578, 0.003085291,
0.003763146, 0.118843056, 0.019891671, 0.007112815, 0.004553507,
0.014161345, 0.011043344, 1.65e-05, 0.05419503, 0.107074967,
0.01952576, 0.015831838, 0.015618949, 0.133629759, 0.016718132,
0.120940954, 0.072855599, 0.066799617, 0.006925232)), .Names = c("Filename",
"Funds", "Biotech", "Transfers", "Collab"), class = "data.frame", row.names = c(NA,
-166L))
As #Cath mentioned, your problem is with the column of text. Removing this works:
EUTopicNetworks2 <- EUTopicNetworks[,-1]
class(EUTopicNetworks2)
library(cluster)
FundDist <- as.matrix(daisy(EUTopicNetworks2, metric = "euclidean", stand = TRUE))
By running this code I was able to answer the question I posed in one of the comments
row.names(EUTopicNetworks) <- EUTopicNetworks[,1]
EUTopicNetworks <- EUTopicNetworks[,-1]
library(cluster)
FundDist <- as.matrix(daisy(EUTopicNetworks, metric = "euclidean", stand = TRUE))
Im trying to query trades from IB by using function reqExecutions:
library(IBrokers)
con <- twsConnect(clientId=1)
id <- reqIds(con)
Order <- twsOrder(orderId=id, action="BUY", totalQuantity = 1, orderType="LMT", lmtPrice = 600, tif="GTC")
placeOrder(con, twsSTK("AAPL", Order)
print(reqExecutions(con, reqId = as.character(.Last.orderId), ExecutionFilter = twsExecutionFilter(clientId="1")))
although trades are executed in IB, it always returns NULL.
Can't you just use reqOpenOrders?
Warning: The following will execute a trade. Make sure you are connected to a paper trading account before running this code!
library(IBrokers)
#con <- twsConnect(clientId=1)
con <- ibgConnect(clientId=1)
id <- reqIds(con)
Order <- twsOrder(orderId=id, action="BUY", totalQuantity = 1, orderType="LMT",
lmtPrice = 600, tif="GTC")
placeOrder(con, twsSTK("AAPL"), Order)
> reqOpenOrders(twsconn=con)
TWS Message: 2 -1 2100 New account data requested. API client has been unsubscribed from account data.
TWS Execution: orderId=1 time=2012-03-26 08:47:29 side=BOT shares=1 symbol=AAPL conId=265598 price=597.91