k <= n is not TRUE in rollmeanr - r

I have the following matrix:
X1 X2 X3 X4 X5 X6 X7 X8 X9 X10
A.DCE 3838.00 3838.0 3838.0 3838.0 3838.00 3837.00 3837.0 3836.0 3835.00 3824.0
AG.SHF 3840.00 3841.0 3842.0 3842.0 3842.00 3846.00 3846.0 3848.0 3847.00 3854.0
AU.SHF 272.75 272.8 272.8 272.8 272.85 272.85 272.9 272.9 272.95 273.1
I.DCE 493.00 492.5 493.0 493.0 491.00 491.00 491.0 491.0 491.50 494.5
IC.CFE 5968.60 5971.8 5970.0 5967.6 5972.20 5973.00 5973.6 5973.6 5978.00 6052.2
IF.CFE 3691.40 3693.8 3694.0 3696.0 3700.00 3699.00 3699.4 3698.8 3702.20 3701.2
IH.CFE 2652.20 2653.6 2653.6 2656.8 2664.40 2660.00 2658.0 2661.4 2662.00 2639.4
J.DCE 1897.50 1897.0 1898.0 1897.0 1896.00 1896.00 1895.0 1895.0 1896.00 1883.0
JM.DCE 1223.00 1222.0 1222.5 1222.0 1220.50 1220.50 1218.5 1221.0 1221.50 1205.0
M.DCE 2811.00 2811.0 2811.0 2812.0 2811.00 2812.00 2811.0 2810.0 2810.00 2810.0
RB.SHF 3658.00 3658.0 3661.0 3660.0 3654.00 3656.00 3652.0 3652.0 3653.00 3636.0
Y.DCE 6102.00 6102.0 6106.0 6104.0 6102.00 6098.00 6094.0 6090.0 6094.00 6084.0
ZC.CZC 614.20 614.0 614.2 614.0 613.80 613.80 613.8 614.0 614.00 611.6
I want to apply roll-mean to every row. When I call this function from Rcpp package
rollmeanr((df_close[2,]),2,fill=NA)
I receive this error: Error: k <= n is not TRUE
Although when I do the same on columns in works well

That function "prefers" columns as is for time series.
This should work:
rollmeanr(t(df_close[,-1])[,2],2,fill=NA)

Related

Crash when Database.Migrate() is called during startup

I have a Xamarin Forms application which uses Entity Framework Core. When I start and test on the emulator everything is fine. Also when I start on a device which has a previous version running it works as expected. But when I run the app on a device with no data on it crashes when the following is executed:
var context = new EfCoreContext();
context.Database.Migrate();
I first noticed it when the prelaunch reports of google failed on 7 of 9 devices. The error there is:
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'google/walleye/walleye:9/PQ2A.190405.003/5310204:user/release-keys'
Revision: 'MP1'
ABI: 'arm64'
pid: 12770, tid: 12770, name: utions.moneyfox >>> com.applysolutions.moneyfox <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x20
Cause: null pointer dereference
x0 0000000000000000 x1 0000000000000000 x2 0000000000000000 x3 0000007fec923bd0
x4 0000007f29ade9a0 x5 0000007fec923c60 x6 0000000000000000 x7 0000000000000000
x8 0000000000000000 x9 0000000000000000 x10 0000000000000000 x11 0000000000000000
x12 0000000000000000 x13 0000000000000000 x14 00000000ffffffff x15 0000000000000000
x16 0000007f1bd1d1f8 x17 0000007f1bb44670 x18 0000000000000008 x19 0000007f1bd34560
x20 0000000000000002 x21 0000000000000000 x22 0000000000000000 x23 000000000000007f
x24 0000000000000000 x25 0000000000000000 x26 0000007fec923d50 x27 0000007f16bdda34
x28 0000007f29ade000 x29 0000007fec923070
sp 0000007fec923070 lr 0000007f1ba8b658 pc 0000007f1bb44678
backtrace:
#00 pc 0000000000177678 /data/app/com.applysolutions.moneyfox-tqWhOmZmoDQ8yd5YLjvTqg==/lib/arm64/libmonosgen-2.0.so (mono_jit_info_get_method+8)
Funny enough, when I remove the Migrate call, start and add it again the app can start. Also in the prelaunch report are always 2 or 3 devices who can start the app without any issue. I can imagine that this is some kind of timing issue or that some other effect play in here. But the crash is consistently on that call no matter where in my application I put it.
I tried to get more information with try catches and global error handler which should log to my log file. But unfortunately, nothing is caught.
Is there a way to narrow down the issue, may be based on the error log from the prelaunch report?
Alright, it seems that is an issue in Xamarin.Android: https://developercommunity.visualstudio.com/content/problem/580820/xamarin-problem-following-update-to-vs2019-161.html
And it seems like it is fixed with 16.1.4.

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

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

Copy values from Dataframe to new Dataframe depending on value in first column and first row [duplicate]

I am trying to use unix to transform a tab delimited file from a short/wide format to long format, in a similar way as the reshape function in R. I hope to create three rows for each row in the starting file. Column 4 currently contains 3 values separated by commas. I hope to keep columns 1, 2, and 3 the same for each starting row, but have column 4 be one of the values from the initial column 4. This example probably makes it more clear than I can describe verbally:
current file:
A1 A2 A3 A4,A5,A6
B1 B2 B3 B4,B5,B6
C1 C2 C3 C4,C5,C6
goal:
A1 A2 A3 A4
A1 A2 A3 A5
A1 A2 A3 A6
B1 B2 B3 B4
B1 B2 B3 B5
B1 B2 B3 B6
C1 C2 C3 C4
C1 C2 C3 C5
C1 C2 C3 C6
As someone just becoming familiar with this language, my initial thought was to use sed to find the commas replace with a hard return
sed 's/,/&\n/' data.frame
I am really not sure how to include the values for columns 1-3. I had low hopes of this working, but the only thing I could think of was to try inserting the column values with {print $1, $2, $3}.
sed 's/,/&\n{print $1, $2, $3}/' data.frame
Not to my surprise, the output looked like this:
A1 A2 A3 A4
{print $1, $2, $3} A5
{print $1, $2, $3} A6
B1 B2 B3 B4
{print $1, $2, $3} B5
{print $1, $2, $3} B6
C1 C2 C3 C4
{print $1, $2, $3} C5
{print $1, $2, $3} C6
It seems like an approach might be to store the values of columns 1-3 and then insert them. I am not really sure how to store the values, I think that it may involve using an adaptation of the following script, but I am having a hard time understanding all of the components.
NR==FNR{a[$1, $2, $3]=1}
Thanks in advance for your thoughts on this.
You can a write simple read loop for this and use brace expansion for parsing the comma delimited field:
#!/bin/bash
while read -r f1 f2 f3 c1; do
# split the comma delimited field 'c1' into its constituents
for c in ${c1//,/ }; do
printf "$f1 $f2 $f3 $c\n"
done
done < input.txt
Output:
A1 A2 A3 A4
A1 A2 A3 A5
A1 A2 A3 A6
B1 B2 B3 B4
B1 B2 B3 B5
B1 B2 B3 B6
C1 C2 C3 C4
C1 C2 C3 C5
C1 C2 C3 C6
As solution without calling an external program :
#!/bin/bash
data_file="d"
while IFS=" " read -r f1 f2 f3 r
do
IFS="," read f4 f5 f6 <<<"$r"
printf "$f1 $f2 $f3 $f4\n$f1 $f2 $f3 $f5\n$f1 $f2 $f3 $f6\n"
done <"$data_file"
In the great Miller there is the nest verb to do it
With
mlr --nidx --ifs "\t" nest --explode --values --across-records -f 4 --nested-fs "," input.tsv
you will have
A1 A2 A3 A4
A1 A2 A3 A5
A1 A2 A3 A6
B1 B2 B3 B4
B1 B2 B3 B5
B1 B2 B3 B6
C1 C2 C3 C4
C1 C2 C3 C5
C1 C2 C3 C6
If you don't need the output to be in any particular order within a group of the fourth column, the following awk one-liner might do:
awk '{split($4,a,","); for(i in a) print $1,$2,$3,a[i]}' input.txt
This works by splitting your 4th column into an array, then for each element of the array, printing the "new" four columns.
If order is important -- that is, A4 must come before A5, etc, then you can use a classic for loop:
awk '{split($4,a,","); for(i=1;i<=length(a);i++) print $1,$2,$3,a[i]}' input.txt
But that's awk. And you're asking about bash.
The following might work:
#!/usr/bin/env bash
mapfile -t arr < input.txt
for s in "${arr[#]}"; do
t=($s)
mapfile -t -d, u <<<"${t[3]}"
for v in "${u[#]}"; do
printf '%s %s %s %s\n' "${t[#]:0:3}" "${v%$'\n'}"
done
done
This copies your entire input file into the elements of an array, and then steps through that array, mapping each 4th-column into a second array. It then steps through that second array, printing the first three columns from the first array, along with the current field from the second array.
It's obviously similar in structure to the awk alternative, but much more cumbersome to read and code.
Note the ${v%$'\n'} on the printf line. This strips off the last field's trailing newline, which doesn't get stripped by mapfile because we're using an alternate delimiter.
Note also that there's no reason you have to copy all your input into an array, I just did it that way to demonstrate a little more of mapfile. You could of course use the old standard,
while read s; do
...
done < input.txt
if you prefer.

Including lagged independent variables - R

I would like to run a regression where I use both the current value and lagged values from a specific independent variable.
My dataset
This is an example extract from my dataset:
dt nrOfCalls nrOfOrders nrOfOrdersLag1 nrOfOrdersLag2 nrOfOrdersLag3
2016/04/20 17 5 9 7 12
2016/04/21 12 8 5 9 7
2016/04/22 14 4 8 5 9
2016/04/23 15 6 4 8 5
2016/04/24 20 14 6 4 8
2016/04/25 10 3 14 6 4
Where NrOfOrdersLagX implies the number of orders X days ago. I have also included dummy variables (because of limited space I have included these dummy variables in the example extract of my dataset).
My code
When I run the following code everything works perfectly fine:
reg <- lm(nrOfCalls ~ dummy1+...+dummy6+nrOfOrders, data=trainingSet)
However, when I try including the lagged values of the nrOfOrders regressor (for this example I only include one lagged value), I get some inordinary results. I use the following code:
reg <- lm(nrOfCalls ~ dummy1+...+dummy6+nrOfOrders+nrOfOrdersLag1, data=trainingSet)
Instead of merely including the regressor nrOfOrdersLag1, it will include all kinds of regressors which variable names are a variation on nrOfOrdersLag1.
Call:
lm(formula = nrOfCalls ~ dummy1 + dummy2 + dummy3 + dummy4 +
dummy5 + dummy6 + nrOfOrders + nrOfOrdersLag1, data = trainCall)
Coefficients:
(Intercept) dummy1 dummy2 dummy3 dummy4
604.06334 -114.03241 -229.67540 -270.62292 -220.12409
dummy5 dummy6 nrOfOrders nrOfOrdersLag110707 nrOfOrdersLag11161
-457.22245 -465.17116 0.01729 -249.54641 -10.98526
nrOfOrdersLag111869 nrOfOrdersLag11207 nrOfOrdersLag11234 nrOfOrdersLag11262 nrOfOrdersLag11267
45.36821 33.46161 -17.70615 -384.09745 -413.64804
nrOfOrdersLag11279 nrOfOrdersLag11285 nrOfOrdersLag112945 nrOfOrdersLag11336 nrOfOrdersLag11348
-200.19660 32.75546 -264.04005 -47.13457 79.48368
nrOfOrdersLag11351 nrOfOrdersLag11355 nrOfOrdersLag11363 nrOfOrdersLag11364 nrOfOrdersLag11368
-208.62312 6.83426 -98.71679 170.29583 -93.83054
nrOfOrdersLag11375 nrOfOrdersLag11398 nrOfOrdersLag11456 nrOfOrdersLag11462 nrOfOrdersLag11464
50.54960 14.39958 118.73762 113.72744 190.54445
nrOfOrdersLag11469 nrOfOrdersLag114778 nrOfOrdersLag11486 nrOfOrdersLag11489 nrOfOrdersLag11504
-8.79258 84.35041 66.29121 29.67360 24.30553
nrOfOrdersLag11505 nrOfOrdersLag11511 nrOfOrdersLag11520 nrOfOrdersLag11521 nrOfOrdersLag11527
286.85352 69.76762 -159.45588 -38.90402 53.62128
nrOfOrdersLag11538 nrOfOrdersLag11540 nrOfOrdersLag11564 nrOfOrdersLag115674 nrOfOrdersLag11579
-104.66037 -60.10656 -58.32177 522.56810 77.65481
nrOfOrdersLag11587 nrOfOrdersLag11593 nrOfOrdersLag11603 nrOfOrdersLag11618 nrOfOrdersLag11622
34.63649 31.28570 -124.35673 16.43115 207.99435
nrOfOrdersLag11624 nrOfOrdersLag11626 nrOfOrdersLag11629 nrOfOrdersLag11631 nrOfOrdersLag11635
93.90391 78.94275 155.88327 15.32027 125.02409
nrOfOrdersLag11640 nrOfOrdersLag11645 nrOfOrdersLag11649 nrOfOrdersLag11651 nrOfOrdersLag11653
208.51996 -42.03086 -1.62533 164.73045 12.61157
nrOfOrdersLag11654 nrOfOrdersLag11673 nrOfOrdersLag11683 nrOfOrdersLag11688 nrOfOrdersLag11698
129.26306 -41.56615 137.09095 149.86866 -49.43096
nrOfOrdersLag11699 nrOfOrdersLag11702 nrOfOrdersLag11703 nrOfOrdersLag11705 nrOfOrdersLag11714
76.86530 202.69027 -70.26281 -173.43605 170.02302
nrOfOrdersLag11715 nrOfOrdersLag11716 nrOfOrdersLag11726 nrOfOrdersLag11749 nrOfOrdersLag11754
34.30252 75.45378 176.16211 76.39492 58.11995
nrOfOrdersLag11757 nrOfOrdersLag11764 nrOfOrdersLag11766 nrOfOrdersLag11772 nrOfOrdersLag11777
133.71731 137.62373 24.95059 -75.96096 54.03353
nrOfOrdersLag11778 nrOfOrdersLag11782 nrOfOrdersLag11793 nrOfOrdersLag11806 nrOfOrdersLag11810
-147.40657 -45.70752 27.76710 94.17449 -191.98461
nrOfOrdersLag11811 nrOfOrdersLag11812 nrOfOrdersLag11814 nrOfOrdersLag11815 nrOfOrdersLag11817
61.04646 145.25908 38.56959 18.22574 140.84081
nrOfOrdersLag11827 nrOfOrdersLag11832 nrOfOrdersLag11839 nrOfOrdersLag11841 nrOfOrdersLag11859
-254.56931 138.30797 -139.32523 -151.50010 39.27760
nrOfOrdersLag11860 nrOfOrdersLag11862 nrOfOrdersLag11868 nrOfOrdersLag11874 nrOfOrdersLag11876
304.88804 150.84361 30.75749 -91.55666 192.43385
nrOfOrdersLag11879 nrOfOrdersLag11880 nrOfOrdersLag11885 nrOfOrdersLag11887 nrOfOrdersLag11891
118.75260 -44.83615 163.35474 194.12038 127.79107
nrOfOrdersLag11896 nrOfOrdersLag11901 nrOfOrdersLag11914 nrOfOrdersLag11919 nrOfOrdersLag11921
82.79870 179.44324 303.18796 242.51540 159.40652
nrOfOrdersLag11928 nrOfOrdersLag11929 nrOfOrdersLag11932 nrOfOrdersLag11937 nrOfOrdersLag11939
484.73958 35.38640 286.54643 46.88513 48.94031
nrOfOrdersLag11952 nrOfOrdersLag11967 nrOfOrdersLag11988 nrOfOrdersLag11994 nrOfOrdersLag11996
265.02228 170.65576 47.77627 317.10968 383.09702
nrOfOrdersLag119987 nrOfOrdersLag12007 nrOfOrdersLag12010 nrOfOrdersLag12017 nrOfOrdersLag12018
416.71786 93.41540 61.71721 73.68938 136.60641
nrOfOrdersLag12019 nrOfOrdersLag12023 nrOfOrdersLag12027 nrOfOrdersLag12034 nrOfOrdersLag12040
88.13672 -214.93168 38.82154 148.72993 -60.63852
nrOfOrdersLag12050 nrOfOrdersLag12051 nrOfOrdersLag12056 nrOfOrdersLag12058 nrOfOrdersLag12060
205.21811 246.46001 163.20151 -0.35863 61.93024
nrOfOrdersLag12073 nrOfOrdersLag12082 nrOfOrdersLag12087 nrOfOrdersLag12093 nrOfOrdersLag12107
122.50936 -27.13307 -43.74262 366.51938 146.85581
nrOfOrdersLag12119 nrOfOrdersLag12122 nrOfOrdersLag12124 nrOfOrdersLag121319 nrOfOrdersLag12133
119.31341 36.35183 253.68015 115.01838 228.66567
nrOfOrdersLag12136 nrOfOrdersLag12137 nrOfOrdersLag12154 nrOfOrdersLag12167 nrOfOrdersLag12169
-9.97711 121.20416 -448.43096 324.45466 169.37446
nrOfOrdersLag12176 nrOfOrdersLag12180 nrOfOrdersLag12181 nrOfOrdersLag12184 nrOfOrdersLag12186
88.35432 -14.74399 41.03555 310.68640 308.82549
nrOfOrdersLag12189 nrOfOrdersLag12195 nrOfOrdersLag12202 nrOfOrdersLag12204 nrOfOrdersLag12216
121.87542 264.78895 191.52156 281.02113 168.29821
nrOfOrdersLag12219 nrOfOrdersLag12221 nrOfOrdersLag12231 nrOfOrdersLag12236 nrOfOrdersLag12237
218.48030 66.07233 -228.54230 111.06068 162.65347
nrOfOrdersLag12242 nrOfOrdersLag12244 nrOfOrdersLag12246 nrOfOrdersLag12261 nrOfOrdersLag12262
12.05505 114.60872 -123.06406 -45.54485 380.26022
nrOfOrdersLag12268 nrOfOrdersLag12271 nrOfOrdersLag12302 nrOfOrdersLag12304 nrOfOrdersLag12311
4.23556 249.55941 248.38079 103.12194 -71.69000
nrOfOrdersLag12313 nrOfOrdersLag12329 nrOfOrdersLag12345 nrOfOrdersLag12353 nrOfOrdersLag12356
247.93662 207.13958 314.96154 95.08688 300.10247
nrOfOrdersLag12361 nrOfOrdersLag12371 nrOfOrdersLag12376 nrOfOrdersLag12380 nrOfOrdersLag12384
37.27506 -167.84137 66.61313 247.32681 237.73556
nrOfOrdersLag12399 nrOfOrdersLag12406 nrOfOrdersLag12413 nrOfOrdersLag12417 nrOfOrdersLag12420
107.37362 399.28658 275.48695 95.07723 324.87029
nrOfOrdersLag12423 nrOfOrdersLag12434 nrOfOrdersLag12437 nrOfOrdersLag12442 nrOfOrdersLag12446
233.30480 193.45613 250.79606 322.78975 320.40151
nrOfOrdersLag12448 nrOfOrdersLag12449 nrOfOrdersLag12451 nrOfOrdersLag12460 nrOfOrdersLag124708
172.20478 -113.45790 108.52769 305.32173 -134.41931
nrOfOrdersLag12484 nrOfOrdersLag12486 nrOfOrdersLag12493 nrOfOrdersLag12497 nrOfOrdersLag12505
156.35931 -9.49808 223.13247 -67.47891 534.66815
nrOfOrdersLag12541 nrOfOrdersLag12552 nrOfOrdersLag12563 nrOfOrdersLag12588 nrOfOrdersLag12596
221.35464 1.92188 -53.40846 -473.89923 497.69016
nrOfOrdersLag12611 nrOfOrdersLag12618 nrOfOrdersLag12623 nrOfOrdersLag12632 nrOfOrdersLag12638
175.77150 125.22040 -302.58298 -159.54109 -337.04664
nrOfOrdersLag12646 nrOfOrdersLag12648 nrOfOrdersLag12663 nrOfOrdersLag12665 nrOfOrdersLag12687
539.15416 350.53169 -148.22458 147.67351 -349.52567
nrOfOrdersLag12696 nrOfOrdersLag12713 nrOfOrdersLag12721 nrOfOrdersLag12723 nrOfOrdersLag12743
-42.64843 141.90979 47.07766 -443.50878 356.28944
nrOfOrdersLag12745 nrOfOrdersLag12750 nrOfOrdersLag12753 nrOfOrdersLag12761 nrOfOrdersLag127688
14.65720 13.35666 8.30924 -191.17540 -123.52409
nrOfOrdersLag12802 nrOfOrdersLag12806 nrOfOrdersLag12812 nrOfOrdersLag12815 nrOfOrdersLag12818
128.14604 281.35157 361.79299 8.34690 86.67458
nrOfOrdersLag12824 nrOfOrdersLag12836 nrOfOrdersLag12841 nrOfOrdersLag12842 nrOfOrdersLag12876
518.23720 -357.78788 288.63660 433.15556 158.51341
nrOfOrdersLag12883 nrOfOrdersLag12884 nrOfOrdersLag12901 nrOfOrdersLag12941 nrOfOrdersLag12956
214.74913 68.99485 -208.43888 -297.43011 319.30849
nrOfOrdersLag12996 nrOfOrdersLag13007 nrOfOrdersLag13013 nrOfOrdersLag13023 nrOfOrdersLag13033
321.02569 -88.96746 80.93579 106.97804 -223.88599
nrOfOrdersLag13051 nrOfOrdersLag13072 nrOfOrdersLag13094 nrOfOrdersLag13098 nrOfOrdersLag13127
40.95339 161.48086 524.04025 -94.23016 17.50082
nrOfOrdersLag13152 nrOfOrdersLag13171 nrOfOrdersLag13185 nrOfOrdersLag13202 nrOfOrdersLag13205
-266.11135 8.82232 -107.11441 -141.14442 212.80057
nrOfOrdersLag13222 nrOfOrdersLag13277 nrOfOrdersLag13295 nrOfOrdersLag13321 nrOfOrdersLag13332
187.90431 306.69183 -24.55235 68.42339 -290.11682
nrOfOrdersLag13362 nrOfOrdersLag13378 nrOfOrdersLag13380 nrOfOrdersLag13391 nrOfOrdersLag13476
44.30976 463.85118 276.57882 -282.06457 34.35207
nrOfOrdersLag13488 nrOfOrdersLag13490 nrOfOrdersLag13530 nrOfOrdersLag13578 nrOfOrdersLag13599
217.46608 386.26006 194.69082 52.45357 406.44931
nrOfOrdersLag13611 nrOfOrdersLag13618 nrOfOrdersLag13626 nrOfOrdersLag13632 nrOfOrdersLag13635
242.81201 -22.19253 23.90163 -395.87751 103.44677
nrOfOrdersLag13674 nrOfOrdersLag13681 nrOfOrdersLag13767 nrOfOrdersLag13841 nrOfOrdersLag13849
200.18354 83.25027 -71.88190 382.05886 -279.73606
nrOfOrdersLag13857 nrOfOrdersLag13874 nrOfOrdersLag13885 nrOfOrdersLag13897 nrOfOrdersLag13908
370.92867 -17.14313 -140.99009 -244.17716 93.79552
nrOfOrdersLag13966 nrOfOrdersLag14009 nrOfOrdersLag14031 nrOfOrdersLag14111 nrOfOrdersLag14160
61.75484 224.96558 -107.99394 -126.12766 572.14222
nrOfOrdersLag14171 nrOfOrdersLag14205 nrOfOrdersLag14312 nrOfOrdersLag14468 nrOfOrdersLag14560
-42.29929 -379.41067 194.25204 -47.50642 -116.49251
nrOfOrdersLag14619 nrOfOrdersLag14640 nrOfOrdersLag14684 nrOfOrdersLag14762 nrOfOrdersLag14776
41.34325 -355.84333 -122.77109 -331.12296 404.86637
nrOfOrdersLag14865 nrOfOrdersLag14959 nrOfOrdersLag14967 nrOfOrdersLag15195 nrOfOrdersLag15218
371.14617 104.60840 -42.74014 99.78008 520.62517
nrOfOrdersLag15402 nrOfOrdersLag16029 nrOfOrdersLag16284 nrOfOrdersLag16321 nrOfOrdersLag16350
529.17004 161.02870 268.77256 74.02159 386.53868
nrOfOrdersLag16418 nrOfOrdersLag16557 nrOfOrdersLag16711 nrOfOrdersLag16722 nrOfOrdersLag16825
-81.37023 190.74905 225.64313 -131.70051 271.39936
nrOfOrdersLag16952 nrOfOrdersLag16996 nrOfOrdersLag17098 nrOfOrdersLag17251 nrOfOrdersLag17279
357.39158 408.46849 210.03477 -25.74894 NA
nrOfOrdersLag17292 nrOfOrdersLag17391 nrOfOrdersLag18642 nrOfOrdersLag18670 nrOfOrdersLag18949
262.00528 4.71906 326.28857 49.30983 174.99732
nrOfOrdersLag19202 nrOfOrdersLag19690 nrOfOrdersLag19772
16.13322 15.59552 -62.26111
I have no clue what is happening and why this is going wrong. Anybody that can help me out here? Thanks in advance!
The lagged independent variables were factor variables instead of integer/numeric variables. Having fixed this, the lm call works as intended.

Does the basis of column space of a square matrix remains the same after squaring i.e is c(A)=c(AxA)?

Well I'm working on matrices, and this thing is bugging me , though according to me it should be true because:
let there be a nxn matrix:(aij ; i=row number, j=column number)
a11 a12 a13.....a1n
a21 a22 a23......
a31 a32 a33......
. . . ......
. . . ......
an1 an2 an3......
then A^2 will be:
1 column 1 column 2
a11*a11+a12*a21+a13*a31....+a1n*an1|a11*a12+a12*a22+a13*a32....+a1n*an2|
a21*a11+a22*a21+a23*a31....+an2*an1|a21*a12+a22*a22+a23*a32....+an2*an2|
. |. |
. |. |
. |. |
an1*a11+an2*a21+an3*a31....+ann*an1|an1*a12+an2*a22+an3*a32....+ann*an2|
so if we take the row elements to be constants x,y,z,.....
then all the columns are essentially x*column1+y*column2............
What do you all think?
No. Consider the matrix [0,1;0,0] (using matlab notation). Its square is [0,0;0,0]. That doesn't have the same column space.

Resources