diff --git a/input/regression_files/reg_RMSE.xlsx b/input/regression_files/reg_RMSE.xlsx index 3f1ce654e..31ac0239c 100644 Binary files a/input/regression_files/reg_RMSE.xlsx and b/input/regression_files/reg_RMSE.xlsx differ diff --git a/input/regression_files/reg_wealth_financial.xlsx b/input/regression_files/reg_wealth_financial.xlsx index cd70149bb..759e83ec7 100644 Binary files a/input/regression_files/reg_wealth_financial.xlsx and b/input/regression_files/reg_wealth_financial.xlsx differ diff --git a/src/main/java/simpaths/model/BenefitUnit.java b/src/main/java/simpaths/model/BenefitUnit.java index 09d0b5c95..909bb1a42 100644 --- a/src/main/java/simpaths/model/BenefitUnit.java +++ b/src/main/java/simpaths/model/BenefitUnit.java @@ -2538,6 +2538,20 @@ public enum Variables { Liwwh_Male_66, LnDispInc, LnDispInc_sq, + Age20to24_LnDispInc, + Age25to29_LnDispInc, + Age30to34_LnDispInc, + Age35to39_LnDispInc, + Age40to44_LnDispInc, + Age45to49_LnDispInc, + Age50to54_LnDispInc, + Age55to59_LnDispInc, + Age60to64_LnDispInc, + Age65to69_LnDispInc, + Age70to74_LnDispInc, + Age75to79_LnDispInc, + Age80plus_LnDispInc, + ReferenceAdultStudent, MaleEduH_1, MaleEduH_10, MaleEduH_2, @@ -2673,6 +2687,7 @@ public enum Variables { YdsesC54, YdsesC55, Year, + YearFrom2015, Year2009, Year2010, Year2011, @@ -4052,6 +4067,20 @@ public double getDoubleValue(Enum variableID) { throw new RuntimeException("request for parameter LnDispInc without specifying yDispMonth"); return Math.pow(Math.log(Math.max(yDispMonth, 1.0)),2.0); } + case Age20to24_LnDispInc, Age25to29_LnDispInc, Age30to34_LnDispInc, + Age35to39_LnDispInc, Age40to44_LnDispInc, Age45to49_LnDispInc, + Age50to54_LnDispInc, Age55to59_LnDispInc, Age60to64_LnDispInc, + Age65to69_LnDispInc, Age70to74_LnDispInc, Age75to79_LnDispInc, + Age80plus_LnDispInc -> { + // FW1a adds an income slope to each existing age-band intercept. + // Under 20 is the baseline slope; quadratic curvature stays common. + String ageVariable = variableID.name().replace("_LnDispInc", ""); + return getDoubleValue(Variables.valueOf(ageVariable)) * getDoubleValue(Variables.LnDispInc); + } + case ReferenceAdultStudent -> { + // Use the same reference adult as the consumption age regressors. + return Les_c4.Student.equals(getRefPerson().getLabC4()) ? 1.0 : 0.0; + } case MaleEduM_10 -> { return (getMale() != null && getMale().getLabourSupplyWeekly().equals(Labour.TEN) && getMale().getEduHighestC4().equals(Education.Medium)) ? 1. : 0.; } @@ -4182,6 +4211,10 @@ public double getDoubleValue(Enum variableID) { case Year -> { return (Parameters.isFixTimeTrend && getYear() >= Parameters.timeTrendStopsIn) ? Parameters.timeTrendStopsIn : getYear(); } + case YearFrom2015 -> { + // Matches Stata's centred trend, including the existing trend freeze. + return getDoubleValue(Variables.Year) - 2015.0; + } case Year2009 -> { return (getYear() == 2009) ? 1. : 0.; } diff --git a/src/test/java/simpaths/integrationtest/expected/DemographicStatistics.csv b/src/test/java/simpaths/integrationtest/expected/DemographicStatistics.csv index c803e2f30..e5a002123 100644 --- a/src/test/java/simpaths/integrationtest/expected/DemographicStatistics.csv +++ b/src/test/java/simpaths/integrationtest/expected/DemographicStatistics.csv @@ -2,8 +2,8 @@ run,time,id_DemographicStatistics,demMarried18to29Share,demMarried30to54Share,de 1,2019.0,1,0.2119546547578152,0.6774992262457443,0.6043081245609927,0.2631398144967365,0.9653358093469514,0.07867010067899789,2911.0,6462.0,4271.0 1,2020.0,1,0.41941135248773653,0.7690869429728887,0.6558741905642923,0.31289418360196214,0.9839513867248364,0.08048103607770583,2854.0,6418.0,4324.0 1,2021.0,1,0.4362676056338028,0.7826964895930413,0.656797995900706,0.3429577464788732,0.961789375582479,0.08517421999544524,2840.0,6438.0,4391.0 -1,2022.0,1,0.3944986072423398,0.7634308716519586,0.6542902422458682,0.3774373259052925,0.9134540950611549,0.09350237717908082,2872.0,6459.0,4417.0 +1,2022.0,1,0.394508168230796,0.7634957463263727,0.653375623017671,0.37504344803614875,0.9138437741686002,0.09265971907566833,2877.0,6465.0,4414.0 2,2019.0,1,0.21229817931982137,0.6779398076326404,0.6032379164711403,0.26382686362074886,0.9655600372323921,0.07860159549507273,2911.0,6446.0,4262.0 2,2020.0,1,0.42040673211781204,0.7703611067687979,0.6587393211729393,0.3155680224403927,0.9837423792402689,0.08173631955668437,2852.0,6397.0,4331.0 2,2021.0,1,0.43400211193241817,0.7795765877957659,0.6609051626108711,0.337909186906019,0.959838107098381,0.08528542187855356,2841.0,6424.0,4397.0 -2,2022.0,1,0.3917130919220056,0.7633209417596035,0.6564695218672105,0.36664345403899723,0.9200743494423792,0.0940403353727623,2872.0,6456.0,4413.0 \ No newline at end of file +2,2022.0,1,0.3922594142259414,0.7634191746819733,0.6580557443915703,0.36541143654114366,0.9190195470058952,0.09426693859052798,2868.0,6446.0,4413.0 diff --git a/src/test/java/simpaths/integrationtest/expected/HealthStatistics.csv b/src/test/java/simpaths/integrationtest/expected/HealthStatistics.csv index ab83d6f6f..7ac4f023a 100644 --- a/src/test/java/simpaths/integrationtest/expected/HealthStatistics.csv +++ b/src/test/java/simpaths/integrationtest/expected/HealthStatistics.csv @@ -2,8 +2,8 @@ run,time,id_HealthStatistics,healthDsbl18to29Share,healthDsbl30to54Share,healthD 1,2019.0,1,0.04809343868086568,0.08635097493036212,0.0660266916413018,3.6602542081758846,3.4648715567935624,3.0852259424022477 1,2020.0,1,0.04590049053959355,0.09660330320972266,0.06406105457909343,3.546601261387526,3.359613586787161,3.053654024051804 1,2021.0,1,0.038028169014084505,0.0970798384591488,0.06649965839216579,3.5024647887323943,3.2882882882882885,2.9521749032111138 -1,2022.0,1,0.04213091922005571,0.10527945502399752,0.06361784016300656,3.3760445682451254,3.215513237343242,2.9040072447362464 +1,2022.0,1,0.04310045185957595,0.10471771075019334,0.06320797462618939,3.3740006951685784,3.2136117556071153,2.9046216583597646 2,2019.0,1,0.04809343868086568,0.0862550418864412,0.0656968559361802,3.661284781861903,3.4668011169717654,3.0863444392304085 2,2020.0,1,0.0455820476858345,0.09535719868688448,0.06257215423689678,3.5546984572230014,3.362513678286697,3.0491803278688523 2,2021.0,1,0.036606828581485396,0.09480074719800748,0.06504434841937685,3.4973600844772967,3.296232876712329,2.9563338639981804 -2,2022.0,1,0.04700557103064067,0.1008364312267658,0.061862678450033994,3.371518105849582,3.2145291201982653,2.906412871062769 \ No newline at end of file +2,2022.0,1,0.04602510460251046,0.10083772882407695,0.061182868796736914,3.3702928870292888,3.2142413900093083,2.906412871062769 diff --git a/src/test/java/simpaths/integrationtest/expected/LabourStatistics.csv b/src/test/java/simpaths/integrationtest/expected/LabourStatistics.csv index 2b54bf384..0c040efed 100644 --- a/src/test/java/simpaths/integrationtest/expected/LabourStatistics.csv +++ b/src/test/java/simpaths/integrationtest/expected/LabourStatistics.csv @@ -1,9 +1,9 @@ run,time,id_LabourStatistics,labEmpShare,labEmpToNotEmpShare,labNotEmpToEmpShare,labUnempShare,labWorkFullTime18to29Share,labWorkFullTime30to54Share,labWorkFullTime55to74Share,labWorkPartTime18to29Share,labWorkPartTime30to54Share,labWorkPartTime55to74Share 1,2019.0,1,0.7126739685415465,0.0,0.0,0.158939306596393,0.5565097904500171,0.6857010213556175,0.2858815265745727,0.10133974579182412,0.14562055091303003,0.09482556778272068 1,2020.0,1,0.7259651153178474,0.07562834072557717,0.44666666666666666,0.1460692733735637,0.4954449894884373,0.755687129947024,0.34620721554116557,0.13524877365101612,0.08818946712371455,0.057816836262719704 -1,2021.0,1,0.7536779814251664,0.027614505933237218,0.37360801781737196,0.11259965480397797,0.5010563380281691,0.7781919850885368,0.360054657253473,0.15704225352112677,0.09490525007766387,0.07310407652015487 -1,2022.0,1,0.7599413298565841,0.03187671522060376,0.29036827195467424,0.10845827900912647,0.49268802228412256,0.7753522217061465,0.37514149875481095,0.17479108635097493,0.10140888682458585,0.08082408874801902 +1,2021.0,1,0.7536779814251664,0.027725407563491185,0.3741648106904232,0.11259965480397797,0.5014084507042254,0.7777260018639329,0.3602823958096106,0.1563380281690141,0.09537123330226778,0.07310407652015487 +1,2022.0,1,0.7597069597069597,0.03196539719379681,0.29178470254957506,0.10834350834350834,0.4907890163364616,0.7749419953596288,0.37471681014952424,0.17587765033020508,0.10177880897138437,0.08155867693701857 2,2019.0,1,0.7126474713307482,0.0,0.0,0.1585677749360614,0.5568533150120234,0.6860068259385665,0.28554669169404034,0.10099622122981793,0.14551659944151413,0.09408728296574378 2,2020.0,1,0.7250745279894004,0.07609067091923909,0.44467318579516213,0.14657171248757866,0.4926367461430575,0.7572299515397842,0.3458785499884553,0.13569424964936885,0.08675941847741128,0.05679981528515354 -2,2021.0,1,0.7539689068026652,0.02690383546414675,0.3695532266960838,0.11293904746236735,0.5019359380499824,0.7778642590286425,0.3600181942233341,0.15874692009855684,0.09604607721046077,0.07095747100295656 -2,2022.0,1,0.7598043212392989,0.03213870387990274,0.2938689217758985,0.10990623726049735,0.48746518105849584,0.7752478314745973,0.3759347382732835,0.17931754874651812,0.10176579925650557,0.07840471334692953 \ No newline at end of file +2,2021.0,1,0.7539689068026652,0.02690383546414675,0.37010479867622725,0.11293904746236735,0.5022879267863428,0.7777085927770859,0.36024562201501026,0.15769095388947554,0.09620174346201743,0.0711848987946327 +2,2022.0,1,0.7603886031512777,0.032554698234858896,0.2980085348506401,0.10931504612621439,0.4895397489539749,0.774433757368911,0.37548153183775207,0.1806136680613668,0.10254421346571517,0.0790845230002266 diff --git a/src/test/java/simpaths/integrationtest/expected/WealthIncomeStatistics.csv b/src/test/java/simpaths/integrationtest/expected/WealthIncomeStatistics.csv index 4d1d2543a..357b7715a 100644 --- a/src/test/java/simpaths/integrationtest/expected/WealthIncomeStatistics.csv +++ b/src/test/java/simpaths/integrationtest/expected/WealthIncomeStatistics.csv @@ -1,9 +1,9 @@ run,time,id_WealthIncomeStatistics,statInvestLoss18to29Avg,statInvestLoss30to54Avg,statInvestLoss55to74Avg,statSIndexP50,statYDispGrossOfLosses18to29Avg,statYDispGrossOfLosses30to54Avg,statYDispGrossOfLosses55to74Avg,statYHhDispEquivNatGini,statYInvest18to29Avg,statYInvest30to54Avg,statYInvest55to74Avg,statYLabWeeklyPerWorker18to29Avg,statYLabWeeklyPerWorker30to54Avg,statYLabWeeklyPerWorker55to74Avg,statYMktNatGini,statYPens18to29Avg,statYPens30to54Avg,statYPens55to74Avg,wealth18to29Avg,wealth30to54Avg,wealth55to74Avg,yEmployedEarningsP20,yEmployedEarningsP40,yEmployedEarningsP60,yEmployedEarningsP80,yHhDispEquivP50,yHhQuintilesC5P20,yHhQuintilesC5P40,yHhQuintilesC5P60,yHhQuintilesC5P80,yLabFceEarningsP20,yLabFceEarningsP40,yLabFceEarningsP60,yLabFceEarningsP80 1,2019.0,1,0.0,0.0,0.0,0.0,1098.3619822396215,1659.0317891410793,1522.3926171014346,0.0,0.0,0.0,0.0,395.13042709203506,566.9991878868162,487.2743556874287,0.0,0.0,0.0,0.0,14788.277425041762,179671.46899293957,297472.45000012836,11497.444084641429,18506.172624107145,26144.305492414285,38420.89577607858,16048.5576,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 -1,2020.0,1,-250.7488411029527,-328.52812800727696,-762.1198505665782,0.0,1307.3119010178075,1941.3838747128084,2068.4123000004356,0.0,-250.7488411029527,-328.52812800727696,-762.1198505665782,425.84127825543123,643.3286046985605,543.2464470741508,0.0,0.2580110975379803,8.228551113280265,388.1515219185641,19665.43171307161,190923.72950161409,318579.2573834327,10423.380815659611,17528.457823676694,27074.14468509112,43365.68237995348,11385.98054646562,-5.955783258644075,5.70197923247809,7.418462500489933,8.201946603951265,79.92384204585235,887.4637819299685,1682.4925524476525,3046.8137726571863 -1,2021.0,1,-36.68756007817177,-517.9741693028336,-474.1743951732273,0.0,1308.6779125027945,2512.3739926606486,2498.318395617464,0.0,82.3352896148895,-311.29517223174184,31.554844044978324,417.5567714410715,647.5848293342482,520.1240387265273,0.0,0.5849264137883765,8.676252951895004,361.22206239561865,24888.824311751294,238575.78509438183,380975.22088567866,9751.195791039347,17214.130801200638,26338.780615047886,43586.217763426255,17098.12595948333,6.282728145686912,7.404898055813944,8.01953375458997,8.554481213360386,689.4713221320721,1424.7060369005446,2283.4874064516766,3771.9971899033226 -1,2022.0,1,-0.4890385202415654,-0.6175983395229478,-0.16872530202047192,0.0,1342.8815919772696,3220.1586055786543,2868.6368368117614,0.0,201.4163827025984,3237.957451587501,3635.0081103129764,416.31281942018035,640.9411425706578,522.4438525538973,0.0,0.2295824309220035,7.356505184850107,322.2761213635668,24485.684898902036,217365.18431530372,384895.0635175582,9586.632266175575,16616.49975851708,26169.479002616128,42267.36406762688,17689.35650657962,6.675818615152003,7.528208324163545,8.0613859766916,8.586128671926126,790.1406349717676,1491.6106577142205,2369.601879308474,3883.7744529063953 +1,2020.0,1,-250.7488411029527,-328.52812800727696,-762.1198505665782,0.0,1307.3119010178075,1941.3838747128084,2068.4123000004356,0.0,-250.7488411029527,-328.52812800727696,-762.1198505665782,425.84127825543123,643.3286046985605,543.2464470741508,0.0,0.2580110975379803,8.228551113280265,388.1515219185641,20253.729354243365,190849.65904412942,318117.39379962336,10423.380815659611,17528.457823676694,27074.14468509112,43365.68237995348,11385.98054646562,-5.955783258644075,5.70197923247809,7.418462500489933,8.201946603951265,79.92384204585235,887.4637819299685,1682.4925524476525,3046.8137726571863 +1,2021.0,1,-37.015838791649216,-579.8636805032824,-514.5168240939524,0.0,1311.658114843149,2573.6026897842435,2537.979009511179,0.0,83.39924671901379,-371.65055030528947,-9.941845228995463,418.3817800356049,647.6680387493873,520.567319769875,0.0,0.5849264137883765,8.676252951895004,361.22206239561865,26281.302561841854,242714.46816493702,384253.9611595054,9783.134202114947,17221.329603750677,26333.09198062594,43594.67292336701,17136.370929563793,6.282655961741195,7.40557552551278,8.018055697238193,8.554725802060752,690.364374669642,1425.9679982438136,2283.447499472534,3772.2368169515516 +1,2022.0,1,-0.4775388677015336,-0.5997286605649887,-0.1660715640209267,0.0,1340.1344119847204,3310.2589680285414,2928.0707509986246,0.0,204.55470844455527,3515.6089744754854,3884.973261120413,414.99873832300136,641.5809151114466,521.841497994903,0.0,0.2291834346916907,7.349677801847926,322.49515814745683,26285.833406504364,231329.7500097538,396127.6784047258,9568.519399003922,16580.274055759728,26178.92667947928,42266.99714782604,17709.178669879024,6.678815100457701,7.528715111115655,8.0650445502503,8.5900180384411,785.6007923133773,1490.5084364598026,2375.925128747765,3883.058933256573 2,2019.0,1,0.0,0.0,0.0,0.0,1098.3549517548865,1660.4279555229555,1523.8390765899653,0.0,0.0,0.0,0.0,395.554917209919,567.3590978050611,488.6361413475094,0.0,0.0,0.0,0.0,14848.479668022597,180279.78637938178,298618.0568016762,11518.71286347,18523.15623358286,26144.90110037143,38385.89565308573,16068.192000000001,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 -2,2020.0,1,-251.44853207303862,-327.5163848247718,-765.8910514294679,0.0,1313.0876472585383,1938.145675146225,2076.122274153027,0.0,-251.44853207303862,-327.5163848247718,-765.8910514294679,427.1597751776355,642.7577520844819,550.9098190909464,0.0,0.2680109421529793,8.229506463232132,388.604887168888,19738.26579621087,191001.87181937727,321124.09222432907,10462.499647595689,17570.993151163577,27117.55336464533,43596.770540150035,11402.656686917799,-5.964979880372034,5.714758904785886,7.421765226785345,8.208225367394723,77.21236525922397,890.1476100108384,1694.0879450686514,3067.939917282307 -2,2021.0,1,-36.62420661988649,-608.304051467683,-358.5894845357523,0.0,1313.7331877924257,2600.6436017033643,2393.1664386792813,0.0,82.30364461866606,-397.7608985383392,150.76948054731454,417.75259802529683,646.898004928068,524.9825506015943,0.0,0.5637411780655305,8.303709304997756,363.02713557049464,24002.453992000355,242887.53294619726,378892.4757826235,9723.901702426965,17169.961707796203,26356.400807496528,43907.78381605853,17107.091229364036,6.303371440453282,7.408502559403067,8.02442396197474,8.563907765653155,686.951233222443,1424.8537948263267,2296.811166991709,3829.8019327967563 -2,2022.0,1,-0.507976230597884,-0.6284670815577966,-0.190654892928645,0.0,1326.624225188659,3225.6676425335086,2869.756584758877,0.0,202.48414676631998,3511.0042645500757,3016.479829252969,406.50905607556535,638.3357760543789,523.9444925535469,0.0,0.6579750403410656,6.809227198472103,325.42383169340553,23158.241447775097,224540.84392181353,378963.7137527624,9515.420618950966,16568.318397693467,26023.034757176858,42379.12694974829,17682.778892519746,6.674225077093719,7.509050626633911,8.0731158933846,8.59282179021714,785.1324476454662,1483.091501769883,2372.9396165114435,3884.1276201117776 \ No newline at end of file +2,2020.0,1,-251.44853207303862,-327.5163848247718,-765.8910514294679,0.0,1313.0876472585383,1938.145675146225,2076.122274153027,0.0,-251.44853207303862,-327.5163848247718,-765.8910514294679,427.1597751776355,642.7577520844819,550.9098190909464,0.0,0.2680109421529793,8.229506463232132,388.604887168888,20331.9564225529,190924.8903109714,320640.2048370646,10462.499647595689,17570.993151163577,27117.55336464533,43596.770540150035,11402.656686917799,-5.964979880372034,5.714758904785886,7.421765226785345,8.208225367394723,77.21236525922397,890.1476100108384,1694.0879450686514,3067.939917282307 +2,2021.0,1,-36.95695939194427,-673.4713884395934,-410.54292979063,0.0,1317.5023032823108,2664.921300830438,2443.4559661561384,0.0,83.43498802630762,-461.3191951490834,97.62600965772089,418.7378434101851,647.2917433279545,525.2313299619132,0.0,0.5637411780655305,8.303709304997756,363.02713557049464,25391.451146483054,247196.68214369428,382855.5427898394,9736.733863913556,17187.472388658127,26343.764573731576,44041.75042902999,17125.424393503192,6.292717413591005,7.405701059781297,8.023567646432612,8.562852736353621,687.0077749518179,1426.0464484510055,2295.9689555167233,3837.9571463275083 +2,2022.0,1,-0.4988955022159949,-0.5707540692045535,-0.1878862573337276,0.0,1332.6871694904623,3381.2174232601224,3146.105767513779,0.0,207.2053114160848,3987.4238450418407,3458.0007046602254,405.1074951294256,637.9354415176269,524.921114923114,0.0,0.6588927182215971,6.819790690868119,325.42383169340553,24968.50992935619,238183.172218754,391446.65695303713,9537.948122968119,16549.23386825755,26015.41842601896,42398.17394780925,17738.344700329362,6.675686302118199,7.509325947935047,8.07660422532203,8.596816260751885,785.5136251279536,1484.2050801982614,2377.110739875384,3877.966926902728 diff --git a/src/test/java/simpaths/integrationtest/expected/WellbeingByGender.csv b/src/test/java/simpaths/integrationtest/expected/WellbeingByGender.csv index 528bfbf4d..03a2b6bf8 100644 --- a/src/test/java/simpaths/integrationtest/expected/WellbeingByGender.csv +++ b/src/test/java/simpaths/integrationtest/expected/WellbeingByGender.csv @@ -5,21 +5,21 @@ run,time,id_WellbeingByGender,demLifeSatScore0to10Avg,demLifeSatScore0to10P10,de 1,2020.0,1,6.531719057032783,3.6619029594317953,5.126032154983248,6.672429510472085,8.078231374029382,9.34030448057857,Total,8110.486091743377,65872.3866901756,45.73853340891123,32.604653955446956,39.48855858133085,46.25042214579257,52.61532853086872,58.05145587511929,10085,51.08567401306888,38.30609436182795,45.56308491110741,52.07600070991801,57.83068576393079,62.538704593936394,12.883029553278584,6.18360669682598,9.185602468593313,12.534688349095003,16.281417050173566,19.935769021318947 1,2020.0,2,6.555495866706393,3.723363785025523,5.20070909542898,6.654396553959046,8.086760327933826,9.338471094222937,Male,4062.2134873756077,32403.816069129756,47.013858481528516,34.41661832157898,41.06412892252041,47.387138910016816,53.68044556750254,59.044051795120545,4943,51.52874195724106,39.44611046297003,46.155833247932264,52.41173314786387,58.083664207769104,62.54042999775598,12.162772744095959,5.629643336601326,8.608730097229119,11.813467793028996,15.369150937369977,19.02672868104122 1,2020.0,3,6.508862431164122,3.5951748845483316,5.057143526171261,6.680254374277837,8.070674912075647,9.351230104830869,Female,4048.272604367769,33468.570621045976,44.5125645575018,31.306260059211624,38.05714002128869,45.144230919425155,51.46122772447984,56.911359045859456,5142,50.659753194701885,36.77458432252791,44.983533111816946,51.76111567015478,57.59612444571111,62.568954854149524,13.575411779608753,6.847863234639331,9.722448914590839,13.238833406057982,17.0211645966218,20.673675253120077 -1,2021.0,1,6.384821845019674,3.657866438932769,5.0129653562801,6.455968810757305,7.891122159243835,9.081175294315702,Total,8029.979663984851,64735.70868665447,44.9254674680324,32.176894174583786,38.19112077282166,45.24642028650752,51.66632512738298,57.35041543406466,10139,50.77866857717815,38.026128191380984,44.78047843222764,51.25113265375148,57.41806850976098,62.82180665767753,13.270397951017715,6.516423364219324,9.66718828468779,13.130954811621557,16.808395124601887,20.13468624031968 -1,2021.0,2,6.412650532070537,3.6858994342431295,5.047240261948179,6.510253476487479,7.9201382248455685,9.068125947310957,Male,4000.18762742062,31806.74663906991,46.20360990614665,33.512918131525396,39.65271950084021,46.47176600017271,52.629653572139425,58.45268815117875,4960,51.029906875362926,38.97091060634392,45.21035628499107,51.49903186094829,57.33938124086173,62.86480633047945,12.459491615988531,5.798652357904905,8.820540447512919,12.283538550311919,15.92845457407308,19.352538482690676 -1,2021.0,3,6.358169926160383,3.628273143748942,4.9817810983963025,6.4095722719355175,7.869016332110254,9.096245139748284,Female,4029.792036564231,32928.96204758463,43.70137275997164,30.84809123758809,37.11226533062855,43.988533616061964,50.56598066677174,56.03053676919914,5179,50.53805418077025,37.243490472634775,44.22474460568375,51.09370375932314,57.53120675977421,62.770590715883095,14.04701417456372,7.4030205772276565,10.53885404455611,13.931236498750295,17.46641248429281,20.73730488406939 -1,2022.0,1,6.293650841000346,3.5839090016286526,4.927059121448485,6.349769049651194,7.74862918144081,9.035598225216004,Total,7948.4150475520655,64377.75445259256,44.53026525337737,31.75799178563973,38.13080180408613,44.79188124220524,51.178892766885824,56.94966476427934,10229,49.93275777995984,37.43976740702546,43.81447963299145,50.20872852793501,56.540055414197354,62.18382347303197,13.238357581033835,6.495279203367819,9.693363593242488,13.187615070581405,16.73899363655407,19.890913460129205 -1,2022.0,2,6.324123236066413,3.613071773136591,4.947314580888195,6.395960968641006,7.761272974382857,9.052628347102575,Male,3968.1250884304886,31607.967933859996,45.74096112915099,33.21553114329556,39.428650249293014,45.944026587606245,52.22385843245115,58.148153253494065,4998,50.36345072902722,37.95801858691046,44.324913141536236,50.73373828303752,56.73047444388101,62.532663713425066,12.569212498419171,5.90176300268141,9.015862432401995,12.412246484954931,16.089660961946002,19.281017627904834 -1,2022.0,3,6.2645357520039395,3.560229361472044,4.902320676067404,6.305692087614625,7.718545899370114,8.990748650275266,Female,3980.2899591215773,32769.786518732595,43.37349637799666,30.64865267556051,37.08991402693485,43.66828356934874,50.06582143993391,55.60839477426922,5231,49.521248821932936,37.08489202005658,43.39542920906328,49.806087361285,56.188180724666054,61.94825699847218,13.877697501299194,7.211986936460991,10.474659204645317,13.909785067507404,17.181848260973837,20.409619347642717 +1,2021.0,1,6.384879305983952,3.657871350532653,5.012502952738894,6.456401022079937,7.889469460407195,9.08121558845853,Total,8029.9693698885085,64736.29128337107,44.92542123163234,32.17720200308243,38.191163571856606,45.24773354068483,51.6664062868658,57.350483111892046,10139,50.77873170092831,38.024358743210264,44.77894786406224,51.25141308764901,57.4208618802088,62.8236170824407,13.270329483611711,6.516301023892368,9.66845187847887,13.130173928462328,16.808395124601887,20.13528325858139 +1,2021.0,2,6.412890721340803,3.685359185200582,5.050012888060346,6.509829088869624,7.922374812482872,9.068530105252165,Male,4000.2214823110617,31807.93797785047,46.20432714149043,33.51356828381646,39.64224868265374,46.47270338830948,52.62964434956375,58.45354323450649,4960,51.029938172931615,38.96875033249009,45.21036278677732,51.4990056171463,57.339265730601866,62.86410237014559,12.458854356892017,5.7965568458272,8.817467662244553,12.290223078645402,15.927658947627641,19.343136630082604 +1,2021.0,3,6.358052385696255,3.628273143748942,4.981798462421833,6.409614728347958,7.868101229636388,9.096243780415161,Female,4029.7478875774473,32928.35330552096,43.70059533611273,30.84874027375017,37.09476835145788,43.98847838161159,50.566127100495386,56.028308077049594,5179,50.53814778489502,37.243464151678985,44.22467190988386,51.09399998744856,57.537493733419204,62.770609193476304,14.047490446834278,7.4029615575016265,10.53646443425393,13.931323858820395,17.46640787229884,20.737304928114852 +1,2022.0,1,6.292892208382854,3.578717101751178,4.9231853874403475,6.3509672337871805,7.751655872052609,9.033018809914548,Total,7953.202601731116,64432.92332163207,44.51892200815233,31.753466412842137,38.1168415078142,44.7701220251022,51.16903600491321,56.955634643948834,10239,49.91850114224646,37.456446427207354,43.81016739992915,50.208194299705106,56.46862813522558,62.168197478083286,13.246673652527797,6.497160430496873,9.698872554540221,13.193856997171174,16.750708890049708,19.928551784931297 +1,2022.0,2,6.324827027488373,3.6148873254975094,4.959470076373945,6.393653564342233,7.761593701649885,9.046321909934218,Male,3972.1433538855276,31662.084099606705,45.71392092731498,33.17160536017505,39.34265681666417,45.916282352601414,52.22583053488225,58.13603987906013,5006,50.3521986517754,37.955091043425746,44.28003308402822,50.74432948380513,56.70515445009135,62.49041753563044,12.580403107504928,5.884572478359062,9.024057691118923,12.424419958089775,16.096740017689445,19.353012601981845 +1,2022.0,3,6.262342675716653,3.5420545428538017,4.8860107901742715,6.310797013167998,7.728303700507418,8.991624420737564,Female,3981.059247845589,32770.83922202525,43.375760420281466,30.66280246862488,37.09359835840321,43.652766294916994,50.05605484383841,55.59834857059093,5233,49.50361680578518,37.08682470178726,43.396129219944406,49.78180210203683,56.16223287132432,61.93999193933281,13.884042341307557,7.216884806401925,10.47423843496062,13.913800366705514,17.197002876892917,20.442579206092397 2,2019.0,1,6.741525188417298,3.33,5.0,8.0,8.33,8.33,Total,8309.653749245777,67981.5400000033,47.24261106703689,32.39,41.23,49.47,54.79,57.49,10084,51.23513883379611,37.435,47.9725,54.51,57.49,59.79,11.779055930186423,6.0,8.0,11.0,14.0,20.0 2,2019.0,2,6.714190611088631,3.33,5.0,7.0,8.33,8.33,Male,4166.189751478453,33181.530000000865,48.37145285309591,34.25,43.31,51.0,55.7025,58.15,4942,51.781602590044514,39.53,49.0,54.77,57.47,59.37,11.115944961554007,6.0,7.0,10.0,12.0,18.0 2,2019.0,3,6.767796577207312,3.33,5.0,8.33,8.33,8.33,Female,4143.463997767325,34800.01000000123,46.157676001555814,30.77,39.73,48.355000000000004,54.2,57.33,5142,50.70992998833139,35.3,46.65,54.33,57.75,60.09899999999998,12.416374951380794,6.0,8.0,11.0,15.0,21.0 2,2020.0,1,6.540949714036444,3.6852231226651355,5.150099835389495,6.675182731341655,8.090774730250459,9.346128825916193,Total,8092.283633362109,65815.03602263475,45.76964601737298,32.6968812114569,39.48439252058364,46.26304400824915,52.660740978043876,58.05587448509347,10062,51.061516761459536,38.24790379908255,45.58481838325366,52.0063402942549,57.82246809595494,62.52571245286481,12.8710807363802,6.1959161218239265,9.173436142265427,12.523017836531437,16.235895544902366,19.87470149183813 2,2020.0,2,6.566188099692085,3.7302238231361327,5.229079538680326,6.660505290192928,8.094025793670758,9.348232921345122,Male,4052.6649141247544,32397.57208388081,47.050027846263355,34.47802514308085,41.102242818228994,47.48107747800515,53.684846374668325,59.01992217235703,4934,51.47147762812734,39.37692445278696,46.13480080113773,52.30704097421855,58.01657251436907,62.5319463480464,12.179346319601786,5.66695694709504,8.610036896995732,11.85368728136092,15.38998134882099,19.03182910147219 2,2020.0,3,6.516666134702408,3.6434314736838473,5.064899028575013,6.683287107755065,8.084884909002417,9.346488738221423,Female,4039.618719237354,33417.46393875399,44.53770297062081,31.420326256395327,38.085562605848175,45.08024416249953,51.463810245208286,56.9169194780454,5128,50.66706533475538,36.77780045421139,45.044292136902875,51.76406816859323,57.633616830015434,62.503675831082965,13.536645793397497,6.824722784004164,9.729529483275837,13.219784109429465,16.965017312876903,20.518571823343187 -2,2021.0,1,6.392531972412021,3.6564543649168844,5.017927442053093,6.469778138609839,7.905901487839022,9.099014557443624,Total,8019.958011692754,64717.99368869933,44.94208048194549,32.245517800487555,38.27496654752627,45.2947150707601,51.66607302584889,57.361185228245304,10124,50.78396842263172,38.02661239804755,44.76354797851376,51.30825510736786,57.39843448062286,62.86095934778808,13.280978858743628,6.579848363008235,9.669538345827917,13.163269257301328,16.806241111333858,20.102381423210176 -2,2021.0,2,6.416909223384138,3.6928375984308395,5.0575610571609095,6.505088755685854,7.92812572539924,9.08332048740751,Male,3995.161941219114,31789.36829264508,46.21994399391517,33.66594446255509,39.65529588846737,46.517962951138756,52.64094002454712,58.43821587026359,4954,51.0099295920603,38.982363491361426,45.191393757599926,51.46397107046306,57.307583497750684,62.853468709262756,12.50682090763736,5.867211376754124,8.913750112063607,12.346543226576227,15.90587299413187,19.382289103554037 -2,2021.0,3,6.369173190726166,3.605898715002645,4.985071888094175,6.435191811133754,7.890183579095658,9.1208390597757,Female,4024.79607047364,32928.625396054274,43.71760546486661,30.88996709764635,37.181129805403586,44.00602136149024,50.56675567753466,56.03736332581279,5170,50.5674477972257,37.21974296123046,44.255105035653585,51.17763381806225,57.54968127990403,62.89339545121879,14.022792879977757,7.374135727852362,10.522381160389763,13.923968463305044,17.44512565984127,20.65294160476254 -2,2022.0,1,6.277772502313605,3.5671519556240714,4.915071125870329,6.326315430506572,7.719431339529499,9.011723829236749,Total,7948.148165564994,64183.94606365432,44.55570884767418,31.822396553651743,38.19923721335598,44.80562282042183,51.24922312037055,56.934013977162635,10224,49.93545249821693,37.41544486304984,43.813831131783516,50.20719683949365,56.56151827511016,62.250277102041004,13.260906841598404,6.60231698784964,9.756285418057743,13.164231247786592,16.713694984589917,19.938306799487577 -2,2022.0,2,6.295867022325366,3.610184921012878,4.934074094082508,6.33199449747446,7.719923234235579,9.03250881682148,Male,3972.320189881784,31504.518579716158,45.7318143629376,33.23142683069024,39.339300768969814,45.93445165216778,52.30556884062537,57.97628543098898,5004,50.33692715979863,37.924307943873714,44.27980180830151,50.70942544774555,56.70401999647539,62.41132347794596,12.626128598169526,6.006959710921459,9.14393363116356,12.478213982191203,16.08153140383468,19.314433777557657 -2,2022.0,3,6.26042672106095,3.5330890887460686,4.8909690527517,6.315143636530178,7.719431339529499,8.98735998336115,Female,3975.8279756832103,32679.427483938296,43.42826976752512,30.603287417865765,37.13337824083931,43.7541212181674,50.16111650476772,55.635757121796566,5220,49.550590581252415,36.98079907428182,43.395828673587104,49.812244421870375,56.37718315716788,62.09617748855787,13.869418399092293,7.258308055695878,10.447920884733712,13.838162382484494,17.156085883789913,20.475677248160896 \ No newline at end of file +2,2021.0,1,6.3926170900966595,3.6562520208564147,5.017786561513933,6.468926070123672,7.905095848951531,9.09937237384019,Total,8020.088839207434,64718.85542013845,44.942739351181324,32.24527114825335,38.29789446199977,45.29472218310011,51.66612685039066,57.36156903880688,10124,50.78439392499128,38.02609455737263,44.76355873785468,51.30650537770802,57.403395787395354,62.86094478608264,13.280436274981275,6.57964578894508,9.665580347832767,13.159613054626465,16.806214366385728,20.09990776796186 +2,2021.0,2,6.417154657414023,3.6888055943941125,5.055711068460088,6.505067873102327,7.928381714825241,9.083265269975907,Male,3995.249883031219,31790.584172829094,46.22100255275973,33.66064953285322,39.655222586686236,46.515145340394,52.64106052166581,58.44404314231376,4954,51.01047267276506,38.97764073290038,45.191401669201014,51.46402351498751,57.307558397809316,62.853761430358134,12.506094513042642,5.864966219819999,8.908982308505687,12.346748689030932,15.905854184670254,19.377914872511433 +2,2021.0,3,6.369104690001839,3.6059053803864223,4.985206520070877,6.434073704059616,7.886960352137257,9.120856702517733,Female,4024.8389561762156,32928.27124730954,43.717881343324564,30.890016236630263,37.1823976474046,43.99623191872728,50.56688021593018,56.03768456187958,5170,50.56776063360417,37.219937936756466,44.25612746992009,51.177382132698824,57.55207237397079,62.892657201013535,14.022426427523632,7.382448328766508,10.523299887913891,13.9222862171448,17.445129722891803,20.65305118285963 +2,2022.0,1,6.279206680429553,3.5696793689957045,4.916079067771468,6.328880603234933,7.7201999434648565,9.009064546714411,Total,7933.49026917511,64098.141793824674,44.54735758796844,31.791103136257163,38.17044009366954,44.79929958322753,51.24908219719499,56.96511582430976,10208,49.92536438046665,37.41719989192662,43.79104929665941,50.22315185431776,56.560737289497155,62.243929389961394,13.255765848857228,6.5899194157957695,9.74525669713356,13.164878677304474,16.708529564225113,19.93916960294297 +2,2022.0,2,6.296957812385085,3.6090429950200487,4.933833508043516,6.344060958507989,7.713626029206429,9.030261088066881,Male,3960.002614727677,31428.116441613995,45.718512535600425,33.22710700365567,39.31649153857018,45.92097641410677,52.299331952714375,58.00362283825078,4991,50.31441859368968,37.90134524293881,44.23617282860287,50.69471550425454,56.688336063600595,62.37667784859398,12.605825055102331,5.977783699781755,9.133267696120084,12.459474069269936,16.068278182085546,19.29183883917292 +2,2022.0,3,6.262224526013211,3.5336118176987776,4.893273836000972,6.311792599788577,7.728303700507418,8.987368468812326,Female,3973.487654447433,32670.025352210974,43.426936973893056,30.553431765007264,37.101618554291235,43.74475448254485,50.15291362217008,55.68365605030192,5217,49.553163962947735,36.978055349766635,43.396129219944406,49.82948355331851,56.39632444709198,62.102300176862045,13.877551262242449,7.254622942891149,10.446287558280993,13.8445519935073,17.166090055368645,20.495353140178704 diff --git a/src/test/java/simpaths/model/ConsumptionRegressionTest.java b/src/test/java/simpaths/model/ConsumptionRegressionTest.java new file mode 100644 index 000000000..d330f476f --- /dev/null +++ b/src/test/java/simpaths/model/ConsumptionRegressionTest.java @@ -0,0 +1,132 @@ +package simpaths.model; + +import com.opencsv.CSVReader; +import microsim.data.excel.ExcelAssistant; +import microsim.statistics.regression.LinearRegression; +import org.junit.jupiter.api.Test; +import simpaths.data.Parameters; +import simpaths.model.enums.Les_c4; + +import java.io.InputStreamReader; +import java.lang.reflect.Field; +import java.nio.charset.StandardCharsets; +import java.util.*; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +class ConsumptionRegressionTest { + private static final String[] AGE_NAMES = {"Age20to24", "Age25to29", "Age30to34", "Age35to39", + "Age40to44", "Age45to49", "Age50to54", "Age55to59", "Age60to64", "Age65to69", + "Age70to74", "Age75to79", "Age80plus"}; + + private BenefitUnit unit(int age, boolean student, int year, double income, + Map controls) throws Exception { + BenefitUnit bu = mock(BenefitUnit.class); + Person ref = mock(Person.class); + when(ref.getDemAge()).thenReturn(age); + when(ref.getLabC4()).thenReturn(student ? Les_c4.Student : Les_c4.NotEmployed); + when(bu.getRefPerson()).thenReturn(ref); + when(bu.getYear()).thenReturn(year); + Field field = BenefitUnit.class.getDeclaredField("yDispMonth"); + field.setAccessible(true); + field.set(bu, income); + doAnswer(inv -> { + String name = ((Enum) inv.getArgument(0)).name(); + if (name.startsWith("Age") || name.equals("LnDispInc") || name.equals("LnDispInc_sq") + || name.equals("ReferenceAdultStudent") || name.equals("Year") || name.equals("YearFrom2015") + || name.equals("Constant")) + return inv.callRealMethod(); + Double value = controls.get(name); + if (value == null) throw new AssertionError("Unmapped fixture regressor " + name); + return value; + }).when(bu).getDoubleValue(any(Enum.class)); + return bu; + } + + @Test + void predictionsMatchFullPrecisionStataConsumptionModel() throws Exception { + LinearRegression regression = new LinearRegression(ExcelAssistant.loadCoefficientMap( + System.getProperty("simpaths.consumption.coefficients", + "input/regression_files/reg_wealth_financial.xlsx"), "FW1a", 1)); + Object rmseValue = ExcelAssistant.loadCoefficientMap( + System.getProperty("simpaths.consumption.rmse", + "input/regression_files/reg_RMSE.xlsx"), "UK", 1).getValue("FW1a"); + assertInstanceOf(Number.class, rmseValue); + double rmse = ((Number) rmseValue).doubleValue(); + boolean oldFix = Parameters.isFixTimeTrend; + Integer oldStop = Parameters.timeTrendStopsIn; + try { + Parameters.isFixTimeTrend = true; + Parameters.timeTrendStopsIn = 2023; + try (CSVReader reader = new CSVReader(new InputStreamReader(Objects.requireNonNull( + getClass().getResourceAsStream("/simpaths/model/consumption_stata_fixtures.csv")), StandardCharsets.UTF_8))) { + String[] header = reader.readNext(); + String[] row; + int count = 0; + while ((row = reader.readNext()) != null) { + Map data = new HashMap<>(); + for (int i=0; i controls = new HashMap<>(); + controls.put("SingleFemale", data.get("single_female_adult")); + controls.put("SingleMale", data.get("single_male_adult")); + controls.put("NumberMembersUnder18", data.get("nk")); + controls.put("NumberFullTimeWork", data.get("ft")); + controls.put("NumberPartTimeWork", data.get("pt")); + controls.put("NumberSelfEmployed", data.get("semp")); + controls.put("PrivatePensionIncome", data.get("pen_inc_any")); + controls.put("MortgageHolder", data.get("housing_status")==1.0 ? 1.0 : 0.0); + controls.put("HomeOwnedOutright", data.get("housing_status")==2.0 ? 1.0 : 0.0); + String[] regions = {"UKC","UKD","UKE","UKF","UKG","UKH","UKI","UKJ","UKK","UKL","UKM","UKN"}; + for (int i=0;i=lower && (i==12 || age=65 +gen byte ft=(!student & !pen_inc_any & mod(_n,3)==0)+(na==2) +gen byte pt=!student & !pen_inc_any & mod(_n,3)==1 +gen byte semp=!student & !pen_inc_any & mod(_n,3)==2 +gen byte housing_status=mod(floor((_n-1)/7),3) +gen byte gorx=mod(floor((_n-1)/3),12)+1 + +* Match Java's GBP1 monthly floor, double square and 2023 trend freeze. +gen double ln_disp_inc=ln(max(income_month,1)) +gen double ln_disp_inc2=ln_disp_inc^2 +gen int actual_year=year +gen double year_c2015=min(year,2023)-2015 +* 2023 is the omitted annual indicator, so it also represents future years' +* all-zero indicator vector while their centred trend remains frozen at 8. +replace year=2023 if actual_year>2023 +estimates use `"`estimates_file'"' +predict double stata_xb, xb +gen double stata_rmse=e(rmse) +gen double stata_mean_month=exp(stata_xb+stata_rmse^2/2) +replace year=actual_year +keep student age nk ft pt semp pen_inc_any gorx year age_group housing_status /// + single_female_adult single_male_adult income_month stata_xb stata_rmse stata_mean_month +assert _N==700 +assert !missing(stata_xb,stata_rmse,stata_mean_month) +format stata_xb income_month stata_mean_month stata_rmse %24.17g +export delimited using `"`output_file'"', replace datafmt nolabel