Bladeren bron

add two-state model

strongway 5 maanden geleden
bovenliggende
commit
e1b29d7735

File diff suppressed because it is too large
+ 4945 - 1748
analysis-notebook.ipynb


+ 0 - 117
data/arx_v.csv

@@ -1,117 +0,0 @@
-sub,Volatility,group,Intercept,CTI,preErr,p_Intercept,p_CTI,p_preErr,r2,sequence,aic
-A31,High Vola.,ASD,-0.1636260720515039,0.4485224319912138,0.02267592408234776,5.643183347748399e-16,6.771624821062973e-26,0.6684554604295787,0.3844330385828979,31.0,17.776498382325315
-A31,Low Vola.,ASD,-0.10218809237514949,0.22326622574396415,0.522758690842801,1.3108914741665312e-07,3.0482280141717553e-07,3.196388925400576e-17,0.5910267907291533,31.0,-75.86969096872241
-A33,High Vola.,ASD,-0.05461602512957113,0.24397159621097486,0.009412266964022028,3.5569954227961165e-05,2.8372755154495363e-12,0.8731748871635254,0.18931649097910952,33.0,-107.55634331515569
-A33,Low Vola.,ASD,-0.03255699134999322,0.06755747060938369,-0.002898183522044155,0.002004785052565156,0.014240003477907364,0.9631010027182318,0.025517836661714588,33.0,-207.87865998006976
-A34,High Vola.,ASD,-0.02578538594133569,0.5146889415137618,-0.13064464268654952,0.004590109364508344,7.936835243503047e-51,0.001516159000523315,0.6350146585860621,34.0,-264.8038593367695
-A34,Low Vola.,ASD,-0.010153890455653635,0.14845994955957106,0.24643623448798252,0.34958963933195486,9.269358845916346e-06,7.720025573986404e-05,0.18613376937898696,34.0,-175.70395953235914
-A36,High Vola.,ASD,0.014731446448256563,0.1435456635804631,0.08775944302428886,0.5394665758854196,0.006476222322553425,0.19102806114674817,0.04428809582188431,36.0,171.71912238951
-A36,Low Vola.,ASD,0.041862423283285155,0.23651102076482447,0.21389504762302303,0.08168914861061881,2.185953779060046e-05,0.0013372733245813062,0.17314302731806586,36.0,167.86686610512993
-A37,High Vola.,ASD,0.09162193051190788,0.2834625244771001,0.00442976069701978,4.393486334425022e-09,4.2069523423343306e-13,0.9416218778419272,0.20824776992431326,37.0,-54.58527263259532
-A37,Low Vola.,ASD,0.06370068676966169,0.12606579900653403,0.18982397529832182,1.5226653254374147e-06,0.00011549456645900031,0.0032828978952987894,0.12547259209593753,37.0,-127.04657691180506
-C33,High Vola.,TD,0.018955005406609736,0.2022236357009768,-0.051431218015480486,0.027435932329382903,1.1820329014007027e-16,0.36956857093127526,0.25760599585544774,33.0,-292.23100349193
-C33,Low Vola.,TD,-0.01536659809324257,0.08188278055455188,0.09783079734044839,0.05073982597180892,0.00015414322623639933,0.12890316485502235,0.08115210273393991,33.0,-333.29249128659103
-C34,High Vola.,TD,0.07398806428643265,0.4325160876472684,0.007729881101008071,5.85322163161728e-07,4.390304652368354e-22,0.8837029701942037,0.33013771316627405,34.0,-57.091354329818216
-C34,Low Vola.,TD,0.13247578485527017,0.04861377064700744,0.16644201563446392,1.5136493338074298e-15,0.16684849231488716,0.008796892446623714,0.03995133666753614,34.0,-122.35081100561996
-C36,High Vola.,TD,-0.058175435452518694,0.33415807339852405,-0.13654445612204624,4.1070570280239215e-06,3.953428960175924e-28,0.007870734060773169,0.4097797204159317,36.0,-125.16496944179556
-C36,Low Vola.,TD,-0.026605000229549633,0.17004147699675906,0.20948021333875252,0.008393673247956228,1.1979341030810306e-10,0.0010537377256638928,0.32475114565313135,36.0,-221.4173536892685
-C37,High Vola.,TD,0.11774014092656433,0.17689445089121614,0.2231123500348675,5.307883745650459e-09,5.64689730794965e-05,0.0003260589853711634,0.11192196203324623,37.0,34.43670352762621
-C37,Low Vola.,TD,0.12347785686076401,-0.006048437493706503,0.3122562010013119,9.389217444350507e-12,0.8541202604852834,8.088261702743881e-07,0.09899102500328905,37.0,-98.0076337726959
-ara27,High Vola.,ASD,0.07219142662654182,0.11779895809540702,-0.006780246811204843,7.3268673617742895e-06,0.0030104883003992324,0.91564669222547,0.03659882101510048,27.0,-17.39988909689663
-ara27,Low Vola.,ASD,0.08543794975761719,-0.04679962333478706,0.10092203539634838,6.762791259033084e-08,0.20495589987264923,0.1132380491630388,0.018736028882605504,27.0,-48.730448121853385
-ara29,High Vola.,ASD,-0.02441612435884697,0.3291267680057361,-0.005594467250589964,0.06824627985719092,4.828084553268933e-21,0.9190289535131004,0.317031070761411,29.0,-78.01508754424037
-ara29,Low Vola.,ASD,0.06095867715216052,-0.0706292912482655,0.12488577699171932,3.8062741468439536e-08,0.004024704707987095,0.05481080923202136,0.0586963089888376,29.0,-212.26813987692458
-arc17,High Vola.,ASD,0.06080713259323861,-0.0073531506678730235,-0.07758704770360869,8.382565462209338e-08,0.8697758020034771,0.2234636279877569,0.006314150820637687,17.0,-200.98601995858093
-arc17,Low Vola.,ASD,0.15818837125878676,-0.22250559141698664,0.004673430975434545,3.015298463884902e-19,7.69575180011722e-05,0.9417086717542758,0.06983319093363383,17.0,-116.67482947094624
-arc21,High Vola.,ASD,0.06580218035627212,0.20768285790698507,0.10945699959732277,1.0397959688574304e-09,2.6736318085462345e-07,0.0800305459164769,0.1195811353622761,21.0,-240.52520541759503
-arc21,Low Vola.,ASD,0.04076613603584671,0.10639915149942233,0.2776401531296837,7.007908881747416e-05,0.00882847387212755,1.4297428273440233e-05,0.1236210602136224,21.0,-245.40776131713886
-ard07,High Vola.,ASD,0.07751478956101898,0.4195024964492992,-0.05975104047594887,2.830541222416066e-07,7.224824405463371e-12,0.32074729831599974,0.18020099161816294,7.0,-54.06010835811429
-ard07,Low Vola.,ASD,0.09170494905110693,0.015824672302819302,0.10624236021920108,3.937648811887781e-10,0.7600325203115247,0.10035899414806003,0.011901145670669577,7.0,-105.16942065443271
-are28,High Vola.,ASD,-0.08387337605544508,0.30919417215899303,0.0033921960520941104,2.012880395836989e-09,6.286854975863321e-19,0.9503927534937574,0.2863722862100543,28.0,-103.99216624271247
-are28,Low Vola.,ASD,-0.035022867487362865,0.21446821888964546,0.20957101131967074,0.0003479646606726549,5.313055281523938e-12,0.0015285477103873304,0.3867132039439555,28.0,-247.23069600635557
-arek04,High Vola.,ASD,0.0740932609431003,0.24897655967168933,0.02526861074520356,3.037702527405393e-09,5.596465050058993e-09,0.690636931959371,0.13381817106739102,4.0,-165.04056346210297
-arek04,Low Vola.,ASD,0.09251130841899258,0.039974515529447495,0.12007814353950257,1.2327261124818358e-15,0.19913412212229947,0.06713331185354762,0.022740837431732497,4.0,-299.07034752614027
-arj08,High Vola.,ASD,0.01983193757878396,0.06794287195997059,-0.09254537452366553,4.1330114373794566e-05,0.0007822944798702231,0.13796787152991022,0.05741987772623158,8.0,-583.1372699921149
-arj08,Low Vola.,ASD,0.003427310745697458,0.0503432658482941,0.19881259856660233,0.3983228475689108,0.005386645978182385,0.0014922846529295609,0.08907161999127156,8.0,-645.4710945124409
-arj19,High Vola.,ASD,0.1541243299215094,0.37334665574409853,-0.14076436915291546,2.6839079704519386e-17,2.29369989949282e-09,0.0178897857505793,0.1605732985318693,19.0,-10.088586871822656
-arj19,Low Vola.,ASD,0.12051372067260671,0.036742177461673936,0.1040206784221791,3.628545175335289e-14,0.4466824346647479,0.09608734952533722,0.014916888021068386,19.0,-117.86096735504185
-arjs01,High Vola.,ASD,0.03644628224469795,0.2595079928904515,-0.11096226077357746,0.003803240817189363,9.142231746569929e-06,0.08349803955485814,0.087738606355382,1.0,-109.96836135304017
-arjs01,Low Vola.,ASD,-0.008114412576098603,0.042735606429927984,0.01994099359641337,0.5039116087523507,0.4477017158859681,0.7578900430148613,0.0029432747391193725,1.0,-119.50686069181342
-ark09,High Vola.,ASD,0.055264423272441854,0.4229733715674244,-0.03584644202212572,3.4593731057487924e-11,2.9014843573363026e-28,0.46172518431649334,0.4019558198156802,9.0,-350.5933678560723
-ark09,Low Vola.,ASD,-0.008707221522620824,0.2530442234639373,0.09098569754404487,0.20430713258240565,1.0930162553359437e-11,0.1575025388638127,0.2633847436017923,9.0,-395.2427774959149
-ark11,High Vola.,ASD,0.044774083944122856,0.0013971531741124778,-0.010172502151479305,0.00023593418965240438,0.9760520896736262,0.8809320508947309,9.821589302572153e-05,11.0,-138.88757022589323
-ark11,Low Vola.,ASD,0.01962200329238898,0.0055351110800298114,-0.011831865627506242,0.1683584465104709,0.9214239512839865,0.8611012158440396,0.00016852329439898117,11.0,-47.059100994874655
-arl10,High Vola.,ASD,0.05811771771511162,0.476622964505967,0.12306429069240349,9.053551631823713e-05,8.709426953902144e-16,0.02893312683336422,0.2671863153586642,10.0,-47.13647570935717
-arl10,Low Vola.,ASD,0.03859613644189701,0.20209549079555278,0.04979091604795677,0.0010057906104429537,1.8848293894674584e-05,0.44747544180417886,0.09271714067802606,10.0,-154.02652675503822
-arm20,High Vola.,ASD,-0.028404248460278052,0.43798325768794677,-0.0991313122248752,0.02037444794165968,3.2407832612999395e-23,0.05957028947075933,0.35082713667006404,20.0,-120.23687824393443
-arm20,Low Vola.,ASD,-0.01960049600150255,0.11898560738611837,0.14075357575617664,0.0630699128617274,0.0006752911791122232,0.035475557367586424,0.08230919920359336,20.0,-196.81225888633583
-arm25,High Vola.,ASD,-0.02208367459059903,0.5342022992071701,-0.019195910202635547,0.0568982299327992,2.8666821318221e-24,0.7155446995210395,0.3564392183114642,25.0,-145.26465354153578
-arm25,Low Vola.,ASD,0.06077703614352044,-0.011888161970804135,0.1315520140105213,1.1339316912593784e-06,0.800208843070437,0.0416440349619487,0.017888536926087606,25.0,-152.44606195174106
-arm26,High Vola.,ASD,0.036904645637965,0.2149697990741385,0.055293965326029794,0.00018888952672712906,1.6672310590045359e-06,0.34649646256946787,0.09580837236189432,26.0,-240.16930481882292
-arm26,Low Vola.,ASD,0.05654619123240877,0.10543143176740338,0.13092890893954628,1.4218725905202287e-10,0.0024413752593429616,0.043005720050990216,0.062264432153819715,26.0,-359.60555582701227
-arnnew15,High Vola.,ASD,0.12093177510010432,0.13339809516475856,0.004041876303171904,1.9656295224343266e-11,0.02027778496914787,0.9494692317144813,0.022714481370090356,15.0,-12.200109412610402
-arnnew15,Low Vola.,ASD,0.09624365625192016,0.23897032993936124,-0.003241094668807832,7.763776142271405e-09,6.71787358151324e-05,0.9584801699697008,0.06784013028672142,15.0,-10.34950729330916
-arp23,High Vola.,ASD,0.17862284095665742,0.040575663576851696,0.039655392251379165,3.7510793222955235e-20,0.3975602047071737,0.5440559670301844,0.0046408158073278916,23.0,-86.76554258789116
-arp23,Low Vola.,ASD,0.14469705805853084,-0.17195408199896767,0.12569771995956833,1.0768541683511537e-15,0.0005158361050793948,0.053144155827812,0.08121650691211968,23.0,-86.79989930799974
-ars06,High Vola.,ASD,0.010155791093193835,0.3123480671258252,-0.06986376330452221,0.20790802267041728,4.988738656578609e-13,0.21648200241421486,0.20519381701857609,6.0,-315.41024041949595
-ars06,Low Vola.,ASD,0.032877920959560436,0.11445193908483764,-0.09612114657045501,0.0004426277926831698,0.014909616501907346,0.13785390444178547,0.030153703303823276,6.0,-261.03074014925875
-ars14,High Vola.,ASD,-0.14065216990865648,0.34025157980955517,-0.07826346084544367,8.438571143918126e-14,2.5508944607471274e-09,0.20209355049286953,0.14194930953976326,14.0,9.12618572727223
-ars14,Low Vola.,ASD,-0.11137150465122082,0.3798401888621049,0.013318646039922496,3.414059004529916e-14,5.709227745181217e-14,0.8369612625340657,0.271181250524547,14.0,-129.4905833351881
-arsn05,High Vola.,ASD,0.09726790223443815,0.30613110839348756,0.016472355977979296,2.4789291719980715e-15,5.266003700127983e-17,0.7748957174541329,0.25786401188685104,5.0,-211.84785236925052
-arsn05,Low Vola.,ASD,0.11622146697040645,0.02252888097069324,0.08845734828304012,1.2087531581081526e-16,0.5304230769399356,0.1547397194965576,0.010554125708249984,5.0,-180.56212216936171
-art12,High Vola.,ASD,0.1237235879228884,0.06585523284691705,0.006221680326570125,7.091851373067496e-16,0.13925220582011988,0.923796212631494,0.00947616373604443,12.0,-137.30199778548712
-art12,Low Vola.,ASD,0.11095702689600606,-0.024211496690589633,0.1817858829992351,2.0867927705594902e-14,0.5486447050689041,0.004329539644236443,0.03583452268966236,12.0,-181.9067476725121
-art16,High Vola.,ASD,-0.007724327598806427,0.21546073039000146,-0.06197537756508375,0.4065041182220308,1.769904423163741e-08,0.31633036663896,0.12944943273746568,16.0,-247.3504254183029
-art16,Low Vola.,ASD,0.03337339294745937,0.14309754285087978,0.09188882298000003,0.0006070429430725827,0.0002581867611896516,0.20592250804065776,0.07085215055729932,16.0,-243.75778454897244
-arv22,High Vola.,ASD,0.07735341229989676,0.25690751401318235,0.03697214375523539,2.599392379802637e-11,1.355675898234143e-09,0.5449998186954216,0.14410952571422275,22.0,-220.09345304629898
-arv22,Low Vola.,ASD,0.07420317157825182,-0.011864654313343423,-0.02390693159342061,7.788514660771696e-08,0.8175822160209358,0.7133760962425635,0.0007946879659508355,22.0,-104.52613249580696
-c31,High Vola.,TD,0.019224642109701377,0.12596328574423768,0.13500356707522565,0.04404896794815055,1.1344098145255786e-08,0.022955122337820384,0.15000516055311974,31.0,-244.0678368105045
-c31,Low Vola.,TD,0.04669055321462873,-0.04313702423808272,0.10651639776542714,1.9590293839018168e-05,0.06700422662997194,0.10248182909768748,0.029754246869931444,31.0,-207.48221011420338
-cra08,High Vola.,TD,0.04708933264646638,0.29290840809452734,-0.026088194085325964,2.7786413804939676e-05,1.991945390121498e-09,0.667738417106963,0.14287715094581643,8.0,-179.82887099495713
-cra08,Low Vola.,TD,0.026126642768255146,0.15380489556967405,-0.037254359560420815,0.001181811631072114,1.7278278440561606e-05,0.5699997053199815,0.07662430379268059,8.0,-330.4618804457614
-cra20,High Vola.,TD,0.035039399717327044,0.5334832184838312,0.0119976968169666,0.036884423496039175,1.8580800905501862e-19,0.8294983940862918,0.2955090600732744,20.0,28.36520563043632
-cra20,Low Vola.,TD,0.056753359156716934,-0.17536501242696384,0.2267050978547558,0.01688628421612869,0.022129723495821364,0.0004440947132992549,0.08397662687144758,20.0,173.89458027745508
-crc10,High Vola.,TD,0.06313228926882654,0.32239040433185895,0.33577702143147115,9.307115260222668e-08,1.508803647481331e-14,2.455594941791924e-09,0.30194971617390454,10.0,-205.72418264877564
-crc10,Low Vola.,TD,0.14651686443151343,0.08592022390507009,0.137964252152444,3.2734377153776625e-18,0.056854135184408,0.033006576272671,0.0373868094281824,10.0,-148.43616331425142
-crd19,High Vola.,TD,0.039856360974066286,0.2568680048443859,0.029240237367659967,4.385785021768721e-05,1.2372631941307366e-11,0.6189968466447845,0.17911729739265492,19.0,-248.86608834768754
-crd19,Low Vola.,TD,0.044804896036745784,0.026846028630323718,0.010715037000003515,7.769795733292314e-07,0.4166126210603387,0.8679403810153994,0.0029592737061576724,19.0,-298.94448544021134
-cre04,High Vola.,TD,0.08396629549720261,0.28840822932353094,0.040052697487123076,1.415886088749004e-06,2.5965054363224916e-06,0.5254568946685931,0.09137206896914607,4.0,12.35867853684158
-cre04,Low Vola.,TD,0.08857543840625172,0.1447890844560858,0.14230187612484982,9.265494684828708e-10,0.002119560662705553,0.027650784555972554,0.07121924414427505,4.0,-112.33152485366094
-cre05,High Vola.,TD,-0.018853243437023513,0.42888724066958583,0.09613051951747638,0.13364440659907095,1.713597931068841e-20,0.07941817372219705,0.3118942575587298,5.0,-105.4716212082912
-cre05,Low Vola.,TD,0.043033440410328895,0.005562962289152474,0.15847237485877974,0.00445348874543658,0.910010892391013,0.023040610187974903,0.02182075373196546,5.0,-29.521064494519635
-cre11,High Vola.,TD,-0.028303006195997366,0.4641110334198696,0.09566766171693439,0.0026434660101445876,5.269687461820348e-29,0.059854058965669955,0.42991814281946594,11.0,-250.74145517242948
-cre11,Low Vola.,TD,-0.06924229007552363,0.18180195847453703,0.3300515879238678,9.18876431239962e-11,6.370151954842244e-07,1.7376249134059954e-07,0.2985831188110807,11.0,-316.1381523668954
-crf27,High Vola.,TD,-0.03072573364949042,0.22464669467170556,-0.0502032034657388,0.0015828606306057206,1.4363268890062065e-16,0.3678535308578179,0.2507348147639551,27.0,-235.2513812049545
-crf27,Low Vola.,TD,-0.0331945494170303,0.12411710185849889,0.07431555625682541,0.0009293331377832643,4.992143314773659e-06,0.24303963805532613,0.11279541353977218,27.0,-230.20688752731564
-crj12,High Vola.,TD,0.14016340062585697,0.4180878866628422,-0.012048706493201122,2.1971515723858576e-20,2.381422702985692e-18,0.8276525949572324,0.2760753123314088,12.0,-141.0228978339465
-crj12,Low Vola.,TD,0.15162338438778467,0.04865469421048308,0.0033873708292149265,1.745325186459415e-21,0.2389834473560919,0.9562393597807319,0.005945976886958304,12.0,-172.2129970655804
-crj22,High Vola.,TD,0.06550853025056008,0.21445538434279332,0.03270513747579508,1.573077096250259e-07,1.2413751394828015e-05,0.6065995262346131,0.07912325232293504,22.0,-146.2609880017278
-crj22,Low Vola.,TD,0.042885398068122,0.16661930896640836,0.08562948351465284,9.517520612025455e-07,3.627738855722999e-06,0.17816121012134836,0.11983365115222744,22.0,-315.8236695155276
-crj23,High Vola.,TD,0.04026320337273456,0.33267238460660986,-0.0010515760976161446,6.131481736062675e-05,3.044190049060796e-18,0.9848642866793726,0.2744423966687869,23.0,-228.2237459224081
-crj23,Low Vola.,TD,0.012562074129221914,0.15904058217539527,0.3170530667466137,0.12398897492204342,1.523088599660967e-06,2.1184835898049398e-07,0.2710843520061489,23.0,-312.3492182063899
-crk21,High Vola.,TD,0.05072025108429428,0.02371549933168706,-0.011024791056087696,0.0007195217138918402,0.6959414078407202,0.8633024508154125,0.0007709038386601863,21.0,-32.63873469774131
-crk21,Low Vola.,TD,0.002929483030805588,0.15200786802813762,0.16087925271426615,0.7611473404838695,0.0003976340367913146,0.01081119529036618,0.10146027756627274,21.0,-229.48392139950687
-crl25,High Vola.,TD,0.011768685836116918,0.5896055198662754,-0.11454086538147007,0.3397818363845071,1.7643456098563444e-25,0.027363794706993787,0.3796401757442759,25.0,-112.9300615130793
-crl25,Low Vola.,TD,0.043413691625760864,0.07505843401682599,0.05223616976902557,0.0006355371094952851,0.14024786141528656,0.43232793177131223,0.013380461228984064,25.0,-117.52547956220991
-crl26,High Vola.,TD,0.08140313453488786,0.17034619502253281,0.15508070837019217,2.659649261125435e-06,7.83085319189209e-06,0.012132758649910468,0.11336230241019818,26.0,4.4303625483461815
-crl26,Low Vola.,TD,0.05845005839991678,0.03348247437845755,0.19519160857532072,6.315545163396346e-06,0.22615677329388567,0.001036003100549344,0.051407387869960575,26.0,-132.60182426358915
-crm07,High Vola.,TD,0.0447874581717078,0.30542365124139464,0.01789894956871694,2.5088401236465036e-07,3.993800330979792e-17,0.7414921356371146,0.2586722551741315,7.0,-310.6025613648965
-crm07,Low Vola.,TD,0.0412568690841571,0.17248339464664109,0.10616265717103995,7.358311638281642e-09,2.0152389855056138e-08,0.084609034243984,0.19207271825841388,7.0,-422.5419279120297
-crm16,High Vola.,TD,-0.08255191885067265,0.6222072885622131,0.029119526978998632,9.210850622651171e-11,1.542701367793074e-30,0.5475302394737167,0.4289299109324969,16.0,-146.273413123968
-crm16,Low Vola.,TD,-0.02676529980875586,-0.015969392935027898,0.32327697080443335,0.026775239184777404,0.7399545070328851,2.438671236224273e-07,0.10811002054141883,16.0,-135.2294015743277
-crmn29,High Vola.,TD,-0.04490211955417679,0.28170591427319114,-0.13789647019876958,2.565865363906311e-06,2.1920877189763752e-33,0.005401824332291873,0.47412300280095954,29.0,-257.57314164088683
-crmn29,Low Vola.,TD,0.01782925869146359,0.10286566300380179,0.004025731504420042,0.028478314518966416,5.063372573056754e-07,0.9503982240325818,0.10904578867145087,29.0,-317.77118203696364
-crn09,High Vola.,TD,-0.06199659182258668,0.5405434286025681,-0.026370926077060368,1.6139643428116947e-07,9.92408938657009e-23,0.6257049077430372,0.335014575683914,9.0,-167.32390381475665
-crn09,Low Vola.,TD,-0.030687703291489968,0.1447853100666647,0.2628311902142174,0.00033219809366437104,0.0001384728652237322,4.210068840089356e-05,0.15257883852856313,9.0,-313.54921302147454
-crn15,High Vola.,TD,0.029083663250644678,0.44730082463837934,0.00923572577905047,0.005215256042148905,1.0527730781463578e-24,0.8615305012039745,0.36772958516781284,15.0,-203.03489073256708
-crn15,Low Vola.,TD,0.03598088746992113,0.0991058946504293,0.1356915056802264,0.0007726813876239914,0.012854940469600314,0.03804639059469429,0.05360722313102828,15.0,-203.3171264813962
-crp14,High Vola.,TD,0.06484234741831628,0.6301266124341555,0.007344594653196937,7.251223645343384e-07,9.324593706210686e-35,0.8722860492329836,0.4752918264607543,14.0,-110.78931619934718
-crp14,Low Vola.,TD,-0.02973499501235844,0.18010199855108863,0.14825132602864458,0.00756142424119892,8.01727765221628e-06,0.018379197450837676,0.13146387776697654,14.0,-169.22476466866755
-crs06,High Vola.,TD,0.011880156074371255,0.4416987372995401,0.10845796505415228,0.1576079942395089,2.0776298183247516e-21,0.05318517346991562,0.322913235809422,6.0,-297.0452045856241
-crs06,Low Vola.,TD,0.009165480704601657,0.1622511258401341,0.4535950735219698,0.1651815104233781,1.7486593444340247e-05,5.5330093127446694e-14,0.36844343631303833,6.0,-413.58825978812604
-crs28,High Vola.,TD,0.006502165040361435,0.3577955604595286,-0.050109002723533524,0.6273936264371149,8.723447781741356e-22,0.3472242042015683,0.32222128085141033,28.0,-71.62397035590624
-crs28,Low Vola.,TD,0.08374907752863123,0.01813953808918116,0.07353017011070515,7.0348908946121125e-09,0.5640369517661132,0.27278860026150614,0.006644901656302493,28.0,-101.27278713117556
-crt17,High Vola.,TD,0.014987381470636635,0.3265492244419964,-0.035867686555865384,0.06620799102628958,1.811572259485956e-17,0.5175865066736822,0.26472137898492853,17.0,-314.3717106705683
-crt17,Low Vola.,TD,0.031782730012484384,-0.032064809563179315,0.07605193193201977,6.448164605581037e-05,0.32860633106152204,0.24409888267616214,0.010266596486961821,17.0,-348.70005127164313
-crv01,High Vola.,TD,0.009153200353798317,0.30174263673895296,0.2155706377682682,0.30562905180255406,4.797029923280041e-12,0.00023862461378270099,0.22504807069612187,1.0,-267.5420204045804
-crv01,Low Vola.,TD,0.008343401227858737,0.07613931721183068,0.2077018347713166,0.364143398319121,0.07543154676665159,0.0010553136355181487,0.061747894980397566,1.0,-254.0041404604744

BIN
figures/K2_vs_SQSE.pdf


BIN
figures/K2_vs_SQSE.png


BIN
figures/acf_rep_err.pdf


BIN
figures/acf_rep_err.png


BIN
figures/ar_dw.pdf


BIN
figures/ar_dw.png


BIN
figures/cti_boxplot.png


BIN
figures/cti_half.png


File diff suppressed because it is too large
+ 1799 - 0
figures/fig3_2state_model.ezdraw


BIN
figures/fig3_2state_model.png


BIN
figures/kmodel.png


BIN
figures/outliers.png


BIN
figures/rep_err_vs_Duration.png


BIN
figures/rep_err_vs_Duration_b.png


BIN
figures/rep_pred_err.pdf


BIN
figures/rep_pred_err.png


BIN
figures/sequential_effect.pdf


BIN
figures/sequential_effect.png


+ 171 - 0
kmodelY.py

@@ -0,0 +1,171 @@
+from scipy.optimize import least_squares
+from statsmodels.stats.stattools import durbin_watson
+import numpy as np
+
+def fitKmodel(subdata, nolog=None, pfit=None, p0=None):
+    """
+   Parameters:
+    - subdata : subject data
+    - nolog : If zero, logarithm is not used (default is 0)
+    - pfit : A list of logical values to indicate which parameters to fit (default is [True, True, True])
+    - p0 : Initial parameters (must always have length 3)
+    
+    Returns:
+    - px : Parameters of the model
+
+    By S.Glasauer 2019 (matlab), translated to Python by Strongway
+    # add AIC and DW
+
+    """
+    
+    # Handle default arguments
+    if p0 is None:
+        p0 = [1., 1, 0]
+    if pfit is None:
+        pfit = [True, True, True]
+    if nolog is None:
+        nolog = 0
+
+    # Convert pfit to logical and filter p0
+    pfit = np.array(pfit, dtype=bool)
+    p0 = np.array(p0)[pfit]
+
+    # Lower bounds (lb) for the optimization
+    lb = np.array([0, 0, -np.inf])[pfit]
+    
+
+    # extract Duration and Reproduction from subdata as 2d array
+    x = subdata['Duration'].values
+    y = subdata['Reproduction'].values
+    # replace extreme y with nan with y > 3 * x or y < x/3
+    y[(y > 3 * x) | (y < x/3)] = np.nan
+    # combine x,y as 2d array
+    stimrep = np.vstack([x,y]).T
+    # Perform the optimization using least_squares (equivalent to lsqnonlin in MATLAB)
+    result = least_squares(kmodelY,  p0, args = (stimrep, 1),
+                           bounds=(lb, np.inf), method='trf')
+    
+    # calculate kalmann filter parameters
+    q11 = result.x[0]
+    q22 = result.x[1]
+    r = 1
+    # calculate residual sum of squares
+    rss = np.sum(result.fun**2)
+    dw = durbin_watson(result.fun)
+    # number of parameters
+    k = len(result.x)
+    # number of observations
+    n = len(stimrep)
+    # calculate the log-likelihood
+    ll = -n/2*(np.log(2*np.pi) + np.log(rss/n) + 1)
+    # calculate the Akaike information criterion (AIC)
+    aic = 2*k - 2*ll
+    # steady state solution
+    p22 = (q22+np.sqrt(q22*q22+4*(q11+r)*q22))/2
+    K = np.array([p22 + q11, p22])/(p22+q11+r)
+    # return the optimized parameters, steady state solution, and AIC
+    return np.append(np.append(result.x, K), [aic, dw])  # Optimized parameters
+
+
+def kmodelY(par, stimrep, nolog=1, pfit=[1, 1, 1]):
+    """
+    Function to perform Kalman filter-based estimation.
+    
+    Parameters:
+    - par: Model parameters (if pfit = [1,1,1], then par = [q1/r, q2/r, cost-related parameter (0 for median)])
+    - stimrep: Stimulus representation
+    - nolog: Flag to decide if logarithm transformation is needed
+    - pfit: Parameter fitting list (note: len(par) = sum(pfit))
+    
+    Returns:
+    - sres: Stimulus residuals
+    - xest: Estimated state
+    - pest: Estimate error covariance
+    - resp: Response
+    - perr: Prediction error
+
+    S.Glasauer 2019/2023, translated to Python by Strongway
+    """
+
+    # Convert pfit to a boolean array
+    pfit = np.array(pfit, dtype=bool)
+
+    # Adjust pfit based on the size of par
+    if len(par) < 3:
+        pfit[len(par):] = False
+    
+    # Adjust stimrep's shape for further processing
+    if stimrep.shape[1] == 1:
+        stimrep = np.tile(stimrep, (1, 2))
+    # the first column is the stimulus, the second column is the response, 
+    # and add the third column to indicate the start of a new sequence
+    #if stimrep.shape[1] == 2:
+    #    stimrep = np.hstack((stimrep, np.zeros((stimrep.shape[0], 1))))
+    #    stimrep[0, 2] = 1
+    
+    # Initialize pars and overwrite with provided parameters based on pfit
+    pars = np.array([0.0, 0.0, 0.0])
+    pars[pfit] = par
+    par = pars
+
+    # Constants for the model
+    a = 10.0
+    off = 1.
+    r = 1.
+    q1 = par[0] * r
+    q2 = par[1] * r
+
+    # Define matrices Q, P, H, and F for the Kalman filter of two-state model
+    # details see Glasauer & Shi, 2022, Sci. Rep., https://doi.org/10.1038/s41598-022-14939-8
+    Q = np.array([[q1, 0], [0, q2]])
+    P = np.array([[r, 0], [0, r]])
+    H = np.array([[1., 0]])
+    F = np.array([[0, 1.], [0, 1.]])
+
+    # Apply logarithm transformation if nolog is false
+    if nolog:
+        z = stimrep[:, 0]
+    else: # log transformation
+        z = np.log(a * stimrep[:, 0] + off)
+
+    # Initialize state vector x
+    x = np.array([[z[0]], [z[0]]])
+
+    # Initialize matrices for storing results
+    xest = np.zeros((len(z), 2))
+    pest = np.zeros((len(z), 2))
+    perr = np.zeros(len(z))
+
+    # Kalman filter estimation loop
+    for i in range(len(z)):
+        
+        x = F@x
+        P = F@P@F.T + Q
+        K = P@H.T/(H@P@H.T + r)
+        perr[i] = z[i] - H@x
+        x = x + K*perr[i]
+        P = (np.eye(2) - K@H)@P
+
+        pest[i, :] = np.diag(P)
+        xest[i, :] = x.reshape(-1)
+
+    # Adjust for third parameter, if present
+    if len(par) == 3:
+        sh = par[2]
+    else:
+        sh = 0
+
+    # Compute response, adjusting for logarithm if needed
+    if nolog:
+        resp = xest[:, 0] + sh
+    else: # log transformation
+        resp = (np.exp(xest[:, 0] + sh) - off)/a 
+        
+
+    # Calculate stimulus residuals
+    sres = stimrep[:, 1] - resp
+
+    # Remove NaNs from sres
+    sres = sres[np.isfinite(sres)]
+
+    return sres