我有这个动物园系列。
> str(ALLXbm)
‘zoo’ series from 1998-01-01 to 2017-12-01
Data: num [1:240, 1:19] 0.00289 0.00992 -0.00424 0.07958 -0.035 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:19] "DE" "DB" "DM" "IE" ...
Index: Date[1:240], format: "1998-01-01" "1998-02-01" "1998-03-01" "1998-04-01" "1998-05-01" "1998-06-01" "1998-07-01" ...
以下是dput()结果。因变量是
> dput(ALLX$DE)
structure(c(" 0.0028923077", " 0.0099160000", "-0.0042440000",
" 0.0795800000", "-0.0350041667", "-0.2480500000", " 0.0042880000",
"-0.1620888889", " 0.0637518519", " 0.0928178571", "-0.0974379310",
"-0.1012612903", "-0.0141133333", " 0.0373500000", " 0.0420323529",
" 0.0406323529", "-0.0479314286", " 0.0393514286", " 0.0134594595",
"-0.0042162162", " 0.0282142857", "-0.0467717949", " 0.0271487179",
" 0.0484756757", " 0.0388105263", "-0.0232324324", "-0.1534487179",
"-0.0553538462", "-0.0127976190", " 0.0248613636", "-0.0069093023",
" 0.0016234043", "-0.0004617021", "-0.0747617021", " 0.0362914894",
" 0.0773816327", "-0.0038936170", " 0.0876829787", "-0.0198040000",
"-0.0078372549", " 0.0343978723", " 0.0350833333", "-0.0382480000",
" 0.0824346939", "-0.0280615385", "-0.0312228070", "-0.1020928571",
"-0.1011178571", " 0.0460186441", " 0.0407403509", "-0.0200607143",
" 0.1692310345", " 0.1254927273", "-0.0012947368", " 0.0410393443",
"-0.0060650000", " 0.1175457627", "-0.0219952381", " 0.0538709677",
" 0.1302564516", " 0.0177306452", " 0.0465440678", "-0.0318777778",
"-0.0027257576", "-0.0808714286", " 0.0753223881", " 0.0421338235",
" 0.0192617647", " 0.0645835821", " 0.0178743243", " 0.0917106667",
"-0.0504720000", "-0.0605917808", " 0.0670115942", " 0.0841644737",
"-0.0862937500", " 0.0583458333", " 0.0341283951", " 0.0363376623",
"-0.0072297619", " 0.0697188235", " 0.0708900000", " 0.0964263736",
" 0.0265102273", "-0.0310302326", " 0.0419810000", "-0.0719272727",
" 0.0243521739", "-0.0945943925", " 0.0339018868", " 0.0440350000",
" 0.0503681818", " 0.0629381356", "-0.0510975000", " 0.0249760684",
" 0.0827214876", " 0.0892224806", "-0.0168313043", " 0.0291585366",
" 0.0273647541", "-0.0975674242", "-0.0746062016", " 0.0238595238",
"-0.0278552000", "-0.0925223077", " 0.0659656934", " 0.0456731343",
" 0.0466132450", "-0.0135568493", " 0.0414873016", " 0.0340628205",
" 0.0267903846", "-0.0494906667", " 0.0180333333", " 0.0387062500",
"-0.0283124183", " 0.0306898810", " 0.0886619048", "-0.0198162921",
"-0.0154431818", "-0.0838285714", " 0.0658326531", "-0.0614076503",
" 0.0424984211", "-0.0170115000", " 0.0205202970", " 0.0596765258",
"-0.0538638298", "-0.0453000000", "-0.0493330317", " 0.0545885714",
" 0.1193183168", "-0.0335423810", " 0.0599138393", " 0.0207066964",
" 0.0554773756", " 0.0606587156", " 0.0448098039", "-0.0354082569",
" 0.0057316038", " 0.0019272727", " 0.0214976303", "-0.0108309179",
" 0.0166442211", " 0.0028019512", "-0.0548807910", " 0.0297556962",
"-0.0161016854", " 0.0100739726", " 0.0538203704", " 0.0304168724",
" 0.0246617647", " 0.0294436975", "-0.0192055300", "-0.0221397906",
" 0.0429194215", "-0.1356025974", " 0.0155836364", " 0.0421339806",
" 0.0193581152", "-0.0316510526", " 0.0171187192", " 0.0299633484",
" 0.0136308017", "-0.0803899225", "-0.0462198413", "-0.0337478469",
"-0.0044057018", " 0.0297085185", " 0.0273300000", "-0.0814074689",
" 0.0194720183", "-0.0640064885", " 0.0194782979", " 0.0047418868",
"-0.0393941634", " 0.0119372093", "-0.0092268116", "-0.0221629956",
" 0.0803489130", "-0.0976939502", "-0.0391824701", "-0.0672646154",
"-0.0124784247", "-0.1038085627", "-0.0105592476", "-0.0279538710",
" 0.0196077181", " 0.0338205788", "-0.0189602996", "-0.0860247273",
"-0.0478760714", "-0.0510344720", " 0.0275029586", " 0.0428622291",
" 0.0166286232", "-0.0288036101", "-0.0180476923", " 0.0393909483",
"-0.0641453901", "-0.0841982143", " 0.0047675900", "-0.0240106312",
"-0.0700313793", " 0.0733418994", "-0.0533325905", "-0.0331509589",
" 0.0489809399", "-0.0736352078", " 0.0240526646", "-0.0939243553",
"-0.0042405995", "-0.0387828042", "-0.0470409756", "-0.0931115294",
"-0.0910497738", " 0.0013111111", " 0.0348456633", " 0.0705459082",
" 0.0758425000", "-0.1478202222", " 0.0717040179", " 0.0569382114",
"-0.0945091623", " 0.1044561713", " 0.0293398396", "-0.1272769802",
" 0.0325193750", " 0.0277184066", "-0.0341782369", "-0.0250598160",
" 0.0189187500", "-0.0074535385", "-0.0359813953", " 0.0160150115",
" 0.0476877551", "-0.1018837398", "-0.0427113689", " 0.0191961637",
" 0.1059326403"), index = structure(c(883612800, 886291200, 888710400,
891388800, 893980800, 896659200, 899251200, 901929600, 904608000,
907200000, 909878400, 912470400, 915148800, 917827200, 920246400,
922924800, 925516800, 928195200, 930787200, 933465600, 936144000,
938736000, 941414400, 944006400, 946684800, 949363200, 951868800,
954547200, 957139200, 959817600, 962409600, 965088000, 967766400,
970358400, 973036800, 975628800, 978307200, 980985600, 983404800,
986083200, 988675200, 991353600, 993945600, 996624000, 999302400,
1001894400, 1004572800, 1007164800, 1009843200, 1012521600, 1014940800,
1017619200, 1020211200, 1022889600, 1025481600, 1028160000, 1030838400,
1033430400, 1036108800, 1038700800, 1041379200, 1044057600, 1046476800,
1049155200, 1051747200, 1054425600, 1057017600, 1059696000, 1062374400,
1064966400, 1067644800, 1070236800, 1072915200, 1075593600, 1078099200,
1080777600, 1083369600, 1086048000, 1088640000, 1091318400, 1093996800,
1096588800, 1099267200, 1101859200, 1104537600, 1107216000, 1109635200,
1112313600, 1114905600, 1117584000, 1120176000, 1122854400, 1125532800,
1128124800, 1130803200, 1133395200, 1136073600, 1138752000, 1141171200,
1143849600, 1146441600, 1149120000, 1151712000, 1154390400, 1157068800,
1159660800, 1162339200, 1164931200, 1167609600, 1170288000, 1172707200,
1175385600, 1177977600, 1180656000, 1183248000, 1185926400, 1188604800,
1191196800, 1193875200, 1196467200, 1199145600, 1201824000, 1204329600,
1207008000, 1209600000, 1212278400, 1214870400, 1217548800, 1220227200,
1222819200, 1225497600, 1228089600, 1230768000, 1233446400, 1235865600,
1238544000, 1241136000, 1243814400, 1246406400, 1249084800, 1251763200,
1254355200, 1257033600, 1259625600, 1262304000, 1264982400, 1267401600,
1270080000, 1272672000, 1275350400, 1277942400, 1280620800, 1283299200,
1285891200, 1288569600, 1291161600, 1293840000, 1296518400, 1298937600,
1301616000, 1304208000, 1306886400, 1309478400, 1312156800, 1314835200,
1317427200, 1320105600, 1322697600, 1325376000, 1328054400, 1330560000,
1333238400, 1335830400, 1338508800, 1341100800, 1343779200, 1346457600,
1349049600, 1351728000, 1354320000, 1356998400, 1359676800, 1362096000,
1364774400, 1367366400, 1370044800, 1372636800, 1375315200, 1377993600,
1380585600, 1383264000, 1385856000, 1388534400, 1391212800, 1393632000,
1396310400, 1398902400, 1401580800, 1404172800, 1406851200, 1409529600,
1412121600, 1414800000, 1417392000, 1420070400, 1422748800, 1425168000,
1427846400, 1430438400, 1433116800, 1435708800, 1438387200, 1441065600,
1443657600, 1446336000, 1448928000, 1451606400, 1454284800, 1456790400,
1459468800, 1462060800, 1464739200, 1467331200, 1470009600, 1472688000,
1475280000, 1477958400, 1480550400, 1483228800, 1485907200, 1488326400,
1491004800, 1493596800, 1496275200, 1498867200, 1501545600, 1504224000,
1506816000, 1509494400, 1512086400), tzone = "UTC", tclass = "Date"), class = c("xts",
"zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC", .Dim = c(240L,
1L), .Dimnames = list(NULL, "DE"))
和自变量dput()是
> dput(ALLX$SMB_L)
structure(c("-0.0465320170", "-0.0697526439", " 0.0273518415",
"-0.0740531793", " 0.0316742119", " 0.0152537452", "-0.0264616225",
" 0.0288440266", "-0.1158052743", "-0.1629207669", "-0.0321036909",
"-0.0155047450", "-0.0826901559", "-0.0958867805", "-0.1071221681",
"-0.0448685814", "-0.0246406184", "-0.1212194655", "-0.0753136163",
" 0.0410887618", "-0.0472807197", "-0.0821359482", "-0.0538328997",
"-0.1193170755", " 0.0451348940", "-0.0666430865", " 0.1030261973",
"-0.0512679603", "-0.0858501881", "-0.1100767741", " 0.2831559983",
" 0.0049661923", "-0.0466122487", "-0.0566777104", "-0.0268275721",
"-0.0592022576", " 0.0095647556", "-0.0369526728", "-0.0246719322",
" 0.0051186559", "-0.0462739541", "-0.1027257463", " 0.0041844398",
"-0.0443327227", " 0.0513661492", "-0.0672995604", "-0.0509956017",
"-0.0377391126", " 0.1208954628", " 0.0656631973", "-0.0109091553",
"-0.0319298318", " 0.0762361370", " 0.0082987739", " 0.0744911252",
" 0.0268991873", " 0.0106712270", "-0.0162705327", "-0.0030339799",
" 0.0437060161", "-0.0484248103", "-0.0131028206", "-0.0551732558",
"-0.0827144280", " 0.0412271313", "-0.0625801905", "-0.0531687861",
"-0.0194387563", " 0.0651252536", " 0.0185203178", " 0.0212495415",
"-0.0058409877", " 0.0005737324", " 0.0033661115", " 0.0166057656",
" 0.0273215778", "-0.0160116096", "-0.0516442850", " 0.0622634418",
" 0.0059385646", "-0.1501443652", " 0.0901923236", " 0.0033375512",
"-0.0753535560", " 0.0112127728", " 0.0174845326", " 0.0523481171",
"-0.0687008257", " 0.0364307873", " 0.0136230636", " 0.0058142113",
" 0.0554519027", " 0.0519022715", "-0.0570389442", "-0.0170328466",
" 0.0497557753", "-0.0022714909", " 0.0319902902", " 0.0567367912",
"-0.0807706219", " 0.0858961234", " 0.0222949488", " 0.0242892126",
" 0.0215915873", " 0.0537398523", "-0.0632469276", " 0.0111250970",
" 0.0532290206", "-0.0146115567", "-0.0497947429", "-0.0261614454",
"-0.0231347005", " 0.1003858901", " 0.0445487378", "-0.0150134676",
"-0.0457789040", "-0.0034933110", "-0.0668239816", "-0.0159024243",
"-0.0077140317", " 3.6823096028", "-0.0901045024", "-0.0143629036",
"-0.0098836289", "-0.0311347099", "-0.0151321886", "-0.0233462522",
"-0.0458991158", "-0.0282613742", "-0.0779876682", " 0.0117855889",
"-0.0893392649", "-0.0328418515", "-0.0090601777", "-0.0322611560",
"-0.0641631336", "-0.0595636188", " 0.0206379342", "-0.0891543562",
" 0.0717742257", "-0.0461537130", "-0.0954444539", "-0.0543154861",
"-0.0714790350", " 0.0474770475", "-0.0037168520", "-0.0077110744",
"-0.0355079545", " 0.0354765095", "-0.0152485350", "-0.0037694163",
" 0.0088693973", "-0.0013576659", "-0.0158975649", "-0.0569949742",
"-0.0047187899", " 0.0359832832", " 0.0048156392", "-0.0213823507",
"-0.0253481502", "-0.0305909946", "-0.0459944589", " 0.0697664274",
"-0.0053565569", " 0.0119311291", "-0.0068067904", "-0.0046527312",
"-0.0317481424", " 0.0322190631", " 0.0095508469", " 0.0009492415",
" 0.0109837401", " 0.0129883296", "-0.0230918819", " 0.0291994624",
" 0.0053826778", " 0.0116937939", " 0.7079728243", " 0.0103552944",
" 0.0016701093", " 0.0283116307", " 0.0367686262", " 0.0352952954",
" 0.0251452293", " 0.6522285618", " 0.0005676648", "-0.0355068478",
" 0.0383934967", "-0.0054156326", "-0.0288061771", " 0.0076047198",
"-0.0261335344", " 0.0587687305", " 0.0635220884", "-0.0035395762",
" 0.0638110053", "-0.0043276134", "-0.0183498085", "-0.0306437649",
"-0.0153833213", " 0.0165571651", "-0.0014514427", "-0.0111594992",
" 0.0061678879", "-0.0898811021", "-0.0106517096", " 0.0582380903",
" 0.0471135599", " 0.0946734825", " 0.0518059714", " 0.0075574758",
" 0.0078389969", " 0.0998944849", "-0.0259425031", "-0.0031939886",
"-0.0078991041", "-0.0583307843", "-0.0664592297", "-0.0428550515",
"-0.0282970576", " 0.0085063220", " 0.0027516516", "-0.0413816309",
"-0.0080472825", " 0.0001809490", "-0.0719654720", " 0.0250187336",
" 0.0017591069", "-0.0352040828", " 0.0032731177", "-0.0182234806",
"-0.0276918415", " 0.0246782744", " 0.0390556980", "-0.0240913343",
"-0.0207629243", " 0.0289632858", "-0.0398579730", " 0.0048926744",
"-0.0397687581"), index = structure(c(883612800, 886291200, 888710400,
891388800, 893980800, 896659200, 899251200, 901929600, 904608000,
907200000, 909878400, 912470400, 915148800, 917827200, 920246400,
922924800, 925516800, 928195200, 930787200, 933465600, 936144000,
938736000, 941414400, 944006400, 946684800, 949363200, 951868800,
954547200, 957139200, 959817600, 962409600, 965088000, 967766400,
970358400, 973036800, 975628800, 978307200, 980985600, 983404800,
986083200, 988675200, 991353600, 993945600, 996624000, 999302400,
1001894400, 1004572800, 1007164800, 1009843200, 1012521600, 1014940800,
1017619200, 1020211200, 1022889600, 1025481600, 1028160000, 1030838400,
1033430400, 1036108800, 1038700800, 1041379200, 1044057600, 1046476800,
1049155200, 1051747200, 1054425600, 1057017600, 1059696000, 1062374400,
1064966400, 1067644800, 1070236800, 1072915200, 1075593600, 1078099200,
1080777600, 1083369600, 1086048000, 1088640000, 1091318400, 1093996800,
1096588800, 1099267200, 1101859200, 1104537600, 1107216000, 1109635200,
1112313600, 1114905600, 1117584000, 1120176000, 1122854400, 1125532800,
1128124800, 1130803200, 1133395200, 1136073600, 1138752000, 1141171200,
1143849600, 1146441600, 1149120000, 1151712000, 1154390400, 1157068800,
1159660800, 1162339200, 1164931200, 1167609600, 1170288000, 1172707200,
1175385600, 1177977600, 1180656000, 1183248000, 1185926400, 1188604800,
1191196800, 1193875200, 1196467200, 1199145600, 1201824000, 1204329600,
1207008000, 1209600000, 1212278400, 1214870400, 1217548800, 1220227200,
1222819200, 1225497600, 1228089600, 1230768000, 1233446400, 1235865600,
1238544000, 1241136000, 1243814400, 1246406400, 1249084800, 1251763200,
1254355200, 1257033600, 1259625600, 1262304000, 1264982400, 1267401600,
1270080000, 1272672000, 1275350400, 1277942400, 1280620800, 1283299200,
1285891200, 1288569600, 1291161600, 1293840000, 1296518400, 1298937600,
1301616000, 1304208000, 1306886400, 1309478400, 1312156800, 1314835200,
1317427200, 1320105600, 1322697600, 1325376000, 1328054400, 1330560000,
1333238400, 1335830400, 1338508800, 1341100800, 1343779200, 1346457600,
1349049600, 1351728000, 1354320000, 1356998400, 1359676800, 1362096000,
1364774400, 1367366400, 1370044800, 1372636800, 1375315200, 1377993600,
1380585600, 1383264000, 1385856000, 1388534400, 1391212800, 1393632000,
1396310400, 1398902400, 1401580800, 1404172800, 1406851200, 1409529600,
1412121600, 1414800000, 1417392000, 1420070400, 1422748800, 1425168000,
1427846400, 1430438400, 1433116800, 1435708800, 1438387200, 1441065600,
1443657600, 1446336000, 1448928000, 1451606400, 1454284800, 1456790400,
1459468800, 1462060800, 1464739200, 1467331200, 1470009600, 1472688000,
1475280000, 1477958400, 1480550400, 1483228800, 1485907200, 1488326400,
1491004800, 1493596800, 1496275200, 1498867200, 1501545600, 1504224000,
1506816000, 1509494400, 1512086400), tzone = "UTC", tclass = "Date"), class = c("xts",
"zoo"), .indexCLASS = "Date", tclass = "Date", .indexTZ = "UTC", tzone = "UTC", .Dim = c(240L,
1L), .Dimnames = list(NULL, "SMB_L"))
我想要gmm滚动回归,然后设置下面的代码。
dogmm <- function(x) {gmm(ALLX$DE~ ALLX$SMB_L, x = ALLXbm)}
kk=rollapply(dogmm, ALLXbm,width=24, by.column = FALSE)
错误讯息是
Error in zoo(rval, index(x)[i]) :
“x” : attempt to define invalid zoo object
即使我花了很多时间,我也无法弄明白。当我单独尝试gmm代码时,它确实有效
gmm(ALLXbm$DE~ ALLXbm$SMB_L, x = ALLXbm)
。我在想,问题出在rollapply
代码中。对不起,这是我第一次尝试GMM。请帮帮忙?