statsmodels / statsmodels

Statsmodels: statistical modeling and econometrics in Python
http://www.statsmodels.org/devel/
BSD 3-Clause "New" or "Revised" License
10k stars 2.87k forks source link

Difference in local and deployed version of app using VAR from statsmodels.tsa.vector_ar.var_model #9340

Closed ejuliaschulz closed 3 weeks ago

ejuliaschulz commented 3 weeks ago

Describe the bug

I build and fit a VAR model to obtain the best model order based on the AIC criterion. When running this code locally (Windows 11 Pro, statsmodel version 0.14.2, python 3.11), my best model order is calculated as 8, with AIC of -599.87597. I use this code in a deployed app with streamlit, which seems to use Linux, and also Python 3.11, same module versions as I use locally. In this app, the exact same code (same module versions) produces a different output, the best model order changes to 9 with AIC of -600.3351. Here are two screenshots of the same code output, once in the deployed app (Linux?), and once in the local version of my app (Windows)

Deployed app image

Local app image

Code Sample, a copy-pastable example if possible

from statsmodels.tsa.vector_ar.var_model import VAR
import numpy as np
import pandas as pd

df = pd.DataFrame({'Variable 1': {'2014-02-01 00:00:00': 0.56, '2014-03-01 00:00:00': 0.56, '2014-04-01 00:00:00': 0.56, '2014-05-01 00:00:00': 0.56, '2014-06-01 00:00:00': 0.56, '2014-07-01 00:00:00': 0.56, '2014-08-01 00:00:00': 0.56, '2014-09-01 00:00:00': 0.56, '2014-10-01 00:00:00': 0.56, '2014-11-01 00:00:00': 0.5622405804992034, '2014-12-01 00:00:00': 0.5639382971491507, '2015-01-01 00:00:00': 0.5673876773197045, '2015-02-01 00:00:00': 0.5700568829892957, '2015-03-01 00:00:00': 0.5721369904866512, '2015-04-01 00:00:00': 0.5737669411810388, '2015-05-01 00:00:00': 0.5750496582196891, '2015-06-01 00:00:00': 0.5760625345224498, '2015-07-01 00:00:00': 0.5756424602322934, '2015-08-01 00:00:00': 0.5744974670957123, '2015-09-01 00:00:00': 0.5735874822657767, '2015-10-01 00:00:00': 0.5720558590821788, '2015-11-01 00:00:00': 0.5708356839624799, '2015-12-01 00:00:00': 0.5692592414961524, '2016-01-01 00:00:00': 0.5671976576424296, '2016-02-01 00:00:00': 0.5651503917621239, '2016-03-01 00:00:00': 0.562712946683977, '2016-04-01 00:00:00': 0.5615675880399065, '2016-05-01 00:00:00': 0.5606523000073893, '2016-06-01 00:00:00': 0.5603213278513066, '2016-07-01 00:00:00': 0.560256982625514, '2016-08-01 00:00:00': 0.5596049403490181, '2016-09-01 00:00:00': 0.5584830634367512, '2016-10-01 00:00:00': 0.5555846136385878, '2016-11-01 00:00:00': 0.5534666169589654, '2016-12-01 00:00:00': 0.551172362907164, '2017-01-01 00:00:00': 0.5483039274652103, '2017-02-01 00:00:00': 0.5459952666095429, '2017-03-01 00:00:00': 0.545364238228167, '2017-04-01 00:00:00': 0.5450207275070252, '2017-05-01 00:00:00': 0.5447632357790988, '2017-06-01 00:00:00': 0.5443097704025691, '2017-07-01 00:00:00': 0.5437569172905139, '2017-08-01 00:00:00': 0.5420997470512489, '2017-09-01 00:00:00': 0.5399143646574641, '2017-10-01 00:00:00': 0.5383202182911042, '2017-11-01 00:00:00': 0.5371102504716583, '2017-12-01 00:00:00': 0.5348746840588304, '2018-01-01 00:00:00': 0.5325060924257059, '2018-02-01 00:00:00': 0.5310115652773095, '2018-03-01 00:00:00': 0.5302256810053324, '2018-04-01 00:00:00': 0.5289805305871615, '2018-05-01 00:00:00': 0.5277844135439355, '2018-06-01 00:00:00': 0.5262275194581321, '2018-07-01 00:00:00': 0.5253820106236555, '2018-08-01 00:00:00': 0.5263056128184319, '2018-09-01 00:00:00': 0.5268444922709329, '2018-10-01 00:00:00': 0.5256755903180412, '2018-11-01 00:00:00': 0.5245404695363587, '2018-12-01 00:00:00': 0.523832374272646, '2019-01-01 00:00:00': 0.5234658988564947, '2019-02-01 00:00:00': 0.5228127182843988, '2019-03-01 00:00:00': 0.5219301737619219, '2019-04-01 00:00:00': 0.5208641381730857, '2019-05-01 00:00:00': 0.5196513097771639, '2019-06-01 00:00:00': 0.5183210471537155, '2019-07-01 00:00:00': 0.5162568368937079, '2019-08-01 00:00:00': 0.5140054687914045, '2019-09-01 00:00:00': 0.5124043746214663, '2019-10-01 00:00:00': 0.5113234994748499, '2019-11-01 00:00:00': 0.5108587995034134}, 'Variable 2': {'2014-02-01 00:00:00': 0.76, '2014-03-01 00:00:00': 0.7822222222222223, '2014-04-01 00:00:00': 0.7977049180327868, '2014-05-01 00:00:00': 0.8052574525745256, '2014-06-01 00:00:00': 0.8036934792955734, '2014-07-01 00:00:00': 0.8108240090207303, '2014-08-01 00:00:00': 0.8182076739929706, '2014-09-01 00:00:00': 0.8234447797372412, '2014-10-01 00:00:00': 0.8226490185282981, '2014-11-01 00:00:00': 0.8265366456010516, '2014-12-01 00:00:00': 0.8338582363360735, '2015-01-01 00:00:00': 0.8287344877468826, '2015-02-01 00:00:00': 0.829002314107386, '2015-03-01 00:00:00': 0.8229350083570376, '2015-04-01 00:00:00': 0.8202536653143172, '2015-05-01 00:00:00': 0.8222593883355219, '2015-06-01 00:00:00': 0.8197510274015803, '2015-07-01 00:00:00': 0.8238751148765261, '2015-08-01 00:00:00': 0.8210595148281693, '2015-09-01 00:00:00': 0.8127518307866864, '2015-10-01 00:00:00': 0.808159104203408, '2015-11-01 00:00:00': 0.8125597544301224, '2015-12-01 00:00:00': 0.8120447635746545, '2016-01-01 00:00:00': 0.8176623391101475, '2016-02-01 00:00:00': 0.8201392287124698, '2016-03-01 00:00:00': 0.8221173615095082, '2016-04-01 00:00:00': 0.8156783205618962, '2016-05-01 00:00:00': 0.8105327033783633, '2016-06-01 00:00:00': 0.8164352965231777, '2016-07-01 00:00:00': 0.8131441629925701, '2016-08-01 00:00:00': 0.8105127243434443, '2016-09-01 00:00:00': 0.8104100981659207, '2016-10-01 00:00:00': 0.8103280265136469, '2016-11-01 00:00:00': 0.8102623879282007, '2016-12-01 00:00:00': 0.8082090774208655, '2017-01-01 00:00:00': 0.8025654304685461, '2017-02-01 00:00:00': 0.794050133677398, '2017-03-01 00:00:00': 0.7772366149106914, '2017-04-01 00:00:00': 0.7737887190485899, '2017-05-01 00:00:00': 0.777031406265935, '2017-06-01 00:00:00': 0.773624762756274, '2017-07-01 00:00:00': 0.7748999186832886, '2017-08-01 00:00:00': 0.7759200043700653, '2017-09-01 00:00:00': 0.7807362657182619, '2017-10-01 00:00:00': 0.784589180392712, '2017-11-01 00:00:00': 0.7896715214079071, '2017-12-01 00:00:00': 0.7977374419713747, '2018-01-01 00:00:00': 0.7981899636686708, '2018-02-01 00:00:00': 0.8065521201207929, '2018-03-01 00:00:00': 0.8032416488480094, '2018-04-01 00:00:00': 0.8065933573481534, '2018-05-01 00:00:00': 0.8003098284823494, '2018-06-01 00:00:00': 0.8002478623330613, '2018-07-01 00:00:00': 0.7961982661924835, '2018-08-01 00:00:00': 0.7929585978026886, '2018-09-01 00:00:00': 0.7903668685453406, '2018-10-01 00:00:00': 0.7942935065893102, '2018-11-01 00:00:00': 0.795434808004322, '2018-12-01 00:00:00': 0.7923478404900027, '2019-01-01 00:00:00': 0.79187827167239, '2019-02-01 00:00:00': 0.7855026095213731, '2019-03-01 00:00:00': 0.7824020845761124, '2019-04-01 00:00:00': 0.7899216735610429, '2019-05-01 00:00:00': 0.7919373401140887, '2019-06-01 00:00:00': 0.7907376714888356, '2019-07-01 00:00:00': 0.7937127383862557, '2019-08-01 00:00:00': 0.8044939941739666, '2019-09-01 00:00:00': 0.8175951987076252, '2019-10-01 00:00:00': 0.8260761607105328, '2019-11-01 00:00:00': 0.7428609148753197}, 'Variable 3': {'2014-02-01 00:00:00': 0.73, '2014-03-01 00:00:00': 0.7355555555555554, '2014-04-01 00:00:00': 0.7455737704918032, '2014-05-01 00:00:00': 0.7436856368563685, '2014-06-01 00:00:00': 0.7574631128034269, '2014-07-01 00:00:00': 0.7635718622603868, '2014-08-01 00:00:00': 0.7727908521079994, '2014-09-01 00:00:00': 0.7769265339645449, '2014-10-01 00:00:00': 0.7753264702560229, '2014-11-01 00:00:00': 0.7830953537143132, '2014-12-01 00:00:00': 0.7889819365901924, '2015-01-01 00:00:00': 0.7934957351470745, '2015-02-01 00:00:00': 0.8012213058591142, '2015-03-01 00:00:00': 0.7988738003009945, '2015-04-01 00:00:00': 0.7887425796020084, '2015-05-01 00:00:00': 0.7807696455386262, '2015-06-01 00:00:00': 0.79288861127886, '2015-07-01 00:00:00': 0.7963736702644841, '2015-08-01 00:00:00': 0.7950802967346366, '2015-09-01 00:00:00': 0.7879824042589837, '2015-10-01 00:00:00': 0.7843524429233086, '2015-11-01 00:00:00': 0.7734011480450893, '2015-12-01 00:00:00': 0.7686931271861905, '2016-01-01 00:00:00': 0.7729747210040915, '2016-02-01 00:00:00': 0.7763926895232527, '2016-03-01 00:00:00': 0.7791224016673299, '2016-04-01 00:00:00': 0.7913274312847312, '2016-05-01 00:00:00': 0.7870536783874261, '2016-06-01 00:00:00': 0.7876438559655086, '2016-07-01 00:00:00': 0.7841107109507285, '2016-08-01 00:00:00': 0.779283788408037, '2016-09-01 00:00:00': 0.7754239726653402, '2016-10-01 00:00:00': 0.7723372216713971, '2016-11-01 00:00:00': 0.7738705548293968, '2016-12-01 00:00:00': 0.7690945064681345, '2017-01-01 00:00:00': 0.7612730669722748, '2017-02-01 00:00:00': 0.7470147519075939, '2017-03-01 00:00:00': 0.7416106791440739, '2017-04-01 00:00:00': 0.7412884897823692, '2017-05-01 00:00:00': 0.7370302258055261, '2017-06-01 00:00:00': 0.73762424381125, '2017-07-01 00:00:00': 0.7440999459408121, '2017-08-01 00:00:00': 0.7552807176765437, '2017-09-01 00:00:00': 0.7602248433250394, '2017-10-01 00:00:00': 0.7581797855852043, '2017-11-01 00:00:00': 0.7505435623846199, '2017-12-01 00:00:00': 0.7524349026305672, '2018-01-01 00:00:00': 0.7499478666416979, '2018-02-01 00:00:00': 0.7419581507720641, '2018-03-01 00:00:00': 0.7435665435734004, '2018-04-01 00:00:00': 0.7408532038778578, '2018-05-01 00:00:00': 0.746312612970632, '2018-06-01 00:00:00': 0.7447532789816597, '2018-07-01 00:00:00': 0.740342197398116, '2018-08-01 00:00:00': 0.7409253606458336, '2018-09-01 00:00:00': 0.7367402728583945, '2018-10-01 00:00:00': 0.7373922202380955, '2018-11-01 00:00:00': 0.7379137774393577, '2018-12-01 00:00:00': 0.7363310189195232, '2019-01-01 00:00:00': 0.7273212013281132, '2019-02-01 00:00:00': 0.7118675421163595, '2019-03-01 00:00:00': 0.7066490285747843, '2019-04-01 00:00:00': 0.7003730179354327, '2019-05-01 00:00:00': 0.7057160177022014, '2019-06-01 00:00:00': 0.698675610626293, '2019-07-01 00:00:00': 0.6990652886575816, '2019-08-01 00:00:00': 0.7023210319724209, '2019-09-01 00:00:00': 0.7098568275154657, '2019-10-01 00:00:00': 0.7098854620182623, '2019-11-01 00:00:00': 0.7059083689601774}, 'Variable 4': {'2014-02-01 00:00:00': 0.74, '2014-03-01 00:00:00': 0.74, '2014-04-01 00:00:00': 0.723606557377049, '2014-05-01 00:00:00': 0.7257723577235771, '2014-06-01 00:00:00': 0.7359543074726319, '2014-07-01 00:00:00': 0.7343403590944573, '2014-08-01 00:00:00': 0.7433648628949967, '2014-09-01 00:00:00': 0.7449594111151099, '2014-10-01 00:00:00': 0.7507439113745216, '2014-11-01 00:00:00': 0.7640207150378528, '2014-12-01 00:00:00': 0.7740807198648756, '2015-01-01 00:00:00': 0.7796470942252629, '2015-02-01 00:00:00': 0.7881871710698463, '2015-03-01 00:00:00': 0.790658423695772, '2015-04-01 00:00:00': 0.7925948716624064, '2015-05-01 00:00:00': 0.7879450155148408, '2015-06-01 00:00:00': 0.7945037008766296, '2015-07-01 00:00:00': 0.7956231264802287, '2015-08-01 00:00:00': 0.7985405456250583, '2015-09-01 00:00:00': 0.8008591684006369, '2015-10-01 00:00:00': 0.800685735080474, '2015-11-01 00:00:00': 0.8025624356705747, '2015-12-01 00:00:00': 0.8040587814026247, '2016-01-01 00:00:00': 0.8052526630688649, '2016-02-01 00:00:00': 0.8062057310441018, '2016-03-01 00:00:00': 0.8049608223295611, '2016-04-01 00:00:00': 0.7979517108720217, '2016-05-01 00:00:00': 0.7863389062666964, '2016-06-01 00:00:00': 0.7770567615901753, '2016-07-01 00:00:00': 0.7656312651926812, '2016-08-01 00:00:00': 0.7604999303262361, '2016-09-01 00:00:00': 0.7563966933417224, '2016-10-01 00:00:00': 0.755116543281882, '2016-11-01 00:00:00': 0.7580947447530586, '2016-12-01 00:00:00': 0.7504727039353692, '2017-01-01 00:00:00': 0.7423755354668953, '2017-02-01 00:00:00': 0.743900824361153, '2017-03-01 00:00:00': 0.7451209128913961, '2017-04-01 00:00:00': 0.7400958953888739, '2017-05-01 00:00:00': 0.7400767137614234, '2017-06-01 00:00:00': 0.746062007474736, '2017-07-01 00:00:00': 0.7468496729869601, '2017-08-01 00:00:00': 0.7474797812725159, '2017-09-01 00:00:00': 0.7599845058399765, '2017-10-01 00:00:00': 0.7639877790391211, '2017-11-01 00:00:00': 0.7631901954395647, '2017-12-01 00:00:00': 0.772552417332308, '2018-01-01 00:00:00': 0.776042011686401, '2018-02-01 00:00:00': 0.7648334093809737, '2018-03-01 00:00:00': 0.7618666851622758, '2018-04-01 00:00:00': 0.7594933210307929, '2018-05-01 00:00:00': 0.7633324918930999, '2018-06-01 00:00:00': 0.7513019056008721, '2018-07-01 00:00:00': 0.7470800997999933, '2018-08-01 00:00:00': 0.7512778994722862, '2018-09-01 00:00:00': 0.7530223261045037, '2018-10-01 00:00:00': 0.7524178590743393, '2018-11-01 00:00:00': 0.7499342813124842, '2018-12-01 00:00:00': 0.7499474250751659, '2019-01-01 00:00:00': 0.738009121764736, '2019-02-01 00:00:00': 0.723599279745374, '2019-03-01 00:00:00': 0.7162468165850243, '2019-04-01 00:00:00': 0.7138576513933903, '2019-05-01 00:00:00': 0.7156889222642197, '2019-06-01 00:00:00': 0.7064441331689372, '2019-07-01 00:00:00': 0.703616905399355, '2019-08-01 00:00:00': 0.7068089253453598, '2019-09-01 00:00:00': 0.71144714146882, '2019-10-01 00:00:00': 0.7111577131155241, '2019-11-01 00:00:00': 0.706926169796117}, 'Variable 5': {'2014-02-01 00:00:00': 0.65, '2014-03-01 00:00:00': 0.6333333333333334, '2014-04-01 00:00:00': 0.6401639344262295, '2014-05-01 00:00:00': 0.6604336043360434, '2014-06-01 00:00:00': 0.6722037125178486, '2014-07-01 00:00:00': 0.6851591638476884, '2014-08-01 00:00:00': 0.6990379164574595, '2014-09-01 00:00:00': 0.7088818754248837, '2014-10-01 00:00:00': 0.7114502173590359, '2014-11-01 00:00:00': 0.7245687674808299, '2014-12-01 00:00:00': 0.7323209187042266, '2015-01-01 00:00:00': 0.7404128051669034, '2015-02-01 00:00:00': 0.7297437040994432, '2015-03-01 00:00:00': 0.7193372840872788, '2015-04-01 00:00:00': 0.7132558560426701, '2015-05-01 00:00:00': 0.706412048785298, '2015-06-01 00:00:00': 0.6989618760525225, '2015-07-01 00:00:00': 0.6971366199512274, '2015-08-01 00:00:00': 0.6936591807809778, '2015-09-01 00:00:00': 0.6868488265867368, '2015-10-01 00:00:00': 0.6854663098027436, '2015-11-01 00:00:00': 0.6843649210274496, '2015-12-01 00:00:00': 0.6854986290529358, '2016-01-01 00:00:00': 0.6904221539312114, '2016-02-01 00:00:00': 0.6983677407231715, '2016-03-01 00:00:00': 0.7047133710694555, '2016-04-01 00:00:00': 0.7097829543558235, '2016-05-01 00:00:00': 0.7118303236728661, '2016-06-01 00:00:00': 0.7194760901889194, '2016-07-01 00:00:00': 0.7215834809745675, '2016-08-01 00:00:00': 0.7272724188308166, '2016-09-01 00:00:00': 0.7298199534295052, '2016-10-01 00:00:00': 0.7318572540362727, '2016-11-01 00:00:00': 0.7474937318652203, '2016-12-01 00:00:00': 0.7459943772817003, '2017-01-01 00:00:00': 0.746795761889534, '2017-02-01 00:00:00': 0.7474367759283862, '2017-03-01 00:00:00': 0.7499499427070278, '2017-04-01 00:00:00': 0.7359576292937829, '2017-05-01 00:00:00': 0.7387664767948997, '2017-06-01 00:00:00': 0.7390132076728472, '2017-07-01 00:00:00': 0.7412107530847662, '2017-08-01 00:00:00': 0.744968858231196, '2017-09-01 00:00:00': 0.7479752502685084, '2017-10-01 00:00:00': 0.7423799565053918, '2017-11-01 00:00:00': 0.7299035304643163, '2017-12-01 00:00:00': 0.7279227691558866, '2018-01-01 00:00:00': 0.7303382691921602, '2018-02-01 00:00:00': 0.7242705071012351, '2018-03-01 00:00:00': 0.7274164505813938, '2018-04-01 00:00:00': 0.7319332120374141, '2018-05-01 00:00:00': 0.729574748086813, '2018-06-01 00:00:00': 0.725473568500047, '2018-07-01 00:00:00': 0.7240618465471018, '2018-08-01 00:00:00': 0.7171134447413594, '2018-09-01 00:00:00': 0.7136907429872398, '2018-10-01 00:00:00': 0.7149525981667205, '2018-11-01 00:00:00': 0.7099620665834272, '2018-12-01 00:00:00': 0.7019696379562902, '2019-01-01 00:00:00': 0.6938832979727522, '2019-02-01 00:00:00': 0.6825722245108661, '2019-03-01 00:00:00': 0.6776925748227463, '2019-04-01 00:00:00': 0.6701110539094498, '2019-05-01 00:00:00': 0.6729524449111299, '2019-06-01 00:00:00': 0.6667985528386154, '2019-07-01 00:00:00': 0.6667028422324421, '2019-08-01 00:00:00': 0.6724098756201236, '2019-09-01 00:00:00': 0.6779279019148391, '2019-10-01 00:00:00': 0.6803423220284887, '2019-11-01 00:00:00': 0.6782738572824242}, 'Variable 6': {'2014-02-01 00:00:00': 0.69, '2014-03-01 00:00:00': 0.7011111111111111, '2014-04-01 00:00:00': 0.6965573770491802, '2014-05-01 00:00:00': 0.7044986449864497, '2014-06-01 00:00:00': 0.7239838172298904, '2014-07-01 00:00:00': 0.7310356492323704, '2014-08-01 00:00:00': 0.7408964869373673, '2014-09-01 00:00:00': 0.7454874203679608, '2014-10-01 00:00:00': 0.7465298486499848, '2014-11-01 00:00:00': 0.7540291054920077, '2014-12-01 00:00:00': 0.7684631602568823, '2015-01-01 00:00:00': 0.7687932089811338, '2015-02-01 00:00:00': 0.766932260457908, '2015-03-01 00:00:00': 0.7633900189366875, '2015-04-01 00:00:00': 0.7626872900756247, '2015-05-01 00:00:00': 0.7683080421668985, '2015-06-01 00:00:00': 0.7686542291718514, '2015-07-01 00:00:00': 0.7730017004169999, '2015-08-01 00:00:00': 0.7764510710026696, '2015-09-01 00:00:00': 0.7771691355224005, '2015-10-01 00:00:00': 0.7777405790542123, '2015-11-01 00:00:00': 0.7781958223459676, '2015-12-01 00:00:00': 0.7785588005217382, '2016-01-01 00:00:00': 0.786886366234597, '2016-02-01 00:00:00': 0.7855038700648177, '2016-03-01 00:00:00': 0.7803876331746648, '2016-04-01 00:00:00': 0.7863244609083996, '2016-05-01 00:00:00': 0.7870609933877296, '2016-06-01 00:00:00': 0.7896528053449289, '2016-07-01 00:00:00': 0.7897223303437229, '2016-08-01 00:00:00': 0.7837719713248361, '2016-09-01 00:00:00': 0.7830169788932382, '2016-10-01 00:00:00': 0.786415737333679, '2016-11-01 00:00:00': 0.7871329535387643, '2016-12-01 00:00:00': 0.7857057839022286, '2017-01-01 00:00:00': 0.7825636074272179, '2017-02-01 00:00:00': 0.7800502334325795, '2017-03-01 00:00:00': 0.7800401846590149, '2017-04-01 00:00:00': 0.7820324787538478, '2017-05-01 00:00:00': 0.7836261948442826, '2017-06-01 00:00:00': 0.7829008787465891, '2017-07-01 00:00:00': 0.782320653637178, '2017-08-01 00:00:00': 0.7918571719315459, '2017-09-01 00:00:00': 0.8014862618027555, '2017-10-01 00:00:00': 0.805189170726635, '2017-11-01 00:00:00': 0.8041513004168058, '2017-12-01 00:00:00': 0.8073211286953607, '2018-01-01 00:00:00': 0.8098569595072054, '2018-02-01 00:00:00': 0.7998853897070145, '2018-03-01 00:00:00': 0.7899081693659644, '2018-04-01 00:00:00': 0.7819264443575827, '2018-05-01 00:00:00': 0.7836207709626981, '2018-06-01 00:00:00': 0.772950738798811, '2018-07-01 00:00:00': 0.7699665735935995, '2018-08-01 00:00:00': 0.7639776308657609, '2018-09-01 00:00:00': 0.7531820643015988, '2018-10-01 00:00:00': 0.7505456435500623, '2018-11-01 00:00:00': 0.7504365145787377, '2018-12-01 00:00:00': 0.742349196170766, '2019-01-01 00:00:00': 0.7311101397128089, '2019-02-01 00:00:00': 0.7195646976155763, '2019-03-01 00:00:00': 0.711108149798303, '2019-04-01 00:00:00': 0.7080263174205204, '2019-05-01 00:00:00': 0.7100056551788667, '2019-06-01 00:00:00': 0.7042059212306517, '2019-07-01 00:00:00': 0.6995393351097928, '2019-08-01 00:00:00': 0.7024886690357137, '2019-09-01 00:00:00': 0.7059909361290391, '2019-10-01 00:00:00': 0.7047927486567783, '2019-11-01 00:00:00': 0.7038341987676929}, 'Variable 7': {'2014-02-01 00:00:00': 0.74, '2014-03-01 00:00:00': 0.7455555555555556, '2014-04-01 00:00:00': 0.7637704918032787, '2014-05-01 00:00:00': 0.7658807588075881, '2014-06-01 00:00:00': 0.7700809138505474, '2014-07-01 00:00:00': 0.7646378697198369, '2014-08-01 00:00:00': 0.7634641486208515, '2014-09-01 00:00:00': 0.7602284605138899, '2014-10-01 00:00:00': 0.7486254369505038, '2014-11-01 00:00:00': 0.7534145798652732, '2014-12-01 00:00:00': 0.757043375022721, '2015-01-01 00:00:00': 0.7641210759203562, '2015-02-01 00:00:00': 0.7590162182160856, '2015-03-01 00:00:00': 0.761314033560453, '2015-04-01 00:00:00': 0.7714063175225095, '2015-05-01 00:00:00': 0.7711169078602121, '2015-06-01 00:00:00': 0.7688423068263266, '2015-07-01 00:00:00': 0.7650047135260325, '2015-08-01 00:00:00': 0.7619598902935452, '2015-09-01 00:00:00': 0.7575166855721088, '2015-10-01 00:00:00': 0.7519621166015673, '2015-11-01 00:00:00': 0.7515667761838508, '2015-12-01 00:00:00': 0.7452159321810096, '2016-01-01 00:00:00': 0.7481867751540896, '2016-02-01 00:00:00': 0.7485507953526997, '2016-03-01 00:00:00': 0.7468354519749125, '2016-04-01 00:00:00': 0.7454650481467877, '2016-05-01 00:00:00': 0.7383582920519313, '2016-06-01 00:00:00': 0.734680943219848, '2016-07-01 00:00:00': 0.7277361573473825, '2016-08-01 00:00:00': 0.7181794613846456, '2016-09-01 00:00:00': 0.7085359287139801, '2016-10-01 00:00:00': 0.7008238548636614, '2016-11-01 00:00:00': 0.6966569710298119, '2016-12-01 00:00:00': 0.693324224901408, '2017-01-01 00:00:00': 0.6866572163531551, '2017-02-01 00:00:00': 0.681324388601285, '2017-03-01 00:00:00': 0.6790590403866112, '2017-04-01 00:00:00': 0.6712459341343434, '2017-05-01 00:00:00': 0.666996182418579, '2017-06-01 00:00:00': 0.6735976479230842, '2017-07-01 00:00:00': 0.6728780571224521, '2017-08-01 00:00:00': 0.6723024065212118, '2017-09-01 00:00:00': 0.6778422268334763, '2017-10-01 00:00:00': 0.6762737131483748, '2017-11-01 00:00:00': 0.677018996488034, '2017-12-01 00:00:00': 0.683615381070792, '2018-01-01 00:00:00': 0.6928925117435609, '2018-02-01 00:00:00': 0.690313963392009, '2018-03-01 00:00:00': 0.6882511412720261, '2018-04-01 00:00:00': 0.6926009626838016, '2018-05-01 00:00:00': 0.6945959883703744, '2018-06-01 00:00:00': 0.6963128032419382, '2018-07-01 00:00:00': 0.6938810283773789, '2018-08-01 00:00:00': 0.6971048377790318, '2018-09-01 00:00:00': 0.6916838499409019, '2018-10-01 00:00:00': 0.6873470669720565, '2018-11-01 00:00:00': 0.6798776356919105, '2018-12-01 00:00:00': 0.6759021009379169, '2019-01-01 00:00:00': 0.6867216973313166, '2019-02-01 00:00:00': 0.6873773586688918, '2019-03-01 00:00:00': 0.6939018933343585, '2019-04-01 00:00:00': 0.7031215219015551, '2019-05-01 00:00:00': 0.7104972221510462, '2019-06-01 00:00:00': 0.7134135791853385, '2019-07-01 00:00:00': 0.7073212609007764, '2019-08-01 00:00:00': 0.7195078126372279, '2019-09-01 00:00:00': 0.7276062521919728, '2019-10-01 00:00:00': 0.7400850043203088, '2019-11-01 00:00:00': 0.7480680047698535}, 'Variable 8': {'2014-02-01 00:00:00': 0.8, '2014-03-01 00:00:00': 0.7722222222222223, '2014-04-01 00:00:00': 0.7672131147540983, '2014-05-01 00:00:00': 0.7749322493224933, '2014-06-01 00:00:00': 0.7823893384102808, '2014-07-01 00:00:00': 0.781741694856449, '2014-08-01 00:00:00': 0.7838316515767481, '2014-09-01 00:00:00': 0.7829108336486317, '2014-10-01 00:00:00': 0.7845484662453334, '2014-11-01 00:00:00': 0.785769926267479, '2014-12-01 00:00:00': 0.7910713279510622, '2015-01-01 00:00:00': 0.7886936710207403, '2015-02-01 00:00:00': 0.7826210933273705, '2015-03-01 00:00:00': 0.7695207138807009, '2015-04-01 00:00:00': 0.7716930016870224, '2015-05-01 00:00:00': 0.7754604454645724, '2015-06-01 00:00:00': 0.7804814186361813, '2015-07-01 00:00:00': 0.788530127558967, '2015-08-01 00:00:00': 0.7949161341005531, '2015-09-01 00:00:00': 0.7939214392293673, '2015-10-01 00:00:00': 0.7931298502639657, '2015-11-01 00:00:00': 0.7965289612231494, '2015-12-01 00:00:00': 0.7932035391513529, '2016-01-01 00:00:00': 0.798588259946083, '2016-02-01 00:00:00': 0.8069020164408807, '2016-03-01 00:00:00': 0.811535617352153, '2016-04-01 00:00:00': 0.8152374443501977, '2016-05-01 00:00:00': 0.8121840493552833, '2016-06-01 00:00:00': 0.8197589610923933, '2016-07-01 00:00:00': 0.8178047496773587, '2016-08-01 00:00:00': 0.8142402696518527, '2016-09-01 00:00:00': 0.8113899574715158, '2016-10-01 00:00:00': 0.8091105212128419, '2016-11-01 00:00:00': 0.8072874925849397, '2016-12-01 00:00:00': 0.7998269677195282, '2017-01-01 00:00:00': 0.7918589884185042, '2017-02-01 00:00:00': 0.7834850167274583, '2017-03-01 00:00:00': 0.7687849602996942, '2017-04-01 00:00:00': 0.7630270115364185, '2017-05-01 00:00:00': 0.7664220605085489, '2017-06-01 00:00:00': 0.7671377245092892, '2017-07-01 00:00:00': 0.7617097178436925, '2017-08-01 00:00:00': 0.7613677510018967, '2017-09-01 00:00:00': 0.7670945125960756, '2017-10-01 00:00:00': 0.7656755482722476, '2017-11-01 00:00:00': 0.7665404687558782, '2017-12-01 00:00:00': 0.7692324500461887, '2018-01-01 00:00:00': 0.7693859634604144, '2018-02-01 00:00:00': 0.7775089156866419, '2018-03-01 00:00:00': 0.7840072252962874, '2018-04-01 00:00:00': 0.7892058395947121, '2018-05-01 00:00:00': 0.7941281166377444, '2018-06-01 00:00:00': 0.7919572774467704, '2018-07-01 00:00:00': 0.7843151772816488, '2018-08-01 00:00:00': 0.7854521471427056, '2018-09-01 00:00:00': 0.7863617211172846, '2018-10-01 00:00:00': 0.7910893910444783, '2018-11-01 00:00:00': 0.7868715027357466, '2018-12-01 00:00:00': 0.7834971957247093, '2019-01-01 00:00:00': 0.7767977463128911, '2019-02-01 00:00:00': 0.7674381855755249, '2019-03-01 00:00:00': 0.7659505470013482, '2019-04-01 00:00:00': 0.7647604366672731, '2019-05-01 00:00:00': 0.7538083424590775, '2019-06-01 00:00:00': 0.7455440698172076, '2019-07-01 00:00:00': 0.734896851576411, '2019-08-01 00:00:00': 0.7394518827250595, '2019-09-01 00:00:00': 0.7415615067224531, '2019-10-01 00:00:00': 0.7412492053137258, '2019-11-01 00:00:00': 0.7429993645389703}, 'Variable 9': {'2014-02-01 00:00:00': 0.72, '2014-03-01 00:00:00': 0.7255555555555556, '2014-04-01 00:00:00': 0.7314754098360655, '2014-05-01 00:00:00': 0.7343631436314362, '2014-06-01 00:00:00': 0.7360399809614468, '2014-07-01 00:00:00': 0.7371133662936941, '2014-08-01 00:00:00': 0.7353131630521047, '2014-09-01 00:00:00': 0.7292299339565472, '2014-10-01 00:00:00': 0.7201676245918789, '2014-11-01 00:00:00': 0.7201300669527039, '2014-12-01 00:00:00': 0.7201016090466464, '2015-01-01 00:00:00': 0.7200797876847457, '2015-02-01 00:00:00': 0.715830206977772, '2015-03-01 00:00:00': 0.710426508405698, '2015-04-01 00:00:00': 0.6999734214226706, '2015-05-01 00:00:00': 0.6938051147401559, '2015-06-01 00:00:00': 0.6848422663896675, '2015-07-01 00:00:00': 0.6838560469619452, '2015-08-01 00:00:00': 0.685102805250074, '2015-09-01 00:00:00': 0.6820470133177352, '2015-10-01 00:00:00': 0.6836524178979007, '2015-11-01 00:00:00': 0.6829165042339126, '2015-12-01 00:00:00': 0.6783059877012017, '2016-01-01 00:00:00': 0.6806558872478184, '2016-02-01 00:00:00': 0.6805242123445349, '2016-03-01 00:00:00': 0.6784129890948842, '2016-04-01 00:00:00': 0.6807360079909531, '2016-05-01 00:00:00': 0.6765807689916218, '2016-06-01 00:00:00': 0.66524707715465, '2016-07-01 00:00:00': 0.6581889241535165, '2016-08-01 00:00:00': 0.6505435677285467, '2016-09-01 00:00:00': 0.6444300105237998, '2016-10-01 00:00:00': 0.6435434464923265, '2016-11-01 00:00:00': 0.6428343976633919, '2016-12-01 00:00:00': 0.6342640415812634, '2017-01-01 00:00:00': 0.6294096579274484, '2017-02-01 00:00:00': 0.6235261989086698, '2017-03-01 00:00:00': 0.616819566213821, '2017-04-01 00:00:00': 0.6094544292277724, '2017-05-01 00:00:00': 0.6115638237688457, '2017-06-01 00:00:00': 0.6072506003544914, '2017-07-01 00:00:00': 0.6098006972218426, '2017-08-01 00:00:00': 0.6078404243682168, '2017-09-01 00:00:00': 0.6062722541152638, '2017-10-01 00:00:00': 0.6110180099990328, '2017-11-01 00:00:00': 0.6148145402889991, '2017-12-01 00:00:00': 0.6238518841555778, '2018-01-01 00:00:00': 0.6230814901441017, '2018-02-01 00:00:00': 0.6184651097563033, '2018-03-01 00:00:00': 0.616772063641081, '2018-04-01 00:00:00': 0.6174176582842525, '2018-05-01 00:00:00': 0.6175875281790592, '2018-06-01 00:00:00': 0.6149180030356703, '2018-07-01 00:00:00': 0.61793442006253, '2018-08-01 00:00:00': 0.6177563352171558, '2018-09-01 00:00:00': 0.612205047403891, '2018-10-01 00:00:00': 0.6115218358781548, '2018-11-01 00:00:00': 0.6137580740572504, '2018-12-01 00:00:00': 0.6070064463122511, '2019-01-01 00:00:00': 0.6196051763572984, '2019-02-01 00:00:00': 0.625684148538637, '2019-03-01 00:00:00': 0.6385473314470826, '2019-04-01 00:00:00': 0.6448378700934599, '2019-05-01 00:00:00': 0.6518703004890961, '2019-06-01 00:00:00': 0.6554962422121093, '2019-07-01 00:00:00': 0.6593241953075084, '2019-08-01 00:00:00': 0.6603693565819088, '2019-09-01 00:00:00': 0.6682954873034151, '2019-10-01 00:00:00': 0.6746363911469803, '2019-11-01 00:00:00': 0.6777091134232021}})

#Build the model
model = VAR(df, freq='MS')
aic, bic = [], []
o_range = np.arange(1, 11)
for i in o_range:
    result = model.fit(i)
    aic.append(result.aic)
    bic.append(result.bic)

lags_metrics_df = pd.DataFrame({'AIC': aic,
                                'BIC': bic},
                               index=range(1, len(aic) + 1))

best_model_order = lags_metrics_df.idxmin(axis=0)['AIC']
print(best_model_order)
print(lags_metrics_df)

Expected Output

The same code should provide the same output with the same data. I asked the same question in the streamlit community but suspect it might be something that is rather related to statsmodel than streamlit?

Output of import statsmodels.api as sm; sm.show_versions()

INSTALLED VERSIONS ------------------ Python: 3.11.9.final.0 statsmodels =========== Installed: 0.14.2 (C:\Users\Julia.Schulz\Desktop\streamlit thing with newest modules\streamlit-app-venv\Lib\site-packages\statsmodels) Required Dependencies ===================== cython: Not installed numpy: 2.1.0 (C:\Users\Julia.Schulz\Desktop\streamlit thing with newest modules\streamlit-app-venv\Lib\site-packages\numpy) scipy: 1.14.1 (C:\Users\Julia.Schulz\Desktop\streamlit thing with newest modules\streamlit-app-venv\Lib\site-packages\scipy) pandas: 2.2.2 (C:\Users\Julia.Schulz\Desktop\streamlit thing with newest modules\streamlit-app-venv\Lib\site-packages\pandas) dateutil: 2.9.0.post0 (C:\Users\Julia.Schulz\Desktop\streamlit thing with newest modules\streamlit-app-venv\Lib\site-packages\dateutil) patsy: 0.5.6 (C:\Users\Julia.Schulz\Desktop\streamlit thing with newest modules\streamlit-app-venv\Lib\site-packages\patsy) Optional Dependencies ===================== matplotlib: Not installed cvxopt: Not installed joblib: Not installed Developer Tools ================ IPython: Not installed jinja2: 3.1.4 (C:\Users\Julia.Schulz\Desktop\streamlit thing with newest modules\streamlit-app-venv\Lib\site-packages\jinja2) sphinx: Not installed pygments: 2.18.0 (C:\Users\Julia.Schulz\Desktop\streamlit thing with newest modules\streamlit-app-venv\Lib\site-packages\pygments) pytest: Not installed virtualenv: Not installed
bashtage commented 3 weeks ago

I suspect that the model you are fitting is not well idenfified so that the regressor matrix, consisting of lagged values, is near-singlar.

You have 70 rows and 9 columns. Each time you lag you get 9 regressors, and lose one observation, so that

lag | obs | reg | dof
1     69  |  10 |  59
2     68  |  19 |  48
3     67  |  28 |  39
4     66  |  37 |  29
5     65  |  46 |  19
6     64  |  55 |  9
7     63  |  64 |  --

At 7 lags you have perfect fit which is why the AIC and BIC get silly values. These are not meaningful and are down to numerical issues, which is you get you different values. For a data set of this size, one would not usually trust IC for more than 2 lags since the number of regressors should usually not be larger than sqrt of the sample size (which would really be 0 or 1, but could probably look at 2).

ejuliaschulz commented 3 weeks ago

Thanks @bashtage, that is reasonable. However, it still does not really explain the difference in outputs for 2 different environments, no? Other users can reproduce my results in different environments with exactly the same outcome. Sorry if I get this wrong!

bashtage commented 3 weeks ago

When you are in the area of numerical instability it is completely platform and compiler specific. In your case, the error covariance matrix is exactly 0 (theoretically) but will not be numerically exactly 0 (will be ~ 1e-15, but will look sort of like random tiny values), and will differ across platforms. This error variance is used in the AIC and BIC.

ejuliaschulz commented 3 weeks ago

ok, thanks for the explanation!