diff --git a/Conception rates by age and country updated.xlsx b/Conception rates by age and country updated.xlsx index 4914d3d..eb4bb61 100644 Binary files a/Conception rates by age and country updated.xlsx and b/Conception rates by age and country updated.xlsx differ diff --git a/Conception rates by age and country.xlsx b/Conception rates by age and country.xlsx index 97c8ade..35da8c0 100644 Binary files a/Conception rates by age and country.xlsx and b/Conception rates by age and country.xlsx differ diff --git a/Data/its_outputs.xlsx b/Data/its_outputs.xlsx new file mode 100644 index 0000000..ac1b9af Binary files /dev/null and b/Data/its_outputs.xlsx differ diff --git a/Data/its_outputs/model 1.xlsx b/Data/its_outputs/model 1.xlsx new file mode 100644 index 0000000..02e19fd Binary files /dev/null and b/Data/its_outputs/model 1.xlsx differ diff --git a/Data/its_outputs/model 10.xlsx b/Data/its_outputs/model 10.xlsx new file mode 100644 index 0000000..03bea0c Binary files /dev/null and b/Data/its_outputs/model 10.xlsx differ diff --git a/Data/its_outputs/model 2.xlsx b/Data/its_outputs/model 2.xlsx new file mode 100644 index 0000000..8fe6390 Binary files /dev/null and b/Data/its_outputs/model 2.xlsx differ diff --git a/Data/its_outputs/model 3.xlsx b/Data/its_outputs/model 3.xlsx new file mode 100644 index 0000000..4f59729 Binary files /dev/null and b/Data/its_outputs/model 3.xlsx differ diff --git a/Data/its_outputs/model 4.xlsx b/Data/its_outputs/model 4.xlsx new file mode 100644 index 0000000..251808d Binary files /dev/null and b/Data/its_outputs/model 4.xlsx differ diff --git a/Data/its_outputs/model 5.xlsx b/Data/its_outputs/model 5.xlsx new file mode 100644 index 0000000..6dc2bc4 Binary files /dev/null and b/Data/its_outputs/model 5.xlsx differ diff --git a/Data/its_outputs/model 6.xlsx b/Data/its_outputs/model 6.xlsx new file mode 100644 index 0000000..5cfacaf Binary files /dev/null and b/Data/its_outputs/model 6.xlsx differ diff --git a/Data/its_outputs/model 7.xlsx b/Data/its_outputs/model 7.xlsx new file mode 100644 index 0000000..62d237e Binary files /dev/null and b/Data/its_outputs/model 7.xlsx differ diff --git a/Data/its_outputs/model 8.xlsx b/Data/its_outputs/model 8.xlsx new file mode 100644 index 0000000..8aaad5b Binary files /dev/null and b/Data/its_outputs/model 8.xlsx differ diff --git a/Data/its_outputs/model 9.xlsx b/Data/its_outputs/model 9.xlsx new file mode 100644 index 0000000..451c278 Binary files /dev/null and b/Data/its_outputs/model 9.xlsx differ diff --git a/Data/under-18-birth-rates.csv b/Data/under-18-birth-rates.csv new file mode 100644 index 0000000..c7dd891 --- /dev/null +++ b/Data/under-18-birth-rates.csv @@ -0,0 +1,385 @@ +Code,Country,Year,rate,GDPperCap,MF_ratio,MobilePhones,UrbanPop +5,Denmark,1990,2.936693803,26891.44164,1.041253113,2.883032183,84.843 +5,Denmark,1991,2.648832447,27011.38589,1.038915294,3.413116199,84.871 +5,Denmark,1992,3.080488629,29569.65453,1.042190141,4.081153984,84.898 +5,Denmark,1993,2.901617047,27597.97148,1.044844088,6.888976566,84.925 +5,Denmark,1994,2.710888028,29995.56522,1.050384395,9.661633662,84.952 +5,Denmark,1995,2.185780465,35351.38071,1.045651276,15.71394063,84.979 +5,Denmark,1996,2.300961315,35650.72434,1.044824496,25.05474932,85.006 +5,Denmark,1997,2.342109514,32835.92877,1.040358124,27.36064934,85.033 +5,Denmark,1998,2.496088665,33368.15485,1.041896072,36.4332626,85.06 +5,Denmark,1999,2.333679064,33440.80162,1.041450585,49.39302195,85.086 +5,Denmark,2000,2.358402741,30743.55917,1.045194444,62.97378451,85.1 +5,Denmark,2001,2.059403999,30751.64946,1.04111453,73.91039895,85.15 +5,Denmark,2002,1.537581349,33228.69291,1.046806837,83.34111016,85.25 +5,Denmark,2003,1.641978759,40458.77064,1.052554966,88.4931932,85.36 +5,Denmark,2004,1.850380293,46511.60457,1.059075945,95.63465791,85.566 +5,Denmark,2005,1.944285777,48799.82037,1.057900171,100.5072946,85.856 +5,Denmark,2006,1.86937603,52026.99311,1.056176334,107.0505628,86.098 +5,Denmark,2007,1.665005088,58487.04501,1.053064329,115.3208334,86.293 +5,Denmark,2008,1.95980402,64322.06664,1.055464454,119.2657784,86.487 +5,Denmark,2009,1.679170431,58163.29359,1.053487961,123.654185,86.654 +5,Denmark,2010,1.599877375,58041.41122,1.051981645,115.5890246,86.795 +5,Denmark,2011,1.425462563,61753.66007,1.052143421,128.4855486,86.957 +5,Denmark,2012,1.293501108,58507.50021,1.052776747,129.9803588,87.142 +5,Denmark,2013,1.160081592,61191.19263,1.056292959,124.714087,87.292 +12,England and Wales,1990,16.3858363,19095.467,1.053864925,1.948120161,78.14 +12,England and Wales,1991,16.38428455,19900.72665,1.053285156,2.197440097,78.112 +12,England and Wales,1992,15.89954599,20487.17079,1.05050874,2.621118549,78.172 +12,England and Wales,1993,16.18439056,18389.01957,1.047853986,3.934052718,78.232 +12,England and Wales,1994,15.07830928,19709.2381,1.04664994,6.815338962,78.293 +12,England and Wales,1995,15.28526949,23013.45882,1.044455728,9.892982241,78.353 +12,England and Wales,1996,16.83279319,24219.62285,1.042036491,12.46348124,78.413 +12,England and Wales,1997,16.88539648,26621.48006,1.041226006,15.15253492,78.472 +12,England and Wales,1998,16.79017363,28014.8947,1.0417628,25.41295714,78.532 +12,England and Wales,1999,16.0922518,28383.66891,1.044904988,46.27491764,78.591 +12,England and Wales,2000,15.17221575,27982.35576,1.050177687,73.70886336,78.651 +12,England and Wales,2001,14.41883733,27427.5875,1.054994929,78.24769922,78.751 +12,England and Wales,2002,13.9722645,29785.98629,1.055222741,82.94670337,79.047 +12,England and Wales,2003,13.73635445,34173.97998,1.046666403,91.06414709,79.339 +12,England and Wales,2004,13.64477963,39983.98467,1.035899623,99.67234557,79.629 +12,England and Wales,2005,13.20783327,41732.64054,1.034381551,108.6004149,79.915 +12,England and Wales,2006,12.96765627,44252.31582,1.043590786,115.254437,80.199 +12,England and Wales,2007,12.35622681,50134.3161,1.049494313,120.2257083,80.479 +12,England and Wales,2008,12.18888302,46767.59222,1.045263607,120.7240644,80.757 +12,England and Wales,2009,11.5851316,38262.18213,1.041477829,121.9353861,81.031 +12,England and Wales,2010,10.80805263,38893.01849,1.046716218,121.2030538,81.302 +12,England and Wales,2011,9.512228668,41412.34924,1.05496036,120.9215205,81.57 +12,England and Wales,2012,9.181896507,41790.77914,1.057163906,121.9127668,81.837 +12,England and Wales,2013,7.927749284,42724.06788,1.056468622,121.7088908,82.102 +8,Finland,1990,4.22463483,28380.54891,1.051748883,5.161339908,79.367 +8,Finland,1991,4.269978594,25503.21521,1.049745808,6.358419047,79.843 +8,Finland,1992,4.112180061,22337.48712,1.046922582,7.651669747,80.128 +8,Finland,1993,3.612217246,17617.03044,1.048943454,9.644999033,80.409 +8,Finland,1994,2.891054085,20305.58355,1.045800106,13.25391689,80.688 +8,Finland,1995,2.9109196,26273.4659,1.040544206,20.29937459,80.963 +8,Finland,1996,3.231306837,25777.6413,1.042943752,29.23903329,81.223 +8,Finland,1997,2.565612382,24676.49708,1.041817379,41.97749656,81.466 +8,Finland,1998,2.6458108,25989.4075,1.051189783,55.10944297,81.707 +8,Finland,1999,2.770608697,26178.79178,1.049291536,63.24342736,81.946 +8,Finland,2000,3.56131121,24253.25042,1.048371105,71.87081844,82.183 +8,Finland,2001,3.592212084,24913.24452,1.042696006,80.29235384,82.368 +8,Finland,2002,3.776658768,26834.02625,1.043754232,86.6381899,82.503 +8,Finland,2003,3.355061266,32816.16088,1.046412171,90.81753315,82.638 +8,Finland,2004,3.399038305,37636.11173,1.047292384,95.15116311,82.772 +8,Finland,2005,2.98966867,38969.17163,1.044961605,100.2105563,82.905 +8,Finland,2006,2.971675568,41120.67651,1.044782943,107.4358085,83.037 +8,Finland,2007,2.777777778,48288.5491,1.042510288,114.7599836,83.168 +8,Finland,2008,2.362148846,53401.31487,1.042143574,128.3858236,83.299 +8,Finland,2009,2.126036316,47107.15571,1.038533137,144.1233426,83.429 +8,Finland,2010,2.290752487,46202.41516,1.037578522,156.361179,83.77 +8,Finland,2011,1.792356068,50790.72415,1.037059293,165.8860374,84.313 +8,Finland,2012,2.107582,47415.55987,1.041749187,172.178726,84.841 +8,Finland,2013,1.939462616,49638.07713,1.041208133,136.3200932,85.125 +9,France,1990,4.229987153,21690.62912,1.049749544,0.497183723,74.056 +9,France,1991,4.219142408,21675.06425,1.047909151,0.655162571,74.229 +9,France,1992,4.167623945,23813.71184,1.049630662,0.759518231,74.401 +9,France,1993,3.881482946,22380.10396,1.048952457,0.990565041,74.572 +9,France,1994,3.652478592,23496.52332,1.048614674,1.522658967,74.743 +9,France,1995,3.498526485,26890.21988,1.047554145,2.236359799,74.912 +9,France,1996,3.553821612,26871.82902,1.045825733,4.20976597,75.082 +9,France,1997,3.560300716,24228.94235,1.048090232,9.899530141,75.25 +9,France,1998,3.537208072,24974.2722,1.048284204,18.9889303,75.417 +9,France,1999,3.7075089,24673.19897,1.048101215,36.13436735,75.614 +9,France,2000,3.960668654,22364.02939,1.042317732,48.73886397,75.871 +9,France,2001,4.30149922,22433.55571,1.03952957,61.75367525,76.127 +9,France,2002,3.95595145,24177.33517,1.040410014,64.06849532,76.38 +9,France,2003,3.812815731,29568.38595,1.041528011,68.87189627,76.632 +9,France,2004,3.842327323,33741.26515,1.043872609,73.1589461,76.883 +9,France,2005,3.609053554,34760.18777,1.043641694,78.53166302,77.13 +9,France,2006,3.622360596,36443.62344,1.0444061,83.87657249,77.377 +9,France,2007,3.657331648,41508.43269,1.049049801,89.34353008,77.621 +9,France,2008,3.63698422,45334.11091,1.049314789,93.00882838,77.868 +9,France,2009,3.622933927,41575.41618,1.047136371,92.39159417,78.117 +9,France,2010,3.664455414,40638.334,1.048489259,91.68330775,78.369 +9,France,2011,3.578615524,43790.7354,1.050471289,94.43104231,78.622 +9,France,2012,3.834494606,40874.71596,1.047506678,97.83174772,78.878 +9,France,2013,3.544100742,42592.95152,1.049654924,99.06771312,79.135 +4,Germany,1990,7.07019383,22219.57253,1.053650696,0.344558605,73.118 +4,Germany,1991,7.307153886,23269.3818,1.054610568,0.668955763,73.269 +4,Germany,1992,6.990941134,26333.53744,1.053800295,1.214161974,73.36 +4,Germany,1993,6.206254991,25488.51952,1.057589067,2.203646375,73.497 +4,Germany,1994,5.808149844,27087.55845,1.056168484,3.077311214,73.71 +4,Germany,1995,5.537837953,31729.69976,1.05431331,4.585145625,73.922 +4,Germany,1996,5.699682126,30564.24781,1.051433866,6.769308559,74.133 +4,Germany,1997,5.646703933,27045.71913,1.049313479,10.15461792,74.342 +4,Germany,1998,5.605228803,27340.67288,1.04987561,17.07132651,74.551 +4,Germany,1999,5.680696533,26795.99113,1.052213549,28.77459027,74.758 +4,Germany,2000,5.799580296,23718.7467,1.052993531,59.15244421,74.965 +4,Germany,2001,6.161390967,23687.31689,1.050496094,68.83597997,75.17 +4,Germany,2002,6.177532047,25205.16445,1.050573912,72.45024706,75.374 +4,Germany,2003,5.757320915,30359.95215,1.050860428,79.32767834,75.577 +4,Germany,2004,5.348789507,34165.93403,1.052054598,87.280701,75.779 +4,Germany,2005,5.076440603,34696.62092,1.051570858,97.06110232,75.98 +4,Germany,2006,4.752998169,36447.87232,1.049922602,105.042469,76.179 +4,Germany,2007,4.655167512,41814.8191,1.048165213,118.3029902,76.378 +4,Germany,2008,4.694325646,45699.19832,1.047886059,130.0651266,76.575 +4,Germany,2009,4.219610865,41732.70725,1.048310743,129.6846864,76.771 +4,Germany,2010,4.1560978,41785.55691,1.050039747,109.2777489,76.966 +4,Germany,2011,3.856220838,46810.32796,1.052862374,112.3137649,77.16 +4,Germany,2012,3.811152869,44065.24891,1.054127938,113.9808799,77.17 +4,Germany,2013,3.705923199,46530.91143,1.054117133,123.0958333,77.18 +14,Iceland,1990,13.20754717,25008.84946,1.050786164,3.924828362,90.75 +14,Iceland,1991,13.41305753,26405.91589,1.051228184,5.003027668,90.932 +14,Iceland,1992,11.62409954,26722.44119,1.043876883,5.86236455,91.112 +14,Iceland,1993,9.58677686,23230.4718,1.030909091,6.628061038,91.287 +14,Iceland,1994,9.563758389,23662.80668,1.040771812,8.239105673,91.46 +14,Iceland,1995,10.92985318,26239.0273,1.033115824,11.53948189,91.63 +14,Iceland,1996,8.781558727,27261.17166,1.0439077939999999,17.32555987,91.797 +14,Iceland,1997,10.95848125,27842.61347,1.054638061,23.96987265,91.96 +14,Iceland,1998,11.08162947,30847.6437,1.065085063,37.87922818,92.121 +14,Iceland,1999,9.835025381,32148.15015,1.055203046,62.12041602,92.267 +14,Iceland,2000,7.998720205,31746.02314,1.043353064,76.62952199,92.401 +14,Iceland,2001,8.123476848,28551.78527,0.998537774,87.70762123,92.532 +14,Iceland,2002,7.08143652,32024.1856,1.013319845,91.27638621,92.662 +14,Iceland,2003,6.105834464,39086.77319,1.038331072,97.12382619,92.789 +14,Iceland,2004,3.411306043,46984.06654,1.078135153,99.64411344,92.914 +14,Iceland,2005,4.329004329,56250.68281,1.069882498,95.97564572,93.037 +14,Iceland,2006,4.795814562,56121.32242,1.048684784,100.731997,93.159 +14,Iceland,2007,6.130491899,68428.34821,1.043789228,106.8473132,93.278 +14,Iceland,2008,4.35413643,55632.10432,1.062264151,108.3754712,93.395 +14,Iceland,2009,5.062924924,40640.9902,1.053667004,107.4754972,93.511 +14,Iceland,2010,5.478662053,41851.73548,1.0455594,106.4774231,93.574 +14,Iceland,2011,3.25732899,46181.95294,1.04693515,106.3901824,93.587 +14,Iceland,2012,3.947168666,44562.81802,1.059814787,108.167704,93.6 +14,Iceland,2013,2.955818295,48023.62691,1.067828251,108.9395742,93.633 +15,Italy,1990,3.461951557,20757.08868,1.042517348,0.465628234,66.726 +15,Italy,1991,3.051377852,21884.10437,1.039554258,0.993832013,66.706 +15,Italy,1992,2.903478314,23166.80406,1.038336824,1.369147121,66.742 +15,Italy,1993,3.20929561,18676.95258,1.038839114,2.109463097,66.802 +15,Italy,1994,3.067498228,19273.84417,1.039587725,3.912570332,66.862 +15,Italy,1995,3.081843803,20596.38858,1.040652624,6.851780239,66.922 +15,Italy,1996,3.054853849,23020.09994,1.043026763,11.22145209,66.982 +15,Italy,1997,3.101870493,21779.62437,1.04368579,20.52622947,67.042 +15,Italy,1998,2.743918665,22252.35809,1.044070044,35.84903924,67.102 +15,Italy,1999,3.047042903,21936.82313,1.046628232,52.98357088,67.162 +15,Italy,2000,3.038040593,20051.24215,1.049787902,73.73582875,67.222 +15,Italy,2001,2.92762033,20400.81111,1.050952991,89.11361067,67.282 +15,Italy,2002,2.820059782,22196.50675,1.050951465,93.76876619,67.382 +15,Italy,2003,2.973014825,27387.22632,1.053222987,97.63180194,67.501 +15,Italy,2004,3.149007738,31174.56109,1.057353975,107.2746688,67.62 +15,Italy,2005,3.034289994,31959.26295,1.057649162,121.5810991,67.738 +15,Italy,2006,2.776326498,33410.74744,1.056837545,136.1174311,67.856 +15,Italy,2007,2.74313976,37698.78665,1.056961374,151.4005806,67.974 +15,Italy,2008,2.931116079,40640.18386,1.057653164,151.8275276,68.092 +15,Italy,2009,2.85501221,36976.84553,1.059491597,150.9558833,68.209 +15,Italy,2010,2.628636814,35849.3732,1.061784715,156.8163246,68.327 +15,Italy,2011,2.610271035,38334.68385,1.065974499,160.7112234,68.444 +15,Italy,2012,2.581899313,34814.12512,1.066763103,162.7028059,68.684 +15,Italy,2013,2.329876536,35370.27526,1.065258509,162.3367752,68.979 +17,Netherlands,1990,3.239101064,21019.12567,1.041483507,0.527882627,68.684 +17,Netherlands,1991,3.18215272,21454.86289,1.044884556,0.763383152,69.329 +17,Netherlands,1992,2.905558542,23598.95076,1.050380642,1.094563567,70.223 +17,Netherlands,1993,2.569605828,22827.30004,1.049547134,1.414723049,71.1 +17,Netherlands,1994,2.659402563,24331.75402,1.050680402,2.088603642,71.962 +17,Netherlands,1995,2.19074047,28884.71352,1.046990447,3.484646962,72.809 +17,Netherlands,1996,2.01239272,28698.66602,1.049570879,6.528197347,73.64 +17,Netherlands,1997,2.188863464,26404.98673,1.047357501,10.96740917,74.453 +17,Netherlands,1998,2.32677875,27533.60679,1.049373597,21.28207244,75.25 +17,Netherlands,1999,2.628356312,27951.73429,1.049632732,42.59701432,76.03 +17,Netherlands,2000,3.033424538,25921.12794,1.054380267,67.53028408,76.795 +17,Netherlands,2001,3.45745802,26584.12169,1.052916314,76.16377309,77.83 +17,Netherlands,2002,2.998020399,28817.32321,1.049945489,75.10697312,79.113 +17,Netherlands,2003,2.698738447,35245.16407,1.050022841,81.4766985,80.341 +17,Netherlands,2004,2.323928449,39954.64222,1.048551639,90.86900361,81.514 +17,Netherlands,2005,2.130985117,41577.16009,1.047679306,96.74251327,82.63 +17,Netherlands,2006,1.946324363,44453.97119,1.046325391,105.205392,83.636 +17,Netherlands,2007,1.972086395,51241.31562,1.045861925,116.8288276,84.539 +17,Netherlands,2008,1.809125177,56928.82048,1.04881127,124.4935189,85.402 +17,Netherlands,2009,1.947832792,51900.34009,1.046590667,121.1829535,86.288 +17,Netherlands,2010,1.651597964,50338.25483,1.048550169,114.9619098,87.134 +17,Netherlands,2011,1.620765009,53540.60536,1.047621178,118.4758716,87.879 +17,Netherlands,2012,1.627270578,49474.70561,1.051903391,117.4393259,88.588 +17,Netherlands,2013,1.37160013,51574.48942,1.049005714,115.6018288,89.187 +18,Norway,1990,5.126312122,28242.94374,1.044644802,4.6342075,71.956 +18,Norway,1991,4.738071745,28596.933,1.04290429,5.490680227,72.265 +18,Norway,1992,4.698356821,30523.98506,1.038959045,6.590703297,72.665 +18,Norway,1993,4.682447677,27963.66522,1.044725328,8.603688669,73.061 +18,Norway,1994,4.510521266,29315.84191,1.048736808,13.55435708,73.453 +18,Norway,1995,4.114902417,34875.19739,1.048959545,22.47094398,73.787 +18,Norway,1996,4.033413812,37321.44339,1.053826191,28.71352126,74.062 +18,Norway,1997,4.185446524,36628.51742,1.046593826,37.93356593,74.476 +18,Norway,1998,3.987407235,34788.77856,1.050745999,46.58811742,75.027 +18,Norway,1999,3.6275733,36371.39579,1.051634955,59.54397895,75.569 +18,Norway,2000,3.943608827,38146.71539,1.057445092,71.65452385,76.02 +18,Norway,2001,3.465666489,38549.58934,1.056065306,79.43587924,76.378 +18,Norway,2002,3.36915047,43061.15038,1.057005398,83.36964716,76.733 +18,Norway,2003,2.931985294,50111.65445,1.054140998,88.85634163,77.084 +18,Norway,2004,2.427604677,57570.26916,1.053970683,98.40233621,77.399 +18,Norway,2005,2.502725593,66775.3944,1.050965721,102.6355658,77.675 +18,Norway,2006,2.541421818,74114.69715,1.053605355,104.1909494,77.95 +18,Norway,2007,2.98407929,85170.86217,1.054366036,106.737833,78.234 +18,Norway,2008,3.007213706,97007.94189,1.06000687,109.2173612,78.526 +18,Norway,2009,2.607235142,80067.17664,1.059270026,110.925095,78.815 +18,Norway,2010,2.651169808,87770.26684,1.062989665,114.6014289,79.102 +18,Norway,2011,2.013645663,100711.2248,1.063611923,115.7218204,79.455 +18,Norway,2012,1.898791909,101668.1707,1.064572926,115.6722646,79.874 +18,Norway,2013,1.825607041,103059.2482,1.063178667,112.1122467,80.286 +20,Portugal,1990,12.33192779,7885.394019,1.025974116,0.065304797,47.915 +20,Portugal,1991,12.48815381,8959.867208,1.030088437,0.126325984,48.469 +20,Portugal,1992,11.46633197,10811.63064,1.031405661,0.37226352,49.13 +20,Portugal,1993,12.48831724,9535.594849,1.034385017,1.007459376,49.789 +20,Portugal,1994,11.72315432,9978.301937,1.033846245,1.717315573,50.449 +20,Portugal,1995,10.9668743,11782.52148,1.033042062,3.358166494,51.109 +20,Portugal,1996,11.16063518,12185.06389,1.033326518,6.511237694,51.77 +20,Portugal,1997,12.01984668,11578.44151,1.032898579,14.72662057,52.428 +20,Portugal,1998,11.6044135,12202.69141,1.033157754,29.93134148,53.086 +20,Portugal,1999,11.83597848,12474.81808,1.038448463,45.29849909,53.743 +20,Portugal,2000,12.90682859,11502.39681,1.04221083,64.3638406,54.399 +20,Portugal,2001,12.02137252,11729.14616,1.048350946,76.71216134,55.044 +20,Portugal,2002,12.71960041,12882.28897,1.04735403,83.0168098,55.666 +20,Portugal,2003,12.02858158,15772.7334,1.0465565,95.38092133,56.287 +20,Portugal,2004,11.9559068,18045.5881,1.046927677,100.4068285,56.907 +20,Portugal,2005,11.31684146,18784.9485,1.047271081,108.3438682,57.522 +20,Portugal,2006,9.928896121,19821.44463,1.046530001,115.3442973,58.137 +20,Portugal,2007,9.961275492,22780.05845,1.047860427,126.7851539,58.749 +20,Portugal,2008,9.402045403,24815.60884,1.044727778,131.8912545,59.359 +20,Portugal,2009,8.799519384,23063.97161,1.041859561,110.6416365,59.964 +20,Portugal,2010,8.560418883,22538.65408,1.04298244,114.6264462,60.567 +20,Portugal,2011,7.466028649,23196.18375,1.049986197,116.0867004,61.167 +20,Portugal,2012,6.855986813,20577.40264,1.056109196,112.6230069,61.763 +20,Portugal,2013,6.039684021,21618.73534,1.047863407,113.899737,62.352 +11,Scotland,1990,16.71994557,NA,1.037040506,NA,NA +11,Scotland,1991,17.32462569,NA,1.036983329,NA,NA +11,Scotland,1992,17.54783688,NA,1.03645049,NA,NA +11,Scotland,1993,17.29603495,NA,1.035814292,NA,NA +11,Scotland,1994,15.4906833,NA,1.03536195,NA,NA +11,Scotland,1995,16.73285862,NA,1.033965166,NA,NA +11,Scotland,1996,17.79517083,NA,1.03511633,NA,NA +11,Scotland,1997,18.77815804,NA,1.034791111,NA,NA +11,Scotland,1998,18.47878743,NA,1.030922437,NA,NA +11,Scotland,1999,17.39459966,NA,1.028618866,NA,NA +11,Scotland,2000,15.82474701,NA,1.028030299,NA,NA +11,Scotland,2001,15.06377299,NA,1.035017752,NA,NA +11,Scotland,2002,14.5843696,NA,1.0397083,NA,NA +11,Scotland,2003,14.31832034,NA,1.041161388,NA,NA +11,Scotland,2004,13.68591439,NA,1.041842111,NA,NA +11,Scotland,2005,13.63764135,NA,1.040162695,NA,NA +11,Scotland,2006,13.93056621,NA,1.039177752,NA,NA +11,Scotland,2007,14.21956424,NA,1.035065996,NA,NA +11,Scotland,2008,13.55000365,NA,1.026442182,NA,NA +11,Scotland,2009,12.94699338,NA,1.024010346,NA,NA +11,Scotland,2010,11.9588894,NA,1.035461331,NA,NA +11,Scotland,2011,11.12195654,NA,1.053597622,NA,NA +11,Scotland,2012,9.334876868,NA,1.063460324,NA,NA +11,Scotland,2013,9.208430861,NA,1.062234716,NA,NA +6,Spain,1990,5.815738225,13767.38147,1.048453403,0.139164143,75.351 +6,Spain,1991,5.492712986,14771.6723,1.04373829,0.275233991,75.528 +6,Spain,1992,5.092531479,16068.42672,1.045334249,0.456266401,75.61 +6,Spain,1993,4.491702659,13303.67613,1.04880958,0.64901579,75.692 +6,Spain,1994,4.132442745,13378.84984,1.050780683,1.035922387,75.774 +6,Spain,1995,4.125193775,15429.93942,1.050591483,2.368872407,75.856 +6,Spain,1996,3.938116656,16069.20709,1.049733867,7.492366029,75.938 +6,Spain,1997,4.034621362,14696.21611,1.050195962,10.80869022,76.019 +6,Spain,1998,4.021542605,15340.33211,1.051484992,15.97672349,76.1 +6,Spain,1999,4.380961732,15678.21523,1.051914154,37.00989274,76.181 +6,Spain,2000,4.709848837,14676.70609,1.05225419,59.32239009,76.262 +6,Spain,2001,5.176519454,15323.6114,1.053832362,71.64586201,76.343 +6,Spain,2002,5.464751913,17019.53541,1.054809449,79.86324095,76.533 +6,Spain,2003,5.756433157,21495.70741,1.055670846,87.26111814,76.778 +6,Spain,2004,5.890547204,24918.64584,1.056389576,89.09134015,77.022 +6,Spain,2005,6.23338486,26510.71745,1.058751286,96.93815529,77.263 +6,Spain,2006,6.626126174,28482.60948,1.059862622,102.1677305,77.502 +6,Spain,2007,7.118512579,32709.40104,1.062377059,106.6718542,77.74 +6,Spain,2008,6.947297935,35579.30993,1.061929112,107.8819694,77.976 +6,Spain,2009,6.188855481,32334.00548,1.063831443,109.8472629,78.21 +6,Spain,2010,5.473421463,30736.62785,1.063703423,109.8331304,78.442 +6,Spain,2011,5.198178568,31835.2888,1.064079567,112.1114334,78.673 +6,Spain,2012,4.975532673,28563.85904,1.060610742,108.1261331,78.902 +6,Spain,2013,4.763311899,29211.77375,1.057819797,107.4118145,79.133 +22,Sweden,1990,4.05340819,30162.31577,1.049602826,5.383206823,83.1 +22,Sweden,1991,3.817052791,31374.11699,1.047975235,6.587721447,83.204 +22,Sweden,1992,3.603534775,32338.50395,1.05011842,7.551741517,83.361 +22,Sweden,1993,3.107222462,24080.89967,1.053574637,8.854691146,83.516 +22,Sweden,1994,2.883783524,25747.24169,1.054434847,15.69633179,83.671 +22,Sweden,1995,2.906438721,29914.33175,1.052713476,22.72413489,83.824 +22,Sweden,1996,2.717040599,32587.2641,1.04984411,28.12897927,83.914 +22,Sweden,1997,2.703668494,29897.79263,1.048679518,35.7317908,83.942 +22,Sweden,1998,2.273729935,30143.62746,1.052289001,46.3202616,83.97 +22,Sweden,1999,2.25629596,30577.08177,1.055685109,57.77011417,83.998 +22,Sweden,2000,2.724010402,29283.00505,1.06108782,71.74688458,84.026 +22,Sweden,2001,2.478905788,26969.24457,1.062268232,80.67169016,84.071 +22,Sweden,2002,2.658436321,29571.70446,1.06185079,89.10741698,84.133 +22,Sweden,2003,2.617097957,36961.42537,1.05485912,98.31957425,84.196 +22,Sweden,2004,2.371631683,42442.22045,1.05609059,97.71274322,84.258 +22,Sweden,2005,2.213271539,43085.35315,1.054771247,100.7233071,84.319 +22,Sweden,2006,2.336216871,46256.4716,1.057760758,105.6147887,84.43 +22,Sweden,2007,2.206039837,53324.37937,1.057897837,110.4068942,84.588 +22,Sweden,2008,2.003425382,55746.84238,1.06114412,108.4131131,84.746 +22,Sweden,2009,2.051033592,46207.0592,1.05876938,112.0956103,84.902 +22,Sweden,2010,1.92326823,52076.25591,1.053978623,117.0629429,85.056 +22,Sweden,2011,1.839942422,59593.28711,1.05548268,121.0055217,85.297 +22,Sweden,2012,1.789810993,57134.07707,1.060041701,124.1857719,85.62 +22,Sweden,2013,1.790603904,60283.24522,1.066788219,124.9512155,85.936 +2,Switzerland,1990,1.839682448,38428.3855,1.059889122,1.873394168,73.926 +2,Switzerland,1991,2.298339898,38399.21061,1.061371656,2.589455767,73.869 +2,Switzerland,1992,1.703339419,39534.542,1.055127052,3.155526562,73.815 +2,Switzerland,1993,1.716065897,38100.73673,1.056682977,3.739378374,73.762 +2,Switzerland,1994,1.470795463,41843.75688,1.058232932,4.771619748,73.708 +2,Switzerland,1995,1.52201676,48662.43977,1.060215881,6.371238971,73.654 +2,Switzerland,1996,1.467168879,46676.85094,1.057948881,9.385310344,73.6 +2,Switzerland,1997,1.24443391,40417.96228,1.058953998,14.72664421,73.546 +2,Switzerland,1998,1.59726637,41497.20261,1.059549302,23.87258864,73.492 +2,Switzerland,1999,1.666373439,40581.30705,1.063077555,42.83146907,73.438 +2,Switzerland,2000,1.608636663,37868.32306,1.066514621,64.71825317,73.383 +2,Switzerland,2001,1.670597972,38538.99005,1.063819574,73.24755976,73.375 +2,Switzerland,2002,1.735200863,41376.39399,1.049921551,79.18789483,73.401 +2,Switzerland,2003,1.427262704,48087.58314,1.048140221,84.87507976,73.427 +2,Switzerland,2004,1.622685407,53340.14766,1.053757529,85.4029135,73.452 +2,Switzerland,2005,1.679801564,54952.67372,1.056187007,92.22603163,73.478 +2,Switzerland,2006,1.313949378,57579.50195,1.057091485,99.39516725,73.504 +2,Switzerland,2007,1.362387451,63555.2375,1.059039327,108.57798,73.53 +2,Switzerland,2008,1.287185355,72487.84593,1.057614718,116.3559314,73.556 +2,Switzerland,2009,1.15996088,69927.46877,1.057603809,120.4909656,73.581 +2,Switzerland,2010,1.214077148,74605.72102,1.057783925,123.1383135,73.607 +2,Switzerland,2011,1.060767965,88415.62806,1.052625011,127.1387232,73.631 +2,Switzerland,2012,1.118148409,83538.23008,1.052560794,131.49289,73.653 +2,Switzerland,2013,1.069081533,85112.4644,1.051418105,135.8549107,73.674 +23,United States of America,1990,39.46270829,23954.47935,1.058680602,2.092050864,75.3 +23,United States of America,1991,40.90824526,24405.16481,1.060695192,2.963880131,75.701 +23,United States of America,1992,40.39491311,25492.95165,1.061780809,4.285325262,76.097 +23,United States of America,1993,40.24373761,26464.85251,1.062306063,6.157006979,76.488 +23,United States of America,1994,40.20479557,27776.63553,1.062792492,9.18561207,76.875 +23,United States of America,1995,38.3156325,28782.17502,1.063340979,12.71768704,77.257 +23,United States of America,1996,35.72252657,30068.23092,1.063693556,16.38483296,77.636 +23,United States of America,1997,33.58361781,31572.69023,1.063706762,20.32519807,78.008 +23,United States of America,1998,31.66961342,32949.19776,1.063493075,25.1174665,78.377 +23,United States of America,1999,29.72030698,34620.9289,1.063492736,30.85645141,78.742 +23,United States of America,2000,28.35409972,36449.85512,1.063567383,38.82436785,79.057 +23,United States of America,2001,25.93207069,37273.6181,1.062637086,45.11108352,79.234 +23,United States of America,2002,24.43736096,38166.03784,1.06061211,49.32056453,79.409 +23,United States of America,2003,23.37349513,39677.19835,1.05874255,55.38679309,79.583 +23,United States of America,2004,23.03121371,41921.80976,1.057685112,63.17748926,79.757 +23,United States of America,2005,22.42077655,44307.92058,1.057804033,69.02054837,79.928 +23,United States of America,2006,22.76985522,46437.06712,1.058046917,77.09164231,80.099 +23,United States of America,2007,22.69739017,48061.53766,1.057401215,82.93546295,80.269 +23,United States of America,2008,21.90405154,48401.42734,1.056803856,86.13129085,80.438 +23,United States of America,2009,20.24372413,47001.55535,1.056627777,89.61260458,80.606 +23,United States of America,2010,17.98513923,48375.40695,1.056584167,92.37840689,80.772 +23,United States of America,2011,15.92109369,49793.71352,1.054775593,95.61250193,80.944 +23,United States of America,2012,14.57959108,51450.95911,1.050985033,97.28807458,81.119 +23,United States of America,2013,12.70747476,52782.08651,1.047868666,98.46652501,81.299 +30,New Zealand,1990,36.06935411202321,NA,NA,NA,NA +30,New Zealand,1991,35.644676259434796,NA,NA,NA,NA +30,New Zealand,1992,34.2513950041215,NA,NA,NA,NA +30,New Zealand,1993,33.75599489139184,NA,NA,NA,NA +30,New Zealand,1994,33.66355188386955,NA,NA,NA,NA +30,New Zealand,1995,35.88348268580385,NA,NA,NA,NA +30,New Zealand,1996,34.61389110036712,NA,NA,NA,NA +30,New Zealand,1997,34.72795992904572,NA,NA,NA,NA +30,New Zealand,1998,30.769593422579366,NA,NA,NA,NA +30,New Zealand,1999,30.102189010060467,NA,NA,NA,NA +30,New Zealand,2000,29.328794412777153,NA,NA,NA,NA +30,New Zealand,2001,27.83457696795812,NA,NA,NA,NA +30,New Zealand,2002,26.719917134556088,NA,NA,NA,NA +30,New Zealand,2003,27.648096614854417,NA,NA,NA,NA +30,New Zealand,2004,28.416103411475163,NA,NA,NA,NA +30,New Zealand,2005,28.760773870644318,NA,NA,NA,NA +30,New Zealand,2006,29.274473491868168,NA,NA,NA,NA +30,New Zealand,2007,32.73523721220665,NA,NA,NA,NA +30,New Zealand,2008,33.93926716276267,NA,NA,NA,NA +30,New Zealand,2009,29.859401028754185,NA,NA,NA,NA +30,New Zealand,2010,29.39761785300802,NA,NA,NA,NA +30,New Zealand,2011,25.22396191540695,NA,NA,NA,NA +30,New Zealand,2012,23.859801645953844,NA,NA,NA,NA +30,New Zealand,2013,20.89256928653691,NA,NA,NA,NA diff --git a/Data/under-20-pregnancy-rates.csv b/Data/under-20-pregnancy-rates.csv new file mode 100644 index 0000000..6fef5d1 --- /dev/null +++ b/Data/under-20-pregnancy-rates.csv @@ -0,0 +1,385 @@ +Code,Country,Year,pRate,rate,GDPperCap,MF_ratio,MobilePhones,UrbanPop +4,Denmark,1990,26.5082573109863,9.200844155,26891.44164,1.046908673,2.883032183,84.843 +4,Denmark,1991,25.334369276874412,8.996059715,27011.38589,1.044064598,3.413116199,84.871 +4,Denmark,1992,25.430899849504502,9.699860863,29569.65453,1.043513076,4.081153984,84.898 +4,Denmark,1993,24.806557068604622,9.137091653,27597.97148,1.0455619840000001,6.888976566,84.925 +4,Denmark,1994,24.074096392802478,9.20781459,29995.56522,1.04570764,9.661633662,84.952 +4,Denmark,1995,23.083922272494984,8.718792457,35351.38071,1.046747435,15.71394063,84.979 +4,Denmark,1996,23.297258764824054,8.197783682,35650.72434,1.048499773,25.05474932,85.006 +4,Denmark,1997,23.260946622882404,8.687742859,32835.92877,1.043238074,27.36064934,85.033 +4,Denmark,1998,22.133681390396372,7.948066222,33368.15485,1.04339493,36.4332626,85.06 +4,Denmark,1999,21.370403765734935,7.965977749,33440.80162,1.041690037,49.39302195,85.086 +4,Denmark,2000,22.00972893815382,7.851296588,30743.55917,1.039546466,62.97378451,85.1 +4,Denmark,2001,21.73897147536908,7.67042754,30751.64946,1.039873061,73.91039895,85.15 +4,Denmark,2002,20.348353389824375,6.490922116,33228.69291,1.044618758,83.34111016,85.25 +4,Denmark,2003,20.94061350569582,6.035067671,40458.77064,1.048109131,88.4931932,85.36 +4,Denmark,2004,21.714476549617682,5.746926508,46511.60457,1.053127761,95.63465791,85.566 +4,Denmark,2005,21.7865070743737,5.708078348,48799.82037,1.055056642,100.5072946,85.856 +4,Denmark,2006,22.480665841567948,5.991788303,52026.99311,1.0575932,107.0505628,86.098 +4,Denmark,2007,22.905429930525926,5.775708909,58487.04501,1.055700249,115.3208334,86.293 +4,Denmark,2008,24.030836191951607,6.116828348,64322.06664,1.054903914,119.2657784,86.487 +4,Denmark,2009,22.465251589268398,5.525027236,58163.29359,1.052742161,123.654185,86.654 +4,Denmark,2010,20.155464961894122,5.065186494,58041.41122,1.052558621,115.5890246,86.795 +4,Denmark,2011,18.688197927884865,4.589982665,61753.66007,1.05291438,128.4855486,86.957 +4,Denmark,2012,18.208852796522933,4.409241679,58507.50021,1.053785886,129.9803588,87.142 +4,Denmark,2013,16.880056419753796,4.231481535,61191.19263,1.053954256,124.714087,87.292 +10,England and Wales,1990,68,32.67311158,19095.467,1.045904935,1.948120161,78.14 +10,England and Wales,1991,64.1,32.21800813,19900.72665,1.049248042,2.197440097,78.112 +10,England and Wales,1992,61.9,30.91135318,20487.17079,1.046766374,2.621118549,78.172 +10,England and Wales,1993,59.7,30.39406518,18389.01957,1.040022539,3.934052718,78.232 +10,England and Wales,1994,58.7,28.85476576,19709.2381,1.035670454,6.815338962,78.293 +10,England and Wales,1995,58.7,28.64709989,23013.45882,1.032155602,9.892982241,78.353 +10,England and Wales,1996,63.2,30.02536914,24219.62285,1.029277026,12.46348124,78.413 +10,England and Wales,1997,62.6,30.55068211,26621.48006,1.027843751,15.15253492,78.472 +10,England and Wales,1998,65.1,31.20187141,28014.8947,1.027747424,25.41295714,78.532 +10,England and Wales,1999,63.1,30.93753817,28383.66891,1.029230117,46.27491764,78.591 +10,England and Wales,2000,62.5,29.30152667,27982.35576,1.034945877,73.70886336,78.651 +10,England and Wales,2001,60.8,28.13577506,27427.5875,1.043018273,78.24769922,78.751 +10,England and Wales,2002,60.6,27.3243976,29785.98629,1.050564916,82.94670337,79.047 +10,England and Wales,2003,59.9,27.23194542,34173.97998,1.050748334,91.06414709,79.339 +10,England and Wales,2004,60.3,27.15150304,39983.98467,1.042161364,99.67234557,79.629 +10,England and Wales,2005,60,26.56647056,41732.64054,1.032353407,108.6004149,79.915 +10,England and Wales,2006,60.2,26.67870787,44252.31582,1.032786496,115.254437,80.199 +10,England and Wales,2007,61.7,26.01252532,50134.3161,1.039134514,120.2257083,80.479 +10,England and Wales,2008,60.1,25.77333934,46767.59222,1.039587818,120.7240644,80.757 +10,England and Wales,2009,57.3,24.85689815,38262.18213,1.039509792,121.9353861,81.031 +10,England and Wales,2010,54.6,23.35572003,38893.01849,1.042881877,121.2030538,81.302 +10,England and Wales,2011,48.9,21.10878048,41412.34924,1.046532849,120.9215205,81.57 +10,England and Wales,2012,44.2,19.79793278,41790.77914,1.050296956,121.9127668,81.837 +10,England and Wales,2013,40.5,17.27391571,42724.06788,1.0541046,121.7088908,82.102 +7,Finland,1990,28.084570699530392,12.40824941,28380.54891,1.044599473,5.161339908,79.367 +7,Finland,1991,26.02231311249696,12.3887719,25503.21521,1.047616155,6.358419047,79.843 +7,Finland,1992,24.544936486584987,11.9217695,22337.48712,1.05204323,7.651669747,80.128 +7,Finland,1993,21.76534046497807,10.70612327,17617.03044,1.048248419,9.644999033,80.409 +7,Finland,1994,20.83942752312023,10.09606202,20305.58355,1.045605901,13.25391689,80.688 +7,Finland,1995,20.78871395167576,9.777022603,26273.4659,1.044595479,20.29937459,80.963 +7,Finland,1996,21.091624508150648,9.73693086,25777.6413,1.043082881,29.23903329,81.223 +7,Finland,1997,21.085011396387063,9.073282222,24676.49708,1.042835346,41.97749656,81.466 +7,Finland,1998,22.398255177204653,9.293309218,25989.4075,1.046048802,55.10944297,81.707 +7,Finland,1999,23.805128268667257,9.668006864,26178.79178,1.046060253,63.24342736,81.946 +7,Finland,2000,24.807348498859504,9.974724123,24253.25042,1.047999507,71.87081844,82.183 +7,Finland,2001,25.96185272661121,10.60674268,24913.24452,1.045978996,80.29235384,82.368 +7,Finland,2002,27.231749782365377,11.10191518,26834.02625,1.047133441,86.6381899,82.503 +7,Finland,2003,25.575887234082956,10.33451273,32816.16088,1.045243083,90.81753315,82.638 +7,Finland,2004,26.322860778759026,10.61083152,37636.11173,1.044763616,95.15116311,82.772 +7,Finland,2005,25.35533109155088,10.32938771,38969.17163,1.045283577,100.2105563,82.905 +7,Finland,2006,23.80375452736826,9.526603071,41120.67651,1.046510738,107.4358085,83.037 +7,Finland,2007,22.8197783975277,9.208311349,48288.5491,1.043585588,114.7599836,83.168 +7,Finland,2008,21.502785215277136,8.675407011,53401.31487,1.043024651,128.3858236,83.299 +7,Finland,2009,21.459599549063817,8.525818547,47107.15571,1.041325605,144.1233426,83.429 +7,Finland,2010,20.55006613716299,8.413744339,46202.41516,1.03980421,156.361179,83.77 +7,Finland,2011,20.273240820336486,7.667321626,50790.72415,1.039076507,165.8860374,84.313 +7,Finland,2012,18.33868003862086,7.443859594,47415.55987,1.04171053,172.178726,84.841 +7,Finland,2013,17.64234671820563,7.24766676,49638.07713,1.038965745,136.3200932,85.125 +8,France,1990,23.2836158576359,12.42606261,21690.62912,1.045609148,0.497183723,74.056 +8,France,1991,23.977600163155106,12.42989429,21675.06425,1.042915135,0.655162571,74.229 +8,France,1992,23.295493041208704,11.91888303,23813.71184,1.043640717,0.759518231,74.401 +8,France,1993,22.547078459652752,11.02669414,22380.10396,1.044316555,0.990565041,74.572 +8,France,1994,21.762417539774933,10.11512094,23496.52332,1.044267128,1.522658967,74.743 +8,France,1995,21.31606261610164,9.650077206,26890.21988,1.04361639,2.236359799,74.912 +8,France,1996,22.300473285513178,9.576188242,26871.82902,1.044161695,4.20976597,75.082 +8,France,1997,22.211449050347966,9.458652058,24228.94235,1.04479448,9.899530141,75.25 +8,France,1998,22.706228599507572,9.457945189,24974.2722,1.044504185,18.9889303,75.417 +8,France,1999,24.006786339868498,10.21222632,24673.19897,1.044978456,36.13436735,75.614 +8,France,2000,24.326279537768926,11.08327628,22364.02939,1.0401195,48.73886397,75.871 +8,France,2001,25.435537378153292,11.53120257,22433.55571,1.037934019,61.75367525,76.127 +8,France,2002,24.751640523380715,10.90689677,24177.33517,1.03694753,64.06849532,76.38 +8,France,2003,24.446109828487447,10.58312183,29568.38595,1.037197534,68.87189627,76.632 +8,France,2004,25.457947576478812,10.58854373,33741.26515,1.039647665,73.1589461,76.883 +8,France,2005,25.48677545567714,10.32913958,34760.18777,1.039713059,78.53166302,77.13 +8,France,2006,26.03846321692913,10.26051144,36443.62344,1.040762952,83.87657249,77.377 +8,France,2007,25.71966317626706,10.09989788,41508.43269,1.045640824,89.34353008,77.621 +8,France,2008,25.427422976018082,10.15593222,45334.11091,1.04546816,93.00882838,77.868 +8,France,2009,25.109312372438364,9.921736895,41575.41618,1.045262886,92.39159417,78.117 +8,France,2010,25.561279293381865,9.832687978,40638.334,1.046863582,91.68330775,78.369 +8,France,2011,24.000709817665587,9.528553859,43790.7354,1.047836793,94.43104231,78.622 +8,France,2012,24.23041838112139,9.565736473,40874.71596,1.047916978,97.83174772,78.878 +8,France,2013,23.13918786200839,9.034142449,42592.95152,1.048105097,99.06771312,79.135 +3,Germany,1990,30.2635921336887,19.37933928,22219.57253,1.051216202,0.344558605,73.118 +3,Germany,1991,26.5763038425194,18.32929262,23269.3818,1.051787607,0.668955763,73.269 +3,Germany,1992,24.83133475509115,16.88178994,26333.53744,1.050693783,1.214161974,73.36 +3,Germany,1993,23.195642030469177,15.16995027,25488.51952,1.054595,2.203646375,73.497 +3,Germany,1994,21.14851177254554,13.73600375,27087.55845,1.054799842,3.077311214,73.71 +3,Germany,1995,19.915574532292265,12.96288896,31729.69976,1.053076,4.585145625,73.922 +3,Germany,1996,18.576361602308953,13.14063846,30564.24781,1.050666746,6.769308559,74.133 +3,Germany,1997,18.813970996080275,13.04920814,27045.71913,1.049332684,10.15461792,74.342 +3,Germany,1998,19.196327516866628,13.12611876,27340.67288,1.048506059,17.07132651,74.551 +3,Germany,1999,19.785977348839545,13.34873638,26795.99113,1.048539494,28.77459027,74.758 +3,Germany,2000,20.66942256987524,13.69236128,23718.7467,1.047821491,59.15244421,74.965 +3,Germany,2001,21.526604428846536,13.76881712,23687.31689,1.047204025,68.83597997,75.17 +3,Germany,2002,20.615973432271574,13.0888408,25205.16445,1.048740988,72.45024706,75.374 +3,Germany,2003,19.75907066917103,12.31537967,30359.95215,1.048595549,79.32767834,75.577 +3,Germany,2004,19.344726915426886,11.6060568,34165.93403,1.048831468,87.280701,75.779 +3,Germany,2005,18.383364628875423,11.20150814,34696.62092,1.047646095,97.06110232,75.98 +3,Germany,2006,17.485786024194965,10.66004417,36447.87232,1.047701756,105.042469,76.179 +3,Germany,2007,17.023144959422776,10.42218985,41814.8191,1.047771379,118.3029902,76.378 +3,Germany,2008,16.37626588325752,10.15329515,45699.19832,1.046531106,130.0651266,76.575 +3,Germany,2009,15.475843297365607,9.454894527,41732.70725,1.047077716,129.6846864,76.771 +3,Germany,2010,15.029367786891196,9.250654472,41785.55691,1.048757591,109.2777489,76.966 +3,Germany,2011,14.084742631606234,8.591512146,46810.32796,1.049919285,112.3137649,77.16 +3,Germany,2012,13.72247069713984,8.37874574,44065.24891,1.052076992,113.9808799,77.17 +3,Germany,2013,12.923380953713195,8.046213048,46530.91143,1.054079694,123.0958333,77.18 +12,Iceland,1990,46.60439774275151,30.64798599,25008.84946,1.050690796,3.924828362,90.75 +12,Iceland,1991,41.62670247458277,28.58239018,26405.91589,1.045271437,5.003027668,90.932 +12,Iceland,1992,40.90736522399393,26.86028853,26722.44119,1.040242976,5.86236455,91.112 +12,Iceland,1993,39.2578125,23.2421875,23230.4718,1.039355469,6.628061038,91.287 +12,Iceland,1994,39.338089575901705,23.58303607,23662.80668,1.032996433,8.239105673,91.46 +12,Iceland,1995,38.656280428432325,23.17429406,26239.0273,1.033495618,11.53948189,91.63 +12,Iceland,1996,39.599190673475285,21.58204066,27261.17166,1.038057616,17.32555987,91.797 +12,Iceland,1997,44.88467795961336,24.30854627,27842.61347,1.039621016,23.96987265,91.96 +12,Iceland,1998,49.56268221574344,24.82836453,30847.6437,1.052101947,37.87922818,92.121 +12,Iceland,1999,45.28934861615879,24.32205759,32148.15015,1.051439754,62.12041602,92.267 +12,Iceland,2000,47.951012717852095,22.98634008,31746.02314,1.047479981,76.62952199,92.401 +12,Iceland,2001,41.19277453885119,19.87957565,28551.78527,1.02446717,87.70762123,92.532 +12,Iceland,2002,38.46904901386448,18.55106425,32024.1856,1.020894357,91.27638621,92.662 +12,Iceland,2003,35.71781933313545,16.52320174,39086.77319,1.027505689,97.12382619,92.789 +12,Iceland,2004,33.14430973797419,12.8079781,46984.06654,1.046538913,99.64411344,92.914 +12,Iceland,2005,30.36980264418471,14.46637287,56250.68281,1.042249473,95.97564572,93.037 +12,Iceland,2006,29.764098783634353,13.8223369,56121.32242,1.058422411,100.731997,93.159 +12,Iceland,2007,32.92365658921683,14.35363775,68428.34821,1.064860501,106.8473132,93.278 +12,Iceland,2008,29.850746268656717,14.57827143,55632.10432,1.055275946,108.3754712,93.395 +12,Iceland,2009,26.545641376948108,14.55728721,40640.9902,1.044528173,107.4754972,93.511 +12,Iceland,2010,28.664887664629422,12.91211156,41851.73548,1.04863562,106.4774231,93.574 +12,Iceland,2011,26.527544433636926,10.96471837,46181.95294,1.055973119,106.3901824,93.587 +12,Iceland,2012,25.024316915730832,11.31841896,44562.81802,1.050313909,108.167704,93.6 +12,Iceland,2013,20.241093918675784,7.286793811,48023.62691,1.051367398,108.9395742,93.633 +13,Italy,1990,14.52523816613129,8.967367285,20757.08868,1.042673658,0.465628234,66.726 +13,Italy,1991,13.851297521877827,8.394799214,21884.10437,1.041024328,0.993832013,66.706 +13,Italy,1992,13.312217128755355,7.610066156,23166.80406,1.03759221,1.369147121,66.742 +13,Italy,1993,13.637797917242818,7.762192109,18676.95258,1.037184465,2.109463097,66.802 +13,Italy,1994,12.816373503722351,7.179986724,19273.84417,1.037837849,3.912570332,66.862 +13,Italy,1995,12.768639674628709,6.732379889,20596.38858,1.038553387,6.851780239,66.922 +13,Italy,1996,13.425745194306115,6.737526038,23020.09994,1.039945483,11.22145209,66.982 +13,Italy,1997,13.420739746488833,6.567254594,21779.62437,1.040910842,20.52622947,67.042 +13,Italy,1998,13.068343159591949,6.049496819,22252.35809,1.042419892,35.84903924,67.102 +13,Italy,1999,14.309539380264663,6.869640889,21936.82313,1.044600309,52.98357088,67.162 +13,Italy,2000,14.232721936903891,6.849276329,20051.24215,1.046631761,73.73582875,67.222 +13,Italy,2001,13.874600703563548,6.608611689,20400.81111,1.047753849,89.11361067,67.282 +13,Italy,2002,13.781739217418849,6.415517692,22196.50675,1.050516684,93.76876619,67.382 +13,Italy,2003,14.03334978193715,6.916713968,27387.22632,1.052697326,97.63180194,67.501 +13,Italy,2004,15.178740158872888,7.158357171,31174.56109,1.054874481,107.2746688,67.62 +13,Italy,2005,14.53548066510468,6.948493038,31959.26295,1.055700365,121.5810991,67.738 +13,Italy,2006,14.530947914336036,6.830542313,33410.74744,1.057684199,136.1174311,67.856 +13,Italy,2007,14.575505443212185,6.808465542,37698.78665,1.059268788,151.4005806,67.974 +13,Italy,2008,14.327190677394107,7.130022543,40640.18386,1.059630881,151.8275276,68.092 +13,Italy,2009,13.735017876863544,6.859637085,36976.84553,1.059941385,150.9558833,68.209 +13,Italy,2010,13.2852219264014,6.582261879,35849.3732,1.062639754,156.8163246,68.327 +13,Italy,2011,12.909648408455192,6.373515561,38334.68385,1.065431441,160.7112234,68.444 +13,Italy,2012,12.420230349375343,6.2745849,34814.12512,1.066199949,162.7028059,68.684 +13,Italy,2013,11.69318618570417,5.811361806,35370.27526,1.065450473,162.3367752,68.979 +15,Netherlands,1990,12.0378286076771,8.071301596,21019.12567,1.041970318,0.527882627,68.684 +15,Netherlands,1991,12.357672724721892,8.049419233,21454.86289,1.041755569,0.763383152,69.329 +15,Netherlands,1992,11.875202221466806,7.539983536,23598.95076,1.042334424,1.094563567,70.223 +15,Netherlands,1993,11.563781871687716,7.158099825,22827.30004,1.043314698,1.414723049,71.1 +15,Netherlands,1994,11.550101006567612,6.862696657,24331.75402,1.045103149,2.088603642,71.962 +15,Netherlands,1995,10.864958069162027,5.847460072,28884.71352,1.045585778,3.484646962,72.809 +15,Netherlands,1996,10.896573295798644,5.570285481,28698.66602,1.049298665,6.528197347,73.64 +15,Netherlands,1997,11.286320528595823,6.037475341,26404.98673,1.045660093,10.96740917,74.453 +15,Netherlands,1998,12.17837226361234,6.257081245,27533.60679,1.046468878,21.28207244,75.25 +15,Netherlands,1999,13.687085498597838,6.7892505420000004,27951.73429,1.04660358,42.59701432,76.03 +15,Netherlands,2000,15.953875117665516,7.417877204,25921.12794,1.049401839,67.53028408,76.795 +15,Netherlands,2001,17.070929594716354,7.862441043,26584.12169,1.049913092,76.16377309,77.83 +15,Netherlands,2002,17.27154976304349,7.653967307,28817.32321,1.051492597,75.10697312,79.113 +15,Netherlands,2003,15.934949951621327,7.115475181,35245.16407,1.05269208,81.4766985,80.341 +15,Netherlands,2004,14.497980532970567,6.335748257,39954.64222,1.049738998,90.86900361,81.514 +15,Netherlands,2005,13.571152758383896,5.833776871,41577.16009,1.0442013510000001,96.74251327,82.63 +15,Netherlands,2006,12.660139888996637,5.259227928,44453.97119,1.044776858,105.205392,83.636 +15,Netherlands,2007,12.63994836647509,5.210457838,51241.31562,1.04585139,116.8288276,84.539 +15,Netherlands,2008,12.325909942187119,5.197011644,56928.82048,1.0452854,124.4935189,85.402 +15,Netherlands,2009,12.551676698194324,5.333023115,51900.34009,1.044463103,121.1829535,86.288 +15,Netherlands,2010,12.898583151414732,5.111862302,50338.25483,1.046807001,114.9619098,87.134 +15,Netherlands,2011,12.60580101399838,4.807689962,53540.60536,1.046585379,118.4758716,87.879 +15,Netherlands,2012,11.851867822287382,4.523491256,49474.70561,1.049430095,117.4393259,88.588 +15,Netherlands,2013,11.750307158229779,3.918803031,51574.48942,1.046727219,115.6018288,89.187 +16,Norway,1990,36.720399794976935,16.87801128,28242.94374,1.044188877,4.6342075,71.956 +16,Norway,1991,35.07618541621573,16.38238979,28596.933,1.042556262,5.490680227,72.265 +16,Norway,1992,34.15537507142274,15.6466819,30523.98506,1.043533861,6.590703297,72.665 +16,Norway,1993,33.20623424574857,14.73071325,27963.66522,1.043313097,8.603688669,73.061 +16,Norway,1994,28.824522921693355,14.19412152,29315.84191,1.041924399,13.55435708,73.453 +16,Norway,1995,28.449686577059847,13.38127599,34875.19739,1.045227834,22.47094398,73.787 +16,Norway,1996,31.754256731352097,13.51495899,37321.44339,1.048257023,28.71352126,74.062 +16,Norway,1997,31.751951029356142,12.73954627,36628.51742,1.045358055,37.93356593,74.476 +16,Norway,1998,30.93376580352396,12.36631047,34788.77856,1.04791328,46.58811742,75.027 +16,Norway,1999,30.595505704773164,11.68516759,36371.39579,1.048774459,59.54397895,75.569 +16,Norway,2000,31.81658093516845,11.76622333,38146.71539,1.049755163,71.65452385,76.02 +16,Norway,2001,30.005860444314212,11.11363864,38549.58934,1.050847066,79.43587924,76.378 +16,Norway,2002,27.248221726019196,10.17525686,43061.15038,1.057986695,83.36964716,76.733 +16,Norway,2003,25.83047777190731,9.210355499,50111.65445,1.05358895,88.85634163,77.084 +16,Norway,2004,24.230949796074057,8.305654177,57570.26916,1.052609959,98.40233621,77.399 +16,Norway,2005,23.914193108154212,8.198567042,66775.3944,1.054496474,102.6355658,77.675 +16,Norway,2006,25.39745164366925,8.874990565,74114.69715,1.052785421,104.1909494,77.95 +16,Norway,2007,26.340660436965848,9.214525623,85170.86217,1.050281002,106.737833,78.234 +16,Norway,2008,27.476309031896452,9.383839305,97007.94189,1.056708422,109.2173612,78.526 +16,Norway,2009,25.4163204575757,9.461717326,80067.17664,1.056089093,110.925095,78.815 +16,Norway,2010,22.593867574415807,8.459343247,87770.26684,1.060556423,114.6014289,79.102 +16,Norway,2011,19.885303514376997,7.131309904,100711.2248,1.067884984,115.7218204,79.455 +16,Norway,2012,17.517656939972767,6.064506687,101668.1707,1.067866278,115.6722646,79.874 +16,Norway,2013,15.775385842018338,5.644462162,103059.2482,1.063323019,112.1122467,80.286 +19,Portugal,1990,39.80482095246786,24.29940066,7885.394019,1.028811995,0.065304797,47.915 +19,Portugal,1991,38.67678024944545,23.61077269,8959.867208,1.027141723,0.126325984,48.469 +19,Portugal,1992,36.90055873914873,22.52645383,10811.63064,1.027734198,0.37226352,49.13 +19,Portugal,1993,36.72093190733255,22.41679816,9535.594849,1.029403793,1.007459376,49.789 +19,Portugal,1994,34.60617768736848,21.12581734,9978.301937,1.030648416,1.717315573,50.449 +19,Portugal,1995,33.296579023579454,20.32635482,11782.52148,1.032214183,3.358166494,51.109 +19,Portugal,1996,33.607593723845426,20.51621802,12185.06389,1.031263062,6.511237694,51.77 +19,Portugal,1997,33.95145027777599,20.72612999,11578.44151,1.031441515,14.72662057,52.428 +19,Portugal,1998,33.557860463356036,20.48585767,12202.69141,1.031166607,29.93134148,53.086 +19,Portugal,1999,34.13715277289438,20.83949463,12474.81808,1.034101017,45.29849909,53.743 +19,Portugal,2000,35.45570985640426,21.64442595,11502.39681,1.036634324,64.3638406,54.399 +19,Portugal,2001,33.309463175658315,20.33422013,11729.14616,1.04066631,76.71216134,55.044 +19,Portugal,2002,33.96385839465571,20.73370469,12882.28897,1.043623603,83.0168098,55.666 +19,Portugal,2003,32.382231830491044,19.768179,15772.7334,1.045476047,95.38092133,56.287 +19,Portugal,2004,31.729485687388063,19.36970113,18045.5881,1.04595353,100.4068285,56.907 +19,Portugal,2005,31.14861621007279,19.01510137,18784.9485,1.04603503,108.3438682,57.522 +19,Portugal,2006,28.093211549624005,17.14988755,19821.44463,1.045470285,115.3442973,58.137 +19,Portugal,2007,27.913262042098246,17.0400349,22780.05845,1.047411504,126.7851539,58.749 +19,Portugal,2008,23.966060563429817,16.15119755,24815.60884,1.044166989,131.8912545,59.359 +19,Portugal,2009,23.8479381261589,15.31701883,23063.97161,1.040514816,110.6416365,59.964 +19,Portugal,2010,22.92668012855152,14.40516481,22538.65408,1.041530389,114.6264462,60.567 +19,Portugal,2011,21.67158138814778,13.18153505,23196.18375,1.042018168,116.0867004,61.167 +19,Portugal,2012,19.802306063564853,12.07154429,20577.40264,1.043824716,112.6230069,61.763 +19,Portugal,2013,17.80460511201524,10.60124354,21618.73534,1.04245685,113.899737,62.352 +9,Scotland,1990,56.392211710829564,31.22685211,NA,1.027393294,NA,NA +9,Scotland,1991,57.643977577256166,32.39644199,NA,1.030636124,NA,NA +9,Scotland,1992,55.60217661698564,32.2349899,NA,1.034485105,NA,NA +9,Scotland,1993,53.75310650436397,30.71024801,NA,1.031193674,NA,NA +9,Scotland,1994,54.662910947128985,28.38079799,NA,1.026024007,NA,NA +9,Scotland,1995,53.837651486242876,28.24060944,NA,1.025505392,NA,NA +9,Scotland,1996,58.03839623873579,29.84806675,NA,1.02627698,NA,NA +9,Scotland,1997,56.694843997715004,31.33563584,NA,1.025257413,NA,NA +9,Scotland,1998,58.074538115792556,30.73202226,NA,1.024943028,NA,NA +9,Scotland,1999,57.129758160029546,30.30147714,NA,1.024675283,NA,NA +9,Scotland,2000,55.628034849458736,29.30342257,NA,1.02295825,NA,NA +9,Scotland,2001,54.782964364231304,28.35662697,NA,1.026437716,NA,NA +9,Scotland,2002,53.624925104853205,26.79274185,NA,1.030351866,NA,NA +9,Scotland,2003,54.309596385274936,26.43767577,NA,1.032314855,NA,NA +9,Scotland,2004,55.773683680660426,26.35708355,NA,1.03164555,NA,NA +9,Scotland,2005,56.85862689120018,26.27367481,NA,1.029670959,NA,NA +9,Scotland,2006,57.59286552921486,25.89309102,NA,1.029844901,NA,NA +9,Scotland,2007,57.68472420762064,26.72445878,NA,1.029287885,NA,NA +9,Scotland,2008,54.61224690387262,26.33727083,NA,1.025233789,NA,NA +9,Scotland,2009,51.28345698865782,24.41572106,NA,1.023159505,NA,NA +9,Scotland,2010,48.48684853818324,22.91874874,NA,1.026183808,NA,NA +9,Scotland,2011,43.842702231085624,20.90554534,NA,1.03232724,NA,NA +9,Scotland,2012,41.700347716745576,19.45020137,NA,1.041408764,NA,NA +9,Scotland,2013,38.01833517644827,17.90647727,NA,1.048737427,NA,NA +5,Spain,1990,14.994442866655236,11.91540913,13767.38147,1.049910358,0.139164143,75.351 +5,Spain,1991,14.303235152544978,10.96372681,14771.6723,1.047528342,0.275233991,75.528 +5,Spain,1992,13.75023540103214,9.954083378,16068.42672,1.046335052,0.456266401,75.61 +5,Spain,1993,12.8454434089623,9.01279449,13303.67613,1.046563884,0.64901579,75.692 +5,Spain,1994,12.142411497879301,8.038754508,13378.84984,1.04833951,1.035922387,75.774 +5,Spain,1995,11.793627230042288,7.460931204,15429.93942,1.049313398,2.368872407,75.856 +5,Spain,1996,11.80214749703611,7.125680078,16069.20709,1.050099435,7.492366029,75.938 +5,Spain,1997,12.22175173412978,7.45259507,14696.21611,1.05123482,10.80869022,76.019 +5,Spain,1998,12.859649056113557,7.496114974,15340.33211,1.050556794,15.97672349,76.1 +5,Spain,1999,14.450343719869466,8.171458967,15678.21523,1.049988882,37.00989274,76.181 +5,Spain,2000,15.603515957842795,8.615303176,14676.70609,1.051505459,59.32239009,76.262 +5,Spain,2001,17.39898791609604,9.494124785,15323.6114,1.0528327,71.64586201,76.343 +5,Spain,2002,18.72982778032609,9.84029023,17019.53541,1.052424002,79.86324095,76.533 +5,Spain,2003,19.982949934886538,10.61396481,21495.70741,1.053953965,87.26111814,76.778 +5,Spain,2004,21.25435752154522,10.7797844,24918.64584,1.054869337,89.09134015,77.022 +5,Spain,2005,22.79528795626749,11.42896467,26510.71745,1.056769857,96.93815529,77.263 +5,Spain,2006,24.506156392052162,12.12475505,28482.60948,1.057617093,102.1677305,77.502 +5,Spain,2007,26.68836743453999,12.99989269,32709.40104,1.059803799,106.6718542,77.74 +5,Spain,2008,26.652994818855422,13.37892196,35579.30993,1.061108362,107.8819694,77.976 +5,Spain,2009,24.346387084988486,11.83917845,32334.00548,1.062612159,109.8472629,78.21 +5,Spain,2010,22.267263668352378,10.64013029,30736.62785,1.063624789,109.8331304,78.442 +5,Spain,2011,23.1001029162062,9.578339983,31835.2888,1.06396182,112.1114334,78.673 +5,Spain,2012,21.908869522196998,9.04858237,28563.85904,1.060841105,108.1261331,78.902 +5,Spain,2013,20.609249093832354,8.45946743,29211.77375,1.060268473,107.4118145,79.133 +21,Sweden,1990,38.51646702798075,13.96325877,30162.31577,1.048104909,5.383206823,83.1 +21,Sweden,1991,35.26146952492489,12.88616674,31374.11699,1.048751391,6.587721447,83.204 +21,Sweden,1992,31.21741979684847,11.34163415,32338.50395,1.048643174,7.551741517,83.361 +21,Sweden,1993,29.2064925424533,10.69080835,24080.89967,1.051139103,8.854691146,83.516 +21,Sweden,1994,27.114635066323004,9.524108883,25747.24169,1.05155749,15.69633179,83.671 +21,Sweden,1995,25.326440804199585,8.528904176,29914.33175,1.051057304,22.72413489,83.824 +21,Sweden,1996,25.365442923705313,7.707597084,32587.2641,1.051378583,28.12897927,83.914 +21,Sweden,1997,25.042341139302348,7.234635052,29897.79263,1.049771195,35.7317908,83.942 +21,Sweden,1998,25.181631645719367,6.690081954,30143.62746,1.050367343,46.3202616,83.97 +21,Sweden,1999,26.002312402292862,6.977918187,30577.08177,1.051910989,57.77011417,83.998 +21,Sweden,2000,28.51035240945459,7.263991531,29283.00505,1.054976689,71.74688458,84.026 +21,Sweden,2001,29.772116660732205,6.854303564,26969.24457,1.057828634,80.67169016,84.071 +21,Sweden,2002,32.78180923194182,6.96682916,29571.70446,1.060518126,89.10741698,84.133 +21,Sweden,2003,31.846641416093377,6.377058051,36961.42537,1.056991575,98.31957425,84.196 +21,Sweden,2004,31.0655563944169,6.218318004,42442.22045,1.05777234,97.71274322,84.258 +21,Sweden,2005,31.031299643639173,6.196957337,43085.35315,1.056219856,100.7233071,84.319 +21,Sweden,2006,32.08752578982963,6.230754179,46256.4716,1.054192113,105.6147887,84.43 +21,Sweden,2007,31.28222984960785,6.131754796,53324.37937,1.055155947,110.4068942,84.588 +21,Sweden,2008,30.525737196068288,6.078634247,55746.84238,1.059712882,108.4131131,84.746 +21,Sweden,2009,28.414031192548695,5.932423631,46207.0592,1.057925352,112.0956103,84.902 +21,Sweden,2010,26.442570896748055,5.867539176,52076.25591,1.056321291,117.0629429,85.056 +21,Sweden,2011,25.140548079259464,5.741751018,59593.28711,1.059058486,121.0055217,85.297 +21,Sweden,2012,23.60504575672443,5.222386025,57134.07707,1.059664543,124.1857719,85.62 +21,Sweden,2013,20.017403150992156,5.214781056,60283.24522,1.061909092,124.9512155,85.936 +1,Switzerland,1990,15.550043576702738,6.81820337,38428.3855,1.055105118,1.873394168,73.926 +1,Switzerland,1991,17.862190587878747,7.832006866,38399.21061,1.054321746,2.589455767,73.869 +1,Switzerland,1992,16.412206089122677,7.196234423,39534.542,1.051706277,3.155526562,73.815 +1,Switzerland,1993,15.234378940466014,6.6797943890000004,38100.73673,1.053571337,3.739378374,73.762 +1,Switzerland,1994,13.568228606692793,5.949240049,41843.75688,1.055121002,4.771619748,73.708 +1,Switzerland,1995,12.625158808638439,5.535733705,48662.43977,1.050707114,6.371238971,73.654 +1,Switzerland,1996,12.891859357113923,5.652673479,46676.85094,1.050766342,9.385310344,73.6 +1,Switzerland,1997,12.849018749236068,5.633889224,40417.96228,1.05766301,14.72664421,73.546 +1,Switzerland,1998,13.024539364450781,5.710849475,41497.20261,1.055986834,23.87258864,73.492 +1,Switzerland,1999,13.859809287340937,6.077088976,40581.30705,1.056028689,42.83146907,73.438 +1,Switzerland,2000,13.785198746824467,6.044374608,37868.32306,1.063036409,64.71825317,73.383 +1,Switzerland,2001,12.334400577988188,5.408245397,38538.99005,1.059462849,73.24755976,73.375 +1,Switzerland,2002,12.798826347822322,5.61188144,41376.39399,1.046368147,79.18789483,73.401 +1,Switzerland,2003,12.093909827734073,5.302797792,48087.58314,1.050806503,84.87507976,73.427 +1,Switzerland,2004,12.315516946700406,5.39996552,53340.14766,1.050737963,85.4029135,73.452 +1,Switzerland,2005,11.743735976315113,5.149257609,54952.67372,1.048549468,92.22603163,73.478 +1,Switzerland,2006,10.4852832635669,4.59746581,57579.50195,1.051246853,99.39516725,73.504 +1,Switzerland,2007,9.728672022488942,4.377443077,63555.2375,1.053994589,108.57798,73.53 +1,Switzerland,2008,9.330592142421436,4.29252423,72487.84593,1.054176174,116.3559314,73.556 +1,Switzerland,2009,9.282730872973632,4.118140567,69927.46877,1.055159629,120.4909656,73.581 +1,Switzerland,2010,8.666380498384655,3.922011612,74605.72102,1.055459413,123.1383135,73.607 +1,Switzerland,2011,8.095713766799856,3.341808936,88415.62806,1.050576644,127.1387232,73.631 +1,Switzerland,2012,7.934291430690553,3.429188853,83538.23008,1.050618307,131.49289,73.653 +1,Switzerland,2013,7.071755611989546,3.040020761,85112.4644,1.051569133,135.8549107,73.674 +22,United States of America,1990,101.60502994528603,60.94161798,23954.47935,1.052187416,2.092050864,75.3 +22,United States of America,1991,99.6497625326908,62.26406093,24405.16481,1.053699223,2.963880131,75.701 +22,United States of America,1992,97.30833365470282,61.60065596,25492.95165,1.055061224,4.285325262,76.097 +22,United States of America,1993,95.40893324280803,60.80781147,26464.85251,1.056305189,6.157006979,76.488 +22,United States of America,1994,92.76365938815489,60.29130462,27776.63553,1.056987645,9.18561207,76.875 +22,United States of America,1995,88.4027480888787,58.10105726,28782.17502,1.057525665,12.71768704,77.257 +22,United States of America,1996,84.89419065852543,55.44886059,30068.23092,1.05790955,16.38483296,77.636 +22,United States of America,1997,80.84741522580009,52.96410686,31572.69023,1.058064825,20.32519807,78.008 +22,United States of America,1998,78.32450828206909,51.83127065,32949.19776,1.057961074,25.1174665,78.377 +22,United States of America,1999,75.21238710203686,49.97800756,34620.9289,1.05768295,30.85645141,78.742 +22,United States of America,2000,73.06070091368079,48.65911377,36449.85512,1.058451034,38.82436785,79.057 +22,United States of America,2001,68.81955031797179,45.88995456,37273.6181,1.061917057,45.11108352,79.234 +22,United States of America,2002,65.06568619873794,43.49711154,38166.03784,1.064608406,49.32056453,79.409 +22,United States of America,2003,62.86662796879071,41.97940984,39677.19835,1.063311528,55.38679309,79.583 +22,United States of America,2004,61.50728176653167,41.50117056,41921.80976,1.061042381,63.17748926,79.757 +22,United States of America,2005,59.99146531201843,40.73341716,44307.92058,1.059657349,69.02054837,79.928 +22,United States of America,2006,61.4063154521916,42.00018341,46437.06712,1.058468931,77.09164231,80.099 +22,United States of America,2007,60.97279948451296,42.28461638,48061.53766,1.05711782,82.93546295,80.269 +22,United States of America,2008,59.06621730497238,40.89628267,48401.42734,1.055985214,86.13129085,80.438 +22,United States of America,2009,54.9469470527237,38.38217701,47001.55535,1.054799682,89.61260458,80.606 +22,United States of America,2010,49.5401842911036,34.5966229,48375.40695,1.053858822,92.37840689,80.772 +22,United States of America,2011,44.84326760335935,31.41277034,49793.71352,1.054391219,95.61250193,80.944 +22,United States of America,2012,41.299623894968086,29.49719469,51450.95911,1.05407323,97.28807458,81.119 +22,United States of America,2013,37.2054912266687,26.62444205,52782.08651,1.051607933,98.46652501,81.299 +20,New Zealand,1990,50.01931421819151,NA,NA,NA,NA,NA +20,New Zealand,1991,50.133301877143914,NA,NA,NA,NA,NA +20,New Zealand,1992,48.42901457719691,NA,NA,NA,NA,NA +20,New Zealand,1993,48.305090850168874,NA,NA,NA,NA,NA +20,New Zealand,1994,49.58479715371198,NA,NA,NA,NA,NA +20,New Zealand,1995,53.12734890527613,NA,NA,NA,NA,NA +20,New Zealand,1996,55.31401667465075,NA,NA,NA,NA,NA +20,New Zealand,1997,55.08683206085289,NA,NA,NA,NA,NA +20,New Zealand,1998,50.817665493789235,NA,NA,NA,NA,NA +20,New Zealand,1999,50.57485980898316,NA,NA,NA,NA,NA +20,New Zealand,2000,51.78005049209372,NA,NA,NA,NA,NA +20,New Zealand,2001,51.86432045317614,NA,NA,NA,NA,NA +20,New Zealand,2002,52.22033670874948,NA,NA,NA,NA,NA +20,New Zealand,2003,52.83179618231263,NA,NA,NA,NA,NA +20,New Zealand,2004,53.28862141482962,NA,NA,NA,NA,NA +20,New Zealand,2005,52.61034833098724,NA,NA,NA,NA,NA +20,New Zealand,2006,54.76412836811356,NA,NA,NA,NA,NA +20,New Zealand,2007,58.83245152368504,NA,NA,NA,NA,NA +20,New Zealand,2008,59.66632171174441,NA,NA,NA,NA,NA +20,New Zealand,2009,54.56956064320956,NA,NA,NA,NA,NA +20,New Zealand,2010,50.77702069505473,NA,NA,NA,NA,NA +20,New Zealand,2011,43.96011585783876,NA,NA,NA,NA,NA +20,New Zealand,2012,40.85153478076885,NA,NA,NA,NA,NA +20,New Zealand,2013,35.36565195390478,NA,NA,NA,NA,NA diff --git a/R/Data completion in excel file.R b/R/Data completion in excel file.R index 4889950..07403d7 100644 --- a/R/Data completion in excel file.R +++ b/R/Data completion in excel file.R @@ -1,4 +1,4 @@ -library(XLConnect) +# library(XLConnect) library(tidyverse) # Connect to Excel file -------------------------------------------------------------------------------------- diff --git a/R/ITS model pre-strategy fit.R b/R/ITS model pre-strategy fit.R new file mode 100644 index 0000000..aef0d7f --- /dev/null +++ b/R/ITS model pre-strategy fit.R @@ -0,0 +1,12 @@ +library(tidyverse) +library(readxl) + +output_tables <- map(excel_sheets("Data/its_outputs.xlsx"), ~ + read_xlsx("Data/its_outputs.xlsx", sheet = .x)) + + +output_tables %>% + map(~ filter(.x, Year < 1999, + Country == "England") %>% + summarise(mspe = Metrics::mse(Value, Predict), + rsq = cor(Value, Predict) ^2)) diff --git a/R/ITS_graphing all UK countries.R b/R/ITS_graphing all UK countries.R index b797912..ef2b2bd 100644 --- a/R/ITS_graphing all UK countries.R +++ b/R/ITS_graphing all UK countries.R @@ -2,6 +2,7 @@ library(patchwork) library(tidyverse) library(readxl) library(export) +library(RColorBrewer) simple_theme <- theme( panel.background = element_blank(), @@ -14,99 +15,129 @@ simple_theme <- theme( theme_set(simple_theme) -UK_u16 <- read_xlsx("Conception rates by age and country.xlsx", sheet = "Under 16") -UK_u18 <- read_xlsx("Conception rates by age and country.xlsx", sheet = "Under 18") -UK_u20 <- read_xlsx("Conception rates by age and country.xlsx", sheet = "Under 20") +UK_u16 <- + read_xlsx("Conception rates by age and country.xlsx", sheet = "Under 16") +UK_u18 <- + read_xlsx("Conception rates by age and country.xlsx", sheet = "Under 18") +UK_u20 <- + read_xlsx("Conception rates by age and country.xlsx", sheet = "Under 20") -EstScot_u20 <- read_csv("EstScot_1985_2015.csv") %>% - mutate(Country = "Scotland") %>% - filter(Year>1986, Year < 1994) -EstScot_u18 <- read_csv("EstScotU18_1985_2015.csv") %>% - mutate(Country = "Scotland") %>% - filter(Year>1986, Year < 1994) +EstScot_u20 <- read_csv("EstScot_1985_2015.csv") %>% + mutate(Country = "Scotland") %>% + filter(Year > 1986, Year < 1994) +EstScot_u18 <- read_csv("EstScotU18_1985_2015.csv") %>% + mutate(Country = "Scotland") %>% + filter(Year > 1986, Year < 1994) # England-only rates ---------------------------------------------------- UK_u18 %>% filter(Country == "England") %>% gather("Year", "Value",-1) %>% - mutate(Year = as.numeric(Year)) %>% - # bind_rows(EstScot_u18 %>% select(Year, Country, Value)) %>% - filter(!is.na(Value), Year > 1991) %>% - ggplot(aes( - x = Year, - y = Value, - col = Country - )) + - geom_rect(data = tibble(), - aes(ymin = 0, - ymax = Inf, - xmin = 1999, - xmax = 2005), - fill = "grey", - alpha = 0.3, - inherit.aes = FALSE) + - geom_rect(data = tibble(), - aes(ymin = 0, - ymax = Inf, - xmin = 2005, - xmax = 2010), - fill = "grey", - alpha = 0.5, - inherit.aes = FALSE) + + mutate(Year = as.numeric(Year)) %>% + # bind_rows(EstScot_u18 %>% select(Year, Country, Value)) %>% + filter(!is.na(Value), Year > 1991) %>% + ggplot(aes(x = Year, + y = Value, + col = Country)) + + geom_rect( + data = tibble(), + aes( + ymin = 0, + ymax = Inf, + xmin = 1999, + xmax = 2005 + ), + fill = "grey", + alpha = 0.3, + inherit.aes = FALSE + ) + + geom_rect( + data = tibble(), + aes( + ymin = 0, + ymax = Inf, + xmin = 2005, + xmax = 2010 + ), + fill = "grey", + alpha = 0.5, + inherit.aes = FALSE + ) + geom_point(shape = 3) + geom_line(size = 1) + ylab(paste0("Rate of pregnancies to under 18s, per 1,000")) + xlab("Year") + scale_colour_manual( limits = c("England", "Wales", "Scotland"), - values = c("England" = "#CF142B", - "Wales" = "#00AB39", - "Scotland" = "#0072C6"), - drop = FALSE) + + values = c( + "England" = "#CF142B", + "Wales" = "#00AB39", + "Scotland" = "#0072C6" + ), + drop = FALSE + ) + xlim(1990, 2016) + theme(legend.position = "none") + - scale_y_continuous(breaks = c(0, 20, 40), - limits = c(0, NA), - expand = expansion(add = c(0, 2))) + + scale_y_continuous( + breaks = c(0, 20, 40), + limits = c(0, NA), + expand = expansion(add = c(0, 2)) + ) + geom_text( data = tibble( - label = c("1999 - Strategy implemented", - "2005 - Mid-term review and step-up", - "2010 - End of strategy"), + label = c( + "1999 - Strategy implemented", + "2005 - Mid-term review and step-up", + "2010 - End of strategy" + ), Year = c(1999, 2005, 2010), vjust = c(-0.3, -0.3, 1.2), height = 2 ), - aes(x = Year, y = height, vjust = vjust, label = label), + aes( + x = Year, + y = height, + vjust = vjust, + label = label + ), inherit.aes = FALSE, angle = 90, size = pts(14), - hjust = 0) + hjust = 0 + ) -ggsave("graphs/England rates 1992-2016.png", width = 155, height = 120, units = "mm", dpi= 300) +ggsave( + "graphs/England rates 1992-2016.png", + width = 155, + height = 120, + units = "mm", + dpi = 300 +) # All UK compare (figure 1-3) --------------------------------------------- UK_u18 %>% gather("Year", "Value",-1) %>% - mutate(Year = as.numeric(Year)) %>% + mutate(Year = as.numeric(Year)) %>% bind_rows(EstScot_u18 %>% select(Year, Country, Value)) %>% - filter(!is.na(Value), Year > 1991) %>% - ggplot(aes( - x = Year, - y = Value, - col = Country - )) + - geom_rect(data = tibble(), - aes(ymin = 0, - ymax = Inf, - xmin = 1999, - xmax = 2010), - fill = "grey", - alpha = 0.3, - inherit.aes = FALSE) + + filter(!is.na(Value), Year > 1991) %>% + ggplot(aes(x = Year, + y = Value, + col = Country)) + + geom_rect( + data = tibble(), + aes( + ymin = 0, + ymax = Inf, + xmin = 1999, + xmax = 2010 + ), + fill = "grey", + alpha = 0.3, + inherit.aes = FALSE + ) + # geom_rect(data = tibble(), # aes(ymin = 0, # ymax = Inf, @@ -119,56 +150,72 @@ UK_u18 %>% geom_line(size = 1) + ylab(paste0("Rate of pregnancies to under 18s, per 1,000")) + xlab("Year") + - scale_colour_manual("", + scale_colour_manual( + "", limits = c("England", "Wales", "Scotland"), - values = c("England" = "#CF142B", - "Wales" = "#00AB39", - "Scotland" = "#0072C6"), - drop = FALSE) + + values = c( + "England" = "#CF142B", + "Wales" = "#00AB39", + "Scotland" = "#0072C6" + ), + drop = FALSE + ) + xlim(1990, 2016) + - scale_y_continuous(breaks = c(0, 20, 40), - limits = c(0, 60), - expand = expansion(add = c(0, 0))) + + scale_y_continuous( + breaks = c(0, 20, 40), + limits = c(0, 60), + expand = expansion(add = c(0, 0)) + ) + geom_text( data = tibble( label = c("Strategy period"), Year = c(2005), height = 10 ), - # geom_text( - # data = tibble( - # label = c("1999 - Strategy implemented", - # "2005 - Mid-term review and step-up", - # "2010 - End of strategy"), - # Year = c(1999, 2005, 2010), - # vjust = c(-0.3, -0.3, 1.2), - # height = 2 - # ), + # geom_text( + # data = tibble( + # label = c("1999 - Strategy implemented", + # "2005 - Mid-term review and step-up", + # "2010 - End of strategy"), + # Year = c(1999, 2005, 2010), + # vjust = c(-0.3, -0.3, 1.2), + # height = 2 + # ), aes(x = Year, y = height, label = label), inherit.aes = FALSE, size = pts(14), - hjust = 0.5) + + hjust = 0.5 + ) + theme(legend.position = "bottom") -ggsave("graphs/Figure 1-3.png", width = 155, height = 120, units = "mm", dpi= 300) +ggsave( + "graphs/Figure 1-3.png", + width = 155, + height = 120, + units = "mm", + dpi = 300 +) # comparing all uk -------------------------------------------------------- -theme_set(simple_theme + - theme( - legend.position = "bottom", - legend.key = element_blank(), - legend.key.width = unit(1, "cm") - )) +theme_set( + simple_theme + + theme( + legend.position = "bottom", + legend.key = element_blank(), + legend.key.width = unit(1, "cm") + ) +) -(gr_u18_base <- +( + gr_u18_base <- UK_u18 %>% filter(Country == "Scotland" | Country == "England" | Country == "Wales") %>% gather("Year", "Value",-1) %>% - mutate(Year = as.numeric(Year)) %>% - bind_rows(EstScot_u18 %>% select(Year, Country, Value)) %>% - filter(!is.na(Value), Year > 1991) %>% + mutate(Year = as.numeric(Year)) %>% + bind_rows(EstScot_u18 %>% select(Year, Country, Value)) %>% + filter(!is.na(Value), Year > 1991) %>% ggplot(aes( x = Year, y = Value, @@ -181,40 +228,50 @@ theme_set(simple_theme + scale_colour_manual( limits = c("England", "Wales", "Scotland", "England and Wales"), # limits = c("England", "Wales", "Scotland"), - values = c("England" = "#CF142B", - "Wales" = "#00AB39", - "England and Wales" = "#A50115", - "Scotland" = "#0072C6" + values = c( + "England" = "#CF142B", + "Wales" = "#00AB39", + "England and Wales" = "#A50115", + "Scotland" = "#0072C6" ), - drop = FALSE) + + drop = FALSE + ) + xlim(1987, 2016) + theme(legend.position = "bottom") + - scale_y_continuous(limits = c(0,NA), expand = expansion(mult = c(0, 0.03))) - ) + scale_y_continuous(limits = c(0, NA), expand = expansion(mult = c(0, 0.03))) +) -(gr_u18 <- gr_u18_base + ggtitle("a) Pregnancies to under-18s 1992-2016") + - geom_vline(data = tibble(), - xintercept = 1999, - linetype = "dotted", - col = "#000000CC") + - geom_text(data = tibble(), - aes(x = 2000, y = Inf, label = "1999 Strategy launch"), - col = "#666666", - hjust = 0, - vjust = 1.5, - size = 5, - inherit.aes = FALSE)) +( + gr_u18 <- + gr_u18_base + ggtitle("a) Pregnancies to under-18s 1992-2016") + + geom_vline( + data = tibble(), + xintercept = 1999, + linetype = "dotted", + col = "#000000CC" + ) + + geom_text( + data = tibble(), + aes(x = 2000, y = Inf, label = "1999 Strategy launch"), + col = "#666666", + hjust = 0, + vjust = 1.5, + size = 5, + inherit.aes = FALSE + ) +) # ggsave("graphs/under-18 EWS 1992-2016.png", gr_u18, height = 120, width = 155, units = "mm", dpi = 400) # graph2ppt(file = "graphs/under-18.pptx", height = 13.65/2.5, width = 17.37/2.5) -(gr_u18_EW <- UK_u18 %>% filter(Country == "Scotland" | - Country == "England and Wales") %>% +( + gr_u18_EW <- UK_u18 %>% filter(Country == "Scotland" | + Country == "England and Wales") %>% gather("Year", "Value",-1) %>% mutate(Year = as.numeric(Year)) %>% - bind_rows(EstScot_u18 %>% select(Year, Country, Value)) %>% - filter(!is.na(Value)) %>% + bind_rows(EstScot_u18 %>% select(Year, Country, Value)) %>% + filter(!is.na(Value)) %>% ggplot(aes( x = Year, y = Value, @@ -226,20 +283,26 @@ theme_set(simple_theme + xlab("Year") + scale_colour_manual( limits = c("England", "Wales", "Scotland", "England and Wales"), - values = c("England" = "#CF142B", - "Wales" = "#00AB39", - "Scotland" = "#0072C6", - "England and Wales" = "#A50115"), - drop = FALSE) + - xlim(1987, 2016) + - scale_y_continuous(limits = c(0,NA), expand = expansion(mult = c(0, 0.03))) + - ggtitle("b) Pregnancies to under-18s 1987-2016 (England and Wales combined)") - ) + values = c( + "England" = "#CF142B", + "Wales" = "#00AB39", + "Scotland" = "#0072C6", + "England and Wales" = "#A50115" + ), + drop = FALSE + ) + + xlim(1987, 2016) + + scale_y_continuous(limits = c(0, NA), expand = expansion(mult = c(0, 0.03))) + + ggtitle( + "b) Pregnancies to under-18s 1987-2016 (England and Wales combined)" + ) +) -(gr_u16 <- UK_u16 %>% filter(Country == "Scotland" | - Country == "England and Wales") %>% +( + gr_u16 <- UK_u16 %>% filter(Country == "Scotland" | + Country == "England and Wales") %>% gather("Year", "Value",-1) %>% - filter(Year >= 1992) %>% + filter(Year >= 1992) %>% mutate(Year = as.numeric(Year)) %>% ggplot(aes( x = Year, @@ -252,22 +315,28 @@ theme_set(simple_theme + xlab("Year") + scale_colour_manual( limits = c("England", "Wales", "Scotland", "England and Wales"), - values = c("England" = "#CF142B", - "Wales" = "#00AB39", - "Scotland" = "#0072C6", - "England and Wales" = "#A50115"), - drop = FALSE) + + values = c( + "England" = "#CF142B", + "Wales" = "#00AB39", + "Scotland" = "#0072C6", + "England and Wales" = "#A50115" + ), + drop = FALSE + ) + xlim(1987, 2016) + - scale_y_continuous(limits = c(0,NA), expand = expansion(mult = c(0, 0.03))) + - ggtitle("c) Pregnancies to under-16s 1992-2016 (England and Wales combined)") - ) + scale_y_continuous(limits = c(0, NA), expand = expansion(mult = c(0, 0.03))) + + ggtitle( + "c) Pregnancies to under-16s 1992-2016 (England and Wales combined)" + ) +) -(gr_u20 <- UK_u20 %>% filter(Country == "Scotland" | - Country == "England and Wales") %>% +( + gr_u20 <- UK_u20 %>% filter(Country == "Scotland" | + Country == "England and Wales") %>% gather("Year", "Value",-1) %>% mutate(Year = as.numeric(Year)) %>% - bind_rows(EstScot_u20 %>% select(Year, Country, Value)) %>% - filter(!is.na(Value), Year > 1992) %>% + bind_rows(EstScot_u20 %>% select(Year, Country, Value)) %>% + filter(!is.na(Value), Year > 1992) %>% ggplot(aes( x = Year, y = Value, @@ -279,20 +348,28 @@ theme_set(simple_theme + xlab("Year") + scale_colour_manual( limits = c("England", "Wales", "Scotland", "England and Wales"), - values = c("England" = "#CF142B", - "Wales" = "#00AB39", - "Scotland" = "#0072C6", - "England and Wales" = "#A50115"), - drop = FALSE) + - xlim(1987, 2016) + - scale_y_continuous(limits = c(0,NA), expand = expansion(mult = c(0, 0.03))) + - ggtitle("d) Pregnancies to under-20s 1992-2016 (England and Wales combined)") - ) + values = c( + "England" = "#CF142B", + "Wales" = "#00AB39", + "Scotland" = "#0072C6", + "England and Wales" = "#A50115" + ), + drop = FALSE + ) + + xlim(1987, 2016) + + scale_y_continuous(limits = c(0, NA), expand = expansion(mult = c(0, 0.03))) + + ggtitle( + "d) Pregnancies to under-20s 1992-2016 (England and Wales combined)" + ) +) (((gr_u18 | gr_u18_EW) / - (gr_u16 | gr_u20 )) / + (gr_u16 | gr_u20)) / guide_area() + - plot_layout(guides = 'collect'#, widths = unit(173, "mm"), heights = unit(c(55,55,20), "mm")) + plot_layout( + guides = 'collect', + widths = unit(173, "mm"), + heights = unit(c(55, 55, 20), "mm") )) #%>% #ggsave("graphs/test2.svg",., units = "mm", height = 400, width = 400) @@ -301,100 +378,402 @@ theme_set(simple_theme + gr_u18_base + scale_x_continuous() -ggsave("graphs/u18_UK_rates.svg", - gr_u18 + - theme( - # title = element_text(size = 14), - # axis.title = element_text(size = 12), - #legend.position = "none", - text = element_text(size = 12) - ), - dpi = 400, - units = "mm", - width = 173, - height = 136) - -ggsave("graphs/u18_UK_rates_mono.svg", - gr_u18 + - theme( - # title = element_text(size = 14), - # axis.title = element_text(size = 12), - #legend.position = "none", - text = element_text(size = 12) - ) + - scale_colour_grey(limits = c("England", "Wales", "Scotland")), - dpi = 400, - units = "mm", - width = 173, - height = 136) - - - -ggsave("graphs/u18_UK_EW.svg", - gr_u18_EW + - theme(title = element_text(size = 14), - axis.title = element_text(size = 12), - legend.position = "none"), - dpi = 400, - units = "mm", - width = 200, - height = 150) -ggsave("graphs/u16_UK_rates.svg", - gr_u16 + - theme(title = element_text(size = 14), - axis.title = element_text(size = 12), - legend.position = "none"), - dpi = 400, - units = "mm", - width = 200, - height = 150) -ggsave("graphs/u20_UK_rates.svg", - gr_u20 + - theme(title = element_text(size = 14), - axis.title = element_text(size = 12), - legend.position = "none"), - dpi = 400, - units = "mm", - width = 200, - height = 150) - -graph2doc(gr_u18, "graphs/Under-18 EWS.docx", height = 13.65/2.5, width = 17.37/2.5) +ggsave( + "graphs/u18_UK_rates.svg", + gr_u18 + + theme(# title = element_text(size = 14), + # axis.title = element_text(size = 12), + #legend.position = "none", + text = element_text(size = 12)), + dpi = 400, + units = "mm", + width = 173, + height = 136 +) + +ggsave( + "graphs/u18_UK_rates_mono.svg", + gr_u18 + + theme(# title = element_text(size = 14), + # axis.title = element_text(size = 12), + #legend.position = "none", + text = element_text(size = 12)) + + scale_colour_grey(limits = c("England", "Wales", "Scotland")), + dpi = 400, + units = "mm", + width = 173, + height = 136 +) -# producing summaries ----------------------------------------------------- -UK_u18 %>% group_by(Country) %>% select(`1998`, `2016`) %>% mutate(drop = (`2016`-`1998`)/`1998`*100) -UK_u16 %>% group_by(Country) %>% select(`1998`, `2016`) %>% mutate(drop = (`2016`-`1998`)/`1998`*100) -UK_u20 %>% group_by(Country) %>% select(`1998`, `2016`) %>% mutate(drop = (`2016`-`1998`)/`1998`*100) -rates <- UK_u18 %>% filter(Country %in% c("England", "England and Wales")) %>% - gather("Year", "rate", -Country) %>% - filter(Year > 1991, Year < 2017) %>% - spread(Country, rate) %>% +ggsave( + "graphs/u18_UK_EW.svg", + gr_u18_EW + + theme( + title = element_text(size = 14), + axis.title = element_text(size = 12), + legend.position = "none" + ), + dpi = 400, + units = "mm", + width = 200, + height = 150 +) +ggsave( + "graphs/u16_UK_rates.svg", + gr_u16 + + theme( + title = element_text(size = 14), + axis.title = element_text(size = 12), + legend.position = "none" + ), + dpi = 400, + units = "mm", + width = 200, + height = 150 +) +ggsave( + "graphs/u20_UK_rates.svg", + gr_u20 + + theme( + title = element_text(size = 14), + axis.title = element_text(size = 12), + legend.position = "none" + ), + dpi = 400, + units = "mm", + width = 200, + height = 150 +) + +graph2doc(gr_u18, + "graphs/Under-18 EWS.docx", + height = 13.65 / 2.5, + width = 17.37 / 2.5) + +# all in one graph -------------------------------------------------------- + +theme_set( + simple_theme + + theme( + legend.position = "bottom", + legend.key = element_blank(), + legend.key.width = unit(1, "cm") + ) +) + +all_rates <- list("Under 16" = UK_u16, + "Under 18" = UK_u18, + "Under 20" = UK_u20) %>% + map2_dfr( + names(.), + ~ .x %>% + filter( + Country %in% + c("Scotland", "England", "Wales", "England and Wales") + ) %>% + pivot_longer( + -Country, + names_to = "Year", + values_to = "rate", + names_transform = list(Year = as.integer) + ) %>% + filter(!is.na(rate)) %>% + mutate(agegrp = .y) + ) %>% + bind_rows(EstScot_u18 %>% + select(Country, Year, rate = Value) %>% + mutate(agegrp = "Under 18")) %>% + bind_rows(EstScot_u20 %>% + select(Country, Year, rate = Value) %>% + mutate(agegrp = "Under 20")) + +ribbon_bits <- + all_rates %>% + select(agegrp, Year, rate) %>% + group_by(agegrp, Year) %>% + summarise(max = max(rate), + min = min(rate)) %>% + pivot_longer(c(max, min)) %>% + pivot_wider(c(agegrp, name), + names_from = "Year", + values_from = "value") %>% + mutate(`1986` = NA, `2017` = NA) %>% + pivot_longer( + cols = -c(agegrp, name), + names_to = "Year", + values_to = "value" + ) %>% + pivot_wider(c(agegrp, Year), + names_from = "name", + values_from = "value") %>% + arrange(agegrp, Year) %>% + group_by(Year) %>% + mutate( + min = ifelse(agegrp == "Under 16", 0, min), + max = ifelse(agegrp == "Under 20", 70, max) + ) %>% + group_by(agegrp) %>% + mutate( + max = ifelse(is.na(max), lead(max), max), + max = ifelse(is.na(max), lead(max), max), + max = ifelse(is.na(max), lead(max), max), + max = ifelse(is.na(max), lead(max), max), + max = ifelse(is.na(max), lag(max), max), + min = ifelse(is.na(min), lead(min), min), + min = ifelse(is.na(min), lead(min), min), + min = ifelse(is.na(min), lead(min), min), + min = ifelse(is.na(min), lead(min), min), + min = ifelse(is.na(min), lag(min), min) + ) %>% + ungroup() %>% + pivot_wider(Year, names_from = agegrp, + values_from = c(min, max)) %>% + transmute( + Year, + `min_Under 16`, + `max_Under 16` = (`max_Under 16` + `min_Under 18`) / 2 - 0.5, + `min_Under 18` = `max_Under 16` + 1, + `max_Under 18` = (`max_Under 18` + `min_Under 20`) / 2 - 0.5, + `min_Under 20` = `max_Under 18` + 1, + `max_Under 20` + ) %>% + pivot_longer( + -Year, + names_to = c(".value", "agegrp"), + values_to = c("min", "max"), + names_sep = "_" + ) %>% + mutate(Year = as.numeric(Year)) + +# *England and wales separately --------------------------- + +all_rates %>% + filter(Country != "England and Wales") %>% + ggplot(aes( + Year, + rate, + colour = Country, + group = interaction(Country, agegrp) + )) + + geom_ribbon( + data = ribbon_bits, + aes( + x = Year, + ymin = min, + ymax = max, + # group = agegrp + fill = agegrp + ), + alpha = 0.1, + inherit.aes = FALSE, + # fill = "lightgrey" + # colour = "white", + # size = 1 + ) + + scale_fill_brewer(palette = 'Dark2') + + geom_segment(data = tibble( + Year = c(1996, 1999, 2008), + label = c("'Pill scare'", "Strategy launch", "Common Shock") + ), + aes(x = Year, xend = Year, y = 0, yend = 72), + linetype = "dotted", + colour = "grey", + size = 1, + inherit.aes = FALSE) + + # geom_point(shape = 3) + + geom_line() + + ylab(paste0("Rate of pregnancies per 1,000 women")) + + xlab("Year") + + scale_colour_manual( + "", + limits = c("England", + "Wales", + # "England and Wales" + "Scotland"), + values = c( + "England" = "#CF142B", + "Wales" = "#00AB39", + # "England and Wales" = "#A50115" + "Scotland" = "#0072C6" + ) + ) + + scale_x_continuous(limits = c(1986, NA), expand = expansion(add = c(0, 0))) + + scale_y_continuous(limits = c(0, 75), expand = expansion(add = c(0, -5))) + + geom_text( + data = tibble( + x = 1987, + y = c(15, 33, 65), + label = c("Under-16 rates", "Under-18 rates", "Under-20 rates"), + ), + aes(x, y, label = label, colour = label), + hjust = 0, + inherit.aes = FALSE, + size = pts(12), + fontface = "bold", + colour = brewer.pal(3, "Dark2") + ) + + guides(fill = FALSE) + + theme(text = element_text(size = 12), + plot.margin = unit(c(1,0,0,0), "cm")) + + geom_text( + data = tibble( + Year = c(1996, 1999, 2008), + label = c("1996 'Pill scare'", "1999 Strategy launch", "2008 Common Shock") + ), + aes(x = Year, y = 74, label = label), + inherit.aes = FALSE, + hjust = c(1,0.1,0) + ) + + coord_cartesian(clip = "off") + +ggsave( + "graphs/All countries rates.png", + width = 155, + height = 120, + units = "mm", + dpi = 400 +) + +# *Same but with England and Wales combined ------------------------------------ + +all_rates %>% + filter(Country %in% c("Scotland", "England and Wales")) %>% + ggplot(aes( + Year, + rate, + colour = Country, + group = interaction(Country, agegrp) + )) + + geom_ribbon( + data = ribbon_bits, + aes( + x = Year, + ymin = min, + ymax = max, + fill = agegrp + ), + alpha = 0.1, + inherit.aes = FALSE, + # colour = "white", + # size = 1 + ) + + geom_segment(data = tibble( + Year = c(1996, 1999, 2008), + label = c("'Pill scare'", "Strategy launch", "Common Shock") + ), + aes(x = Year, xend = Year, y = 0, yend = 74), + linetype = "dotted", + colour = "grey", + size = 1, + inherit.aes = FALSE) + + # geom_point(shape = 3) + + geom_line() + + ylab(paste0("Rate of pregnancies per 1,000 women")) + + xlab("Year") + + scale_colour_manual( + "", + limits = c( + # "England", + # "Wales", + "England and Wales", + "Scotland"), + values = c( + # "England" = "#CF142B", + # "Wales" = "#00AB39", + "England and Wales" = "#A50115", + "Scotland" = "#0072C6" + ) + ) + + scale_x_continuous(limits = c(1986, NA), expand = expansion(add = c(0, 0))) + + scale_y_continuous(limits = c(0, 76), expand = expansion(add = c(0, -6))) + + scale_fill_brewer(palette = 'Dark2') + + geom_text( + data = tibble( + x = 1987, + y = c(15, 33, 72), + label = c("Under-16 rates", "Under-18 rates", "Under-20 rates"), + ), + aes(x, y, label = label, colour = label), + hjust = 0, + inherit.aes = FALSE, + size = pts(12), + fontface = "bold", + colour = brewer.pal(3, "Dark2") + ) + + guides(fill = FALSE) + + theme(text = element_text(size = 12), + plot.margin = unit(c(1,0,0,0), "cm")) + + geom_text( + data = tibble( + Year = c(1996, 1999, 2008), + label = c("1996 'Pill scare'", "1999 Strategy launch", "2008 Common Shock") + ), + aes(x = Year, y = 76, label = label), + inherit.aes = FALSE, + hjust = c(1,0.1,0) + ) + + coord_cartesian(clip = "off") + + +ggsave( + "graphs/All countries rates-EW combo.png", + width = 155, + height = 120, + units = "mm", + dpi = 400 +) + + +# producing summaries ----------------------------------------------------- + +UK_u18 %>% group_by(Country) %>% select(`1998`, `2016`) %>% mutate(drop = (`2016` - + `1998`) / `1998` * 100) +UK_u16 %>% group_by(Country) %>% select(`1998`, `2016`) %>% mutate(drop = (`2016` - + `1998`) / `1998` * 100) +UK_u20 %>% group_by(Country) %>% select(`1998`, `2016`) %>% mutate(drop = (`2016` - + `1998`) / `1998` * 100) + +rates <- + UK_u18 %>% filter(Country %in% c("England", "England and Wales")) %>% + gather("Year", "rate", -Country) %>% + filter(Year > 1991, Year < 2017) %>% + spread(Country, rate) %>% select(Year, England, EW = `England and Wales`) -cor(rates$England, rates$EW)^2 +cor(rates$England, rates$EW) ^ 2 -rates %>% mutate(spe = (England - EW)^2) %>% - summarise(mspe = mean(spe), - rmse = sqrt(mspe), - R2 = cor(England, EW)^2) +rates %>% mutate(spe = (England - EW) ^ 2) %>% + summarise( + mspe = mean(spe), + rmse = sqrt(mspe), + R2 = cor(England, EW) ^ 2 + ) Metrics::rmse(rates$England, rates$EW) # output synth graphs ----------------------------------------------------- -ulhg <- gr_u18_sp + +ulhg <- gr_u18_sp + geom_line(data = tibble(x = 1999, y = 15), aes(x, y, colour = "Placebo countries")) + - scale_colour_manual(name = "Data", - breaks = c("Treated", "Synthetic", "Placebo countries"), - labels = c("England and Wales", "Synthetic", "Placebo countries"), - values = c("Synthetic" = sphsu_cols("Turquoise", names = FALSE), - "Treated" = sphsu_cols("Thistle", names = FALSE), - "Placebo countries" = "grey"), drop = FALSE) + - theme(legend.position = "bottom", - axis.line = element_blank(), - legend.text = element_text(size=12)) + + scale_colour_manual( + name = "Data", + breaks = c("Treated", "Synthetic", "Placebo countries"), + labels = c("England and Wales", "Synthetic", "Placebo countries"), + values = c( + "Synthetic" = sphsu_cols("Turquoise", names = FALSE), + "Treated" = sphsu_cols("Thistle", names = FALSE), + "Placebo countries" = "grey" + ), + drop = FALSE + ) + + theme( + legend.position = "bottom", + axis.line = element_blank(), + legend.text = element_text(size = 12) + ) + ggtitle("a) England and Wales vs Synthetic Control\nUnder-18 births") urhg <- pb_plot_u18_sp + @@ -402,28 +781,41 @@ urhg <- pb_plot_u18_sp + ugs <- (ulhg | urhg) -llhg <- gr_u20_sp + +llhg <- gr_u20_sp + geom_line(data = tibble(x = 1999, y = 15), aes(x, y, colour = "Placebo countries")) + - scale_colour_manual(name = "Data", - breaks = c("Treated", "Synthetic", "Placebo countries"), - labels = c("England and Wales", "Synthetic", "Placebo countries"), - values = c("Synthetic" = sphsu_cols("Turquoise", names = FALSE), - "Treated" = sphsu_cols("Thistle", names = FALSE), - "Placebo countries" = "grey"), drop = FALSE) + - theme(legend.position = "bottom", - axis.line = element_blank(), - legend.text = element_text(size=12)) + + scale_colour_manual( + name = "Data", + breaks = c("Treated", "Synthetic", "Placebo countries"), + labels = c("England and Wales", "Synthetic", "Placebo countries"), + values = c( + "Synthetic" = sphsu_cols("Turquoise", names = FALSE), + "Treated" = sphsu_cols("Thistle", names = FALSE), + "Placebo countries" = "grey" + ), + drop = FALSE + ) + + theme( + legend.position = "bottom", + axis.line = element_blank(), + legend.text = element_text(size = 12) + ) + ggtitle("c) England and Wales vs Synthetic Control\nUnder-20 pregnancies") lrhg <- pb_plot_u20_sp + ggtitle("d) Gaps between observed and control, plotted by country\n") -lgs <- (llhg | lrhg) +lgs <- (llhg | lrhg) -(ugs / lgs) / guide_area() + plot_layout(guides = "collect", heights = c(6,6,1)) +(ugs / lgs) / guide_area() + plot_layout(guides = "collect", heights = c(6, 6, 1)) -ggsave("graphs/Figure 4.svg", dpi = 300, units = "mm", width = 300, height = 300) +ggsave( + "graphs/Figure 4.svg", + dpi = 300, + units = "mm", + width = 300, + height = 300 +) # start and end ----------------------------------------------------------- @@ -432,8 +824,8 @@ UK_u18 %>% filter(Country == "Scotland" | Country == "England" | Country == "Wales") %>% gather("Year", "Value",-1) %>% - mutate(Year = as.numeric(Year)) %>% - bind_rows(EstScot_u18 %>% select(Year, Country, Value)) %>% - filter(!is.na(Value), Year %in% c(1998, 2016)) %>% - pivot_wider(names_from = "Year", values_from = "Value") %>% - mutate(perc_change = 100*(`1998`-`2016`)/`1998`) + mutate(Year = as.numeric(Year)) %>% + bind_rows(EstScot_u18 %>% select(Year, Country, Value)) %>% + filter(!is.na(Value), Year %in% c(1998, 2016)) %>% + pivot_wider(names_from = "Year", values_from = "Value") %>% + mutate(perc_change = 100 * (`1998` - `2016`) / `1998`) diff --git a/R/Summary table and plot for its models.R b/R/Summary table and plot for its models.R new file mode 100644 index 0000000..f67f38e --- /dev/null +++ b/R/Summary table and plot for its models.R @@ -0,0 +1,269 @@ +library(tidyverse) +library(meta) +library(patchwork) +library(gridExtra) + +source('R/read_in_its_results.R', echo=FALSE) + + +meta_analyses %>% + map( + ~ forest( + .x$re, + prediction = FALSE, + comb.fixed = FALSE, + leftlabs = c("Model", str_to_sentence(.x$Coefficient), "SE"), + print.subgroup.labels = TRUE, + overall = TRUE + ) + ) + +simple_theme <- theme( + panel.background = element_blank(), + legend.key = element_blank(), + panel.grid.major = element_line(colour = "#e0e0e0"), + panel.grid.minor = element_blank(), + axis.line = element_line(colour = "#666666"), + legend.text = element_text(size = 12) +) +theme_set(simple_theme) + + +tidied_results <- results %>% + mutate(Coefficient = factor(Coefficient, levels = c("trend", "level"), + labels = str_to_sentence(c("trend", "level"))), + facet = factor(case_when( + comparison == 0 ~ "England only models", + primary == "Primary comparison" ~ "Comparison models", + TRUE ~ primary + ), + levels = c("England only models", "Comparison models", "Robustness and sensitivity")), + model = fct_relabel(model, str_to_sentence)) + +# Eng_only <- tidied_results %>% +# filter(comparison == 0) %>% +# ggplot(aes(Estimate, fct_rev(model))) + +# geom_vline(xintercept = 0, colour = "darkgrey", size = 1) + +# geom_point(size = 3, shape = 'diamond') + +# geom_linerange(aes(xmin = `Lower 95% CI`, xmax = `Upper 95% CI`)) + +# theme(panel.grid.major.y = element_blank(), +# axis.line.y = element_blank(), +# panel.spacing = unit(2, "cm"), +# plot.margin = unit(c(0.5,2.5,0.5,0.5), units = "cm")) + +# # scale_x_continuous(expand = expansion(add = c(0.5, 0.5))) + +# scale_y_discrete("Model") + +# facet_grid(. ~ Coefficient, +# scales = "free") + +# geom_text(aes(x = Inf, +# label = paste0(Estimate, "\n(", `Lower 95% CI`, " to ", `Upper 95% CI`, ")")), +# hjust = 0) + +# coord_cartesian(clip = "off") + +# ggtitle("Coefficients of England-only models") + + +all_plot <- tidied_results %>% + # filter(comparison == 1) %>% + ggplot(aes(Estimate, fct_rev(model))) + + geom_vline(xintercept = 0, colour = "darkgrey", size = 1) + + geom_point(size = 3, shape = 'diamond') + + geom_linerange(aes(xmin = `Lower 95% CI`, xmax = `Upper 95% CI`)) + + theme(panel.grid.major.y = element_blank(), + axis.line.y = element_blank(), + panel.spacing.x = unit(3.5, units = "cm"), + panel.spacing.y = unit(1, "cm"), + plot.margin = unit(c(0.5,3.5,0.5,0.5), units = "cm"), + strip.background.y = element_blank(), + strip.placement = "outside") + + scale_y_discrete("Model") + + facet_grid(facet ~ Coefficient, + scales = "free", + space = "free_y", + switch = "y") + + geom_text(aes(x = Inf, + label = paste0(round(digits = 2,Estimate), " (", + round(digits = 2,`Lower 95% CI`), " to ", + round(digits = 2,`Upper 95% CI`), ")")), + hjust = 0) + + coord_cartesian(clip = "off") + + +pg <- ggplotGrob(all_plot) + +pg$grobs[[21]]$layout$clip <- "off" + +ggpubr::as_ggplot(pg) + +ggsave( + "graphs/Figure 5-13.png", + width = 155, + height = 160, + units = "mm", + dpi = 300 +) + + +# Try it as a table ------------------------------------------------------- + +all_tidy_df <- tidied_results %>% + mutate( + Comparators = case_when( + model %in% c("Model 1", "Model 2", "Model 5") ~ "England only", + model %in% c("Model 3", "Model 6") ~ "England and Scotland", + model %in% c("Model 4", "Model 7") ~ "England and Wales", + model %in% c("Model 8", "Model 9", "Model 10") ~ "Eng/Wal and Scotland", + ), + `Age group` = case_when( + model == "Model 9" ~ "Under 16", + model == "Model 10" ~ "Under 20", + TRUE ~ "Under 18" + ), + `Pill scare` = case_when( + model == "Model 1" ~ "", + TRUE ~ "\u2713" + ), + `Common shock` = case_when( + model %in% c("Model 5", "Model 6", "Model 7") ~ "\u2713", + TRUE ~ "" + ), + est = paste0(round(digits = 2,Estimate), " (", + round(digits = 2,`Lower 95% CI`), " to ", + round(digits = 2,`Upper 95% CI`), ")"), + model = fct_rev(model) + ) + +draw_forest_table <- function(coefficient = "Trend", data = all_tidy_df) { + +forest1 <- all_tidy_df %>% + filter(Coefficient == coefficient) %>% + ggplot(aes(Estimate, model)) + + geom_vline(xintercept = 0, colour = "darkgrey", size = 1) + + geom_point(size = 3, shape = 'diamond') + + geom_linerange(aes(xmin = `Lower 95% CI`, xmax = `Upper 95% CI`)) + + theme( + strip.text = element_blank(), + panel.spacing.y = unit(1, "cm"), + plot.margin = margin(l = 0, r = 0), + panel.grid.major.y = element_blank(), + axis.ticks.y = element_blank(), + axis.text.y = element_blank(), + axis.line.y = element_blank(), + axis.title.y = element_blank(), + # panel.background = element_rect(colour = "lightblue"), + strip.background.y = element_blank(), + plot.title = element_text(size = 10), + strip.placement = "outside" + )+ + facet_grid(facet ~ ., + scales = "free", + space = "free_y", + switch = "y") + + # scale_x_continuous(limits = c(-4, 6)) + + ggtitle(" \n ") + +base_plot <- all_tidy_df %>% + filter(Coefficient == coefficient) %>% + ggplot(aes(x = 0, y = model)) + + ylab(NULL) + + xlab(" ") + + facet_grid(facet ~ ., + scales = "free", + space = "free_y", + switch = "y") + + theme( + strip.text = element_blank(), + panel.spacing.y = unit(1, "cm"), + plot.margin = margin(l = 0, r = 0), + axis.text.y = element_blank(), + axis.title.y = element_blank(), + axis.line = element_blank(), + axis.ticks = element_blank(), + # axis.line.x = element_line(colour = "white"), + axis.text.x = element_text(color = "white", size = 12), + ## need text to be printed so it stays aligned with figure but white so it's invisible + legend.position = "none", + # panel.background = element_rect(colour = "lightblue", fill = "white"), + # panel.border = element_blank(), + panel.grid.major = element_blank(), + panel.grid.minor = element_blank(), + plot.title = element_text(size = 10, hjust = 0) + )+ + coord_cartesian(clip = "off") + + scale_x_continuous(expand = expansion(add = c(0,0)), limits = c(0,2)) + + +lab1 <- base_plot + + geom_text(aes(label = Comparators), hjust = 0, size = pts(9)) + + # xlim(0, 2) + + ggtitle("\nComparators") + + theme(strip.text = element_text(colour = "black"), + strip.background = element_blank(), + strip.placement = "outside" ) + + +lab2 <- base_plot + + geom_text(aes(label = `Age group`), hjust = 0, size = pts(9)) + + ggtitle("\nAge group") + +lab3 <- base_plot + + geom_text(aes(x = 0, label = `Pill scare`), hjust = 0.5, size = pts(9)) + + ggtitle("Pill\nscare") + + scale_x_continuous(expand = expansion(add = c(0,0)), limits = c(-1,1)) + + theme(plot.title = element_text(hjust = 0.5)) + +lab4 <- base_plot + + geom_text(aes(x = 0, label = `Common shock`), hjust = 0.5, size = pts(9)) + + ggtitle("2008\nshock") + + scale_x_continuous(expand = expansion(add = c(0,0)), limits = c(-1,1)) + + theme(plot.title = element_text(hjust = 0.5)) + +lab5 <- base_plot + + geom_text(aes(label = est, x = Inf), hjust = 1, size = pts(9)) + + ggtitle(glue::glue("{coefficient} change\n(95%CI)")) + + theme(plot.title = element_text(hjust = 0.5)) + +lab1_grob <- ggplotGrob(lab1) +for (i in grep("strip", lab1_grob$grobs)) { + lab1_grob$grobs[[i]]$layout$clip <- "off" +} + +grid.arrange(lab1_grob, lab2, lab3, lab4, lab5, forest1, layout_matrix = + matrix(c( + 1,1,1, + 1,1,1,1,1, + 2,2, + 2,2, + 3, + 3, + 4, + 4, + 5,5,5, + 5,5,5,5, + 6,6,6,6, + 6,6,6,6 + ), nrow = 1)) + + +} + +trend_forest <- draw_forest_table() + +ggsave( + "graphs/Figure 5-13_alt.png", + trend_forest, + width = 155, + height = 160, + units = "mm", + dpi = 400 +) + +level_forest <- draw_forest_table("Level") + +ggsave( + "graphs/Figure 5-14_alt.png", + level_forest, + width = 155, + height = 160, + units = "mm", + dpi = 400 +) + diff --git a/R/Synth save pre-intervention year graphs only.R b/R/Synth save pre-intervention year graphs only.R new file mode 100644 index 0000000..129b425 --- /dev/null +++ b/R/Synth save pre-intervention year graphs only.R @@ -0,0 +1,67 @@ +synthData_u18_filt %>% + filter(Year < 1999) %>% + ggplot(aes(Year, rate, col = Country)) + + geom_line(size = 1) + + scale_colour_sphsu() + + theme_sphsu_light() + + theme( + panel.grid.major = element_line(colour = "#e0e0e0"), + panel.grid.minor = element_blank(), + legend.position = "none", + plot.margin = unit(c(0.5,5,0,0), "cm"), + text = element_text(family = "sans", size = 10)) + + coord_cartesian(clip = "off") + + geom_text_repel(data = synthData_u18_filt %>% + filter(Year == 1998), + aes(x = Year+0.1, + y = rate, + label = Country), + family = "sans", + hjust = 0, + size = 8*(5/14), + nudge_x = 1, + direction = "y", + xlim = c(NA, 2005), + ylim = c(-1, 40), + point.padding = 0) + + ylab("Under-18 birth rate (per 1,000 women)") + + scale_x_continuous(expand = expansion(add = c(0, -1)), limits = c(1990, 1999)) + + scale_y_continuous(expand = c(0,0), limits = c(0, NA)) + +ggsave("graphs/Under-18 all countries.png", width = 155, height = 120, units = "mm", dpi = 400) + + + + + +synthData_u20_filt %>% + filter(Year < 1999) %>% + ggplot(aes(Year, pRate, col = Country)) + + geom_line(size = 1) + + scale_colour_sphsu() + + theme_sphsu_light() + + theme( + panel.grid.major = element_line(colour = "#e0e0e0"), + panel.grid.minor = element_blank(), + legend.position = "none", + plot.margin = unit(c(0.5,5,0,0), "cm"), + text = element_text(family = "sans", size = 10)) + + coord_cartesian(clip = "off") + + geom_text_repel(data = synthData_u20_filt %>% + filter(Year == 1998), + aes(x = Year+0.1, + y = pRate, + label = Country), + family = "sans", + hjust = 0, + size = 8*(5/14), + nudge_x = 1, + direction = "y", + xlim = c(NA, 2005), + ylim = c(-1, 100), + point.padding = 0) + + ylab("Under-20 pregnancy rate (per 1,000 women)") + + scale_x_continuous(expand = expansion(add = c(0, -1)), limits = c(1990, 1999)) + + scale_y_continuous(expand = c(0,0), limits = c(0, NA)) + +ggsave("graphs/Under-20 all countries.png", width = 155, height = 120, units = "mm", dpi = 400) diff --git a/R/Synth_functions.R b/R/Synth_functions.R index e476131..a71a8e4 100644 --- a/R/Synth_functions.R +++ b/R/Synth_functions.R @@ -2,97 +2,126 @@ # so = synth.res (output from `synth` function) # dp = dataprep.res (output from `dataprep` function) -gg_synth <- function(dp = NULL, md = NULL, yr = 1999, post = FALSE, mspe = NULL, mspeOptim = FALSE) { - require(dplyr) - require(SPHSUgraphs) - require(Synth) - - - if ((is.null(dp)&&is.null(md))|(!is.null(dp)&&!is.null(md))) - stop("Please enter either dataprep object or model") - - if (is.null(md)&&!is.null(dp)) { +gg_synth <- + function(dp = NULL, + md = NULL, + yr = 1999, + post = FALSE, + mspe = NULL, + mspeOptim = FALSE, + linesize = 1) { + require(dplyr) + require(SPHSUgraphs) + require(Synth) - agegrp <- gsub("^.*(\\d{2}).*$","\\1", deparse(substitute(dp))) - so <- synth(dp) - synthC <- dp$Y0 %*% so$solution.w - md <- tibble(Year = as.numeric(rownames(dp$Y1)), Treated = dp$Y1[,1], Synthetic = synthC[,1]) %>% - gather("Group", "Rate", -1) - if (is.null(mspe) & mspeOptim){ - mspe <- so$loss.v[1] + if ((is.null(dp) && is.null(md)) | (!is.null(dp) && !is.null(md))) + stop("Please enter either dataprep object or model") + + if (is.null(md) && !is.null(dp)) { + agegrp <- gsub("^.*(\\d{2}).*$", "\\1", deparse(substitute(dp))) + so <- synth(dp) + synthC <- dp$Y0 %*% so$solution.w + + md <- + tibble( + Year = as.numeric(rownames(dp$Y1)), + Treated = dp$Y1[, 1], + Synthetic = synthC[, 1] + ) %>% + gather("Group", "Rate",-1) + if (is.null(mspe) & mspeOptim) { + mspe <- so$loss.v[1] + } + } else { + agegrp <- gsub("^.*(\\d{2}).*$", "\\1", deparse(substitute(md))) } - } else { - agegrp <- gsub("^.*(\\d{2}).*$","\\1", deparse(substitute(md))) - } - - if(post){ - xmax = NA - } else { - xmax = yr - md <- md %>% filter(Year% filter(Year < yr) + } + + if (is.null(mspe) & mspeOptim) { + stop( + "Please enter mspe for the synth output, or change mspeOptim to 'FALSE' to calculate from whole pre-intervention period." + ) + } + + if (!is.null(mspe)) { + mspe <- signif(mspe, 3) + } else { + mspe <- pre_MSPE(md) + } + + + plot <- + ggplot(md, aes(Year, Rate, col = Group)) + # no linetype change + # plot <- ggplot(md, aes(Year, Rate, col = Group, linetype = Group)) + + geom_line(size = linesize) + + theme_sphsu_light() + + ylab(paste0("Under-", agegrp, " rate (per 1,000 women)")) + + theme( + legend.title = element_blank(), + panel.grid.major = element_line(colour = "#e0e0e0"), + panel.grid.minor = element_blank(), + # line = element_blank() + ) + + # scale_linetype_manual(name = "Data", values = c("Synthetic" = "dashed", "Treated" = "solid")) + # no linetype change + scale_colour_manual( + name = "Data", + breaks = c("Treated", "Synthetic"), + labels = c("England and Wales", "Synthetic"), + values = c( + "Synthetic" = sphsu_cols("Turquoise", names = FALSE), + "Treated" = sphsu_cols("Thistle", names = FALSE) + ) + ) + + # scale_colour_manual(name = "Data", labels = c("England and Wales", "Synthetic"), values = c("Synthetic" = sphsu_cols("Turquoise", names = FALSE), "Treated" = sphsu_cols("Thistle", names = FALSE))) + + geom_vline(xintercept = 1998.5, linetype = "dotted") + + scale_x_continuous(limits = c(NA, xmax)) + + scale_y_continuous(limits = c(0, NA)) + + labs(subtitle = paste0("Pre-intervention MSPE = ", mspe)) + + return(plot) + } - - - plot <- ggplot(md, aes(Year, Rate, col = Group)) + # no linetype change - # plot <- ggplot(md, aes(Year, Rate, col = Group, linetype = Group)) + - geom_line(size = 2) + - theme_sphsu_light() + - ylab(paste0("Under-", agegrp, " rate (per 1,000 women)")) + - theme(legend.title = element_blank(), - panel.grid.major = element_line(colour = "#e0e0e0"), - panel.grid.minor = element_blank(), - # line = element_blank() - ) + - # scale_linetype_manual(name = "Data", values = c("Synthetic" = "dashed", "Treated" = "solid")) + # no linetype change - scale_colour_manual(name = "Data", - breaks = c("Treated", "Synthetic"), - labels = c("England and Wales", "Synthetic"), - values = c("Synthetic" = sphsu_cols("Turquoise", names = FALSE), "Treated" = sphsu_cols("Thistle", names = FALSE))) + - # scale_colour_manual(name = "Data", labels = c("England and Wales", "Synthetic"), values = c("Synthetic" = sphsu_cols("Turquoise", names = FALSE), "Treated" = sphsu_cols("Thistle", names = FALSE))) + - geom_vline(xintercept = 1998.5, linetype = "dotted") + - scale_x_continuous(limits = c(NA, xmax)) + - scale_y_continuous(limits = c(0, NA)) + - labs(subtitle = paste0("Pre-intervention MSPE = ", mspe)) - - return(plot) - -} -predvalues_synth <- function(dp, synth_outputs = TRUE, yr = 1999, ...) { - require(dplyr) - require(Synth) - - so <- synth(dp, ...) - synthC <- dp$Y0 %*% so$solution.w - - if (synth_outputs){ - so_name <- gsub("^[a-z]+_(.*$)", "so_\\1", deparse(substitute(dp))) - st_name <- gsub("^[a-z]+_(.*$)", "st_\\1", deparse(substitute(dp))) - print(paste("outputting", so_name, "and", st_name)) - st <- synth.tab(so, dp) +predvalues_synth <- + function(dp, + synth_outputs = TRUE, + yr = 1999, + ...) { + require(dplyr) + require(Synth) + + so <- synth(dp, ...) + synthC <- dp$Y0 %*% so$solution.w + + if (synth_outputs) { + so_name <- gsub("^[a-z]+_(.*$)", "so_\\1", deparse(substitute(dp))) + st_name <- + gsub("^[a-z]+_(.*$)", "st_\\1", deparse(substitute(dp))) + print(paste("outputting", so_name, "and", st_name)) + st <- synth.tab(so, dp) + + assign(so_name, so, envir = .GlobalEnv) + assign(st_name, st, envir = .GlobalEnv) + } + + df <- + tibble( + Year = as.numeric(rownames(dp$Y1)), + Treated = dp$Y1[, 1], + Synthetic = synthC[, 1] + ) %>% + gather("Group", "Rate",-1) + + return(df) - assign(so_name, so, envir = .GlobalEnv) - assign(st_name, st, envir = .GlobalEnv) } - - df <- tibble(Year = as.numeric(rownames(dp$Y1)), Treated = dp$Y1[,1], Synthetic = synthC[,1]) %>% - gather("Group", "Rate", -1) - - return(df) - -} printCoefficients <- function(md = NULL, model = NULL){ @@ -184,16 +213,27 @@ generatePlacebos <- function(data, return(placebos) } -pre_MSPE <- function (md){ +pre_MSPE <- function (md) { md %>% - filter(Year < 1999) %>% - spread(Group, Rate) %>% - mutate(SPE = (Treated - Synthetic)**2) %>% - summarise(MSPE = mean(SPE)) %>% - pull() %>% + filter(Year < 1999) %>% + spread(Group, Rate) %>% + mutate(SPE = (Treated - Synthetic) ** 2) %>% + summarise(MSPE = mean(SPE)) %>% + pull() %>% signif(3) } +pre_corr <- function (md) { + + ps <- md %>% + filter(Year < 1999) %>% + pivot_wider(names_from = "Group", values_from = "Rate") %>% + select(-Year) + + cor(ps$Treated, ps$Synthetic) ^ 2 + +} + sPredText <- function(dp) { paste("Prediction periods:", map(dp$tag$special.predictors, pluck(2)) %>% @@ -741,15 +781,15 @@ gg_pre_postMSPE <- function(md, pl){ summarise(mspe = mean(Gap**2)) %>% spread(period, mspe) %>% mutate(ratio = post/pre, - label = ifelse(Country=="England and Wales", paste0("England and Wales; ratio = ", signif(ratio, 3)), NA), + label = ifelse(Country=="England and Wales", paste0("England and Wales\nratio = ", signif(ratio, 3)), NA), xintercept = ifelse(Country=="England and Wales", ratio, NA)) - df %>% - select(Country, ratio) %>% - arrange(ratio) %>% - ungroup() %>% - mutate(rank = row_number()) %>% - print() + # df %>% + # select(Country, ratio) %>% + # arrange(ratio) %>% + # ungroup() %>% + # mutate(rank = row_number()) %>% + # print() p <- ggplot(df, aes(ratio)) + geom_histogram(fill = sphsu_cols("Cobalt"), col = "darkgrey", bins = 60) + @@ -760,14 +800,124 @@ gg_pre_postMSPE <- function(md, pl){ ytop <- max(ggp[["data"]][[1]][["count"]]) - p <- p + geom_text(aes(x = xintercept, label = label),vjust = 0, hjust = 0, y = ytop + 0.1, inherit.aes = FALSE) + - geom_segment(aes(x = xintercept, xend = xintercept), y = 0, yend = ytop, inherit.aes = FALSE) + - ylim(0, ytop + 0.25) + p <- + p + geom_text(aes(x = xintercept, label = label), + vjust = 0, hjust = 0, y = Inf, inherit.aes = FALSE, + nudge_x = 0.05) + + geom_segment(aes(x = xintercept, xend = xintercept), + y = 0, + yend = Inf, + inherit.aes = FALSE) + + scale_y_continuous(expand = expansion(add = c(0, 0.5))) + + coord_cartesian(clip = "off") + + theme( + plot.title = element_text(margin = margin(b = 1, unit = "cm")), + plot.margin = margin(1, unit = "cm") + ) + return(p) } +gg_pre_postMSPE_tab <- function(md, pl) { + + df <- md %>% + spread(Group, Rate) %>% + mutate(Gap = Treated - Synthetic, + Country = "England and Wales") %>% + select(Year, Country, Gap) %>% + bind_rows(pl %>% select(Year, Country, Gap)) %>% + mutate(period = ifelse(Year<1999, "pre", "post")) %>% + group_by(Country, period) %>% + summarise(mspe = mean(Gap**2)) %>% + spread(period, mspe) %>% + mutate(ratio = post/pre) + + df_tidy <- df %>% + ungroup() %>% + mutate(rank = rank(-ratio), + Country = fct_reorder(factor(Country), ratio), + ratio_lab = str_pad(str_replace(as.character(round(ratio, 2)), "(\\.\\d)$", "\\10"), 6, side = "left"), + EngWa = ifelse(Country == "England and Wales", "E", "C")) %>% + arrange(rank) %>% + select(Country, ratio, ratio_lab, rank, EngWa) + + + points_plot <- ggplot(df_tidy, aes(ratio, Country, colour = EngWa)) + + geom_point(size = 3, shape = 'diamond') + + scale_x_continuous("Post/pre-MSPE ratio") + + ggtitle(" ") + + theme(axis.line.y = element_blank(), + axis.title.y = element_blank(), + axis.text.y = element_blank(), + axis.ticks.y = element_blank(), + panel.background = element_blank(), + panel.grid.major = element_line(colour = "#e0e0e0"), + panel.grid.minor = element_blank(), + axis.line = element_line(colour = "#666666"), + strip.text = element_blank(), + panel.spacing.y = unit(1, "cm"), + plot.margin = margin(l = 0, r = 0), + panel.grid.major.y = element_blank(), + plot.title = element_text(size = 12), + legend.position = "none" + ) + + scale_colour_manual(values = c("E" = sphsu_cols("University blue", names = FALSE), "C" = "darkgrey")) + + base_plot <- df_tidy %>% + ggplot(aes(x = 0, y = Country, colour = EngWa, fontface = ifelse(EngWa == "E", "bold", "plain"))) + + ylab(NULL) + + xlab(" ") + + theme( + strip.text = element_blank(), + plot.margin = margin(l = 0, r = 0), + axis.text.y = element_blank(), + axis.title.y = element_blank(), + axis.line = element_blank(), + axis.ticks = element_blank(), + axis.text.x = element_text(color = "white"), + panel.background = element_blank(), + ## need text to be printed so it stays aligned with figure but white so it's invisible + legend.position = "none", + # panel.background = element_rect(colour = "lightblue", fill = "white"), + # panel.border = element_blank(), + panel.grid.major = element_blank(), + panel.grid.minor = element_blank(), + plot.title = element_text(size = 12, hjust = 0) + ) + + coord_cartesian(clip = "off") + + scale_x_continuous(expand = expansion(add = c(0,0)), limits = c(0,2)) + + scale_colour_manual(values = c("E" = sphsu_cols("University blue", names = FALSE), "C" = "black")) + + c_plot <- base_plot + + geom_text(aes(label = Country), hjust = 0, size = pts(9)) + + ggtitle("Country") + + theme(strip.text = element_text(colour = "black"), + strip.background = element_blank(), + strip.placement = "outside" ) + + + rank_plot <- base_plot + + geom_text(aes(label = rank), hjust = 0, size = pts(9)) + + ggtitle("Rank") + + theme(strip.text = element_text(colour = "black"), + strip.background = element_blank(), + strip.placement = "outside" ) + + rat_plot <- base_plot + + geom_text(aes(x = Inf, label = ratio_lab), hjust = 1, size = pts(9)) + + ggtitle("Ratio") + + theme(strip.text = element_text(colour = "black"), + strip.background = element_blank(), + strip.placement = "outside", + plot.title = element_text(size = 12, hjust = 1)) + + grid.arrange(c_plot, rank_plot, rat_plot, points_plot, + layout_matrix = matrix(c(1,1,1,1,1,1,2, 2,3,3, 4, 4,4,4,4,4,4,4,4,4,4,4), nrow = 1)) + +} + # iterating through removal of top-weighted countries -------------------------------------------------------- gg_iterateCountries <- function(itco, jitter = FALSE, n = 10, float_labs = FALSE) { diff --git a/R/experimental dash plot.R b/R/experimental dash plot.R new file mode 100644 index 0000000..7ebbae3 --- /dev/null +++ b/R/experimental dash plot.R @@ -0,0 +1,155 @@ +# pp_u18_sp <- gg_pre_postMSPE(md_u18_sp, pl_u18_filt) + +# scale_x_log10(labels = scales::comma_format(accuracy = 1), breaks = c(0,1,10, 100, 1000)) + scale_y_continuous(breaks = c(0,1,2,3)) + theme(plot.margin = unit(c(5.5,12,5.5,5.5), "pt")) + + +library(gridExtra) + +df <- md_u18_sp %>% + spread(Group, Rate) %>% + mutate(Gap = Treated - Synthetic, + Country = "England and Wales") %>% + select(Year, Country, Gap) %>% + bind_rows(pl_u18_filt %>% select(Year, Country, Gap)) %>% + mutate(period = ifelse(Year<1999, "pre", "post")) %>% + group_by(Country, period) %>% + summarise(mspe = mean(Gap**2)) %>% + spread(period, mspe) %>% + mutate(ratio = post/pre, + label = ifelse(Country=="England and Wales", paste0("England and Wales\nratio = ", signif(ratio, 3)), NA), + xintercept = ifelse(Country=="England and Wales", ratio, NA)) + +library(scales) +reverselog_trans <- function(base = 10) { + trans <- function(x) -log(x, base) + inv <- function(x) base^(-x) + trans_new(paste0("reverselog-", format(base)), trans, inv, + log_breaks(base = base), + domain = c(1e-100, Inf)) +} + +ggplot(df, aes(0, ratio)) + + geom_segment(aes(xend = -1, yend = ratio, colour = label), + size = ifelse(is.na(df$label), 0.5, 2) + ) + + theme_minimal() + + theme(panel.grid = element_blank()) + + scale_y_continuous("Countries ranked by Pre/post MSPE ratio", trans = "log10")+ + geom_text(aes(x = 0.2, y = ratio, label = label), + vjust = 0.5, hjust = 0, inherit.aes = FALSE, + nudge_x = 0.05) + + coord_cartesian(clip = "off") + + theme( + plot.title = element_text(margin = margin(b = 1, unit = "cm")), + plot.margin = margin(0, unit = "cm"), + legend.position = "none", + axis.text.x = element_blank(), + axis.line.y = element_line(colour = "grey"), + axis.title.x = element_blank() + ) + + scale_x_continuous("", limits = c(-1, 5), expand = expansion(add = 0)) + +ggsave("test_plot_1.png", dpi = 300, height = 12, width = 6, units = "cm") + + + +# doing graph as in Abadie 2015 ------------------------------------------- + + + +df <- md_u18_sp %>% + spread(Group, Rate) %>% + mutate(Gap = Treated - Synthetic, + Country = "England and Wales") %>% + select(Year, Country, Gap) %>% + bind_rows(pl_u18_filt %>% select(Year, Country, Gap)) %>% + mutate(period = ifelse(Year<1999, "pre", "post")) %>% + group_by(Country, period) %>% + summarise(mspe = mean(Gap**2)) %>% + spread(period, mspe) %>% + mutate(ratio = post/pre) + +df_tidy <- df %>% + ungroup() %>% + mutate(rank = rank(-ratio), + Country = fct_reorder(factor(Country), ratio), + ratio_lab = str_pad(str_replace(as.character(round(ratio, 2)), "(\\.\\d)$", "\\10"), 6, side = "left"), + EngWa = ifelse(Country == "England and Wales", "E", "C")) %>% + arrange(rank) %>% + select(Country, ratio, ratio_lab, rank, EngWa) + + +points_plot <- ggplot(df_tidy, aes(ratio, Country, colour = EngWa)) + + geom_point(size = 3, shape = 'diamond') + + scale_x_continuous("Post/pre-MSPE ratio") + + ggtitle(" ") + + theme(axis.line.y = element_blank(), + axis.title.y = element_blank(), + axis.text.y = element_blank(), + axis.ticks.y = element_blank(), +panel.background = element_blank(), +panel.grid.major = element_line(colour = "#e0e0e0"), +panel.grid.minor = element_blank(), +axis.line = element_line(colour = "#666666"), + strip.text = element_blank(), + panel.spacing.y = unit(1, "cm"), + plot.margin = margin(l = 0, r = 0), + panel.grid.major.y = element_blank(), + plot.title = element_text(size = 12), + legend.position = "none" + ) + + scale_colour_manual(values = c("E" = sphsu_cols("University blue", names = FALSE), "C" = "darkgrey")) + +base_plot <- df_tidy %>% + ggplot(aes(x = 0, y = Country, colour = EngWa, fontface = ifelse(EngWa == "E", "bold", "plain"))) + + ylab(NULL) + + xlab(" ") + + theme( + strip.text = element_blank(), + plot.margin = margin(l = 0, r = 0), + axis.text.y = element_blank(), + axis.title.y = element_blank(), + axis.line = element_blank(), + axis.ticks = element_blank(), + axis.text.x = element_text(color = "white"), +panel.background = element_blank(), + ## need text to be printed so it stays aligned with figure but white so it's invisible + legend.position = "none", + # panel.background = element_rect(colour = "lightblue", fill = "white"), + # panel.border = element_blank(), + panel.grid.major = element_blank(), + panel.grid.minor = element_blank(), + plot.title = element_text(size = 12, hjust = 0) + ) + + coord_cartesian(clip = "off") + + scale_x_continuous(expand = expansion(add = c(0,0)), limits = c(0,2)) + + scale_colour_manual(values = c("E" = sphsu_cols("University blue", names = FALSE), "C" = "black")) + +c_plot <- base_plot + + geom_text(aes(label = Country), hjust = 0, size = pts(9)) + + ggtitle("Country") + + theme(strip.text = element_text(colour = "black"), + strip.background = element_blank(), + strip.placement = "outside" ) + + +rank_plot <- base_plot + + geom_text(aes(label = rank), hjust = 0, size = pts(9)) + + ggtitle("Rank") + + theme(strip.text = element_text(colour = "black"), + strip.background = element_blank(), + strip.placement = "outside" ) + +rat_plot <- base_plot + + geom_text(aes(x = Inf, label = ratio_lab), hjust = 1, size = pts(9)) + + ggtitle("Ratio") + + theme(strip.text = element_text(colour = "black"), + strip.background = element_blank(), + strip.placement = "outside", + plot.title = element_text(size = 12, hjust = 1)) + +ratio_tab_plot <- grid.arrange(c_plot, rank_plot, rat_plot, points_plot, + layout_matrix = matrix(c(1,1,1,1,1,1,2, 2,3,3, 4, 4,4,4,4,4,4,4,4,4,4,4), nrow = 1)) + +ggsave("graphs/test_ratio_plot.png", ratio_tab_plot, dpi = 400, width = 155, + height = 120, + units = "mm") diff --git a/R/further graphs for thesis chapter.R b/R/further graphs for thesis chapter.R index 2ad58c8..5b5e469 100644 --- a/R/further graphs for thesis chapter.R +++ b/R/further graphs for thesis chapter.R @@ -37,11 +37,12 @@ super_md_u18_filt %>% ylab(paste0("Under-18 birth rate (per 1,000 women)")) + theme(legend.title = element_blank(), panel.grid.major = element_line(colour = "#e0e0e0"), - panel.grid.minor = element_blank() + panel.grid.minor = element_blank(), + title = element_text(size = 12) ) + scale_linetype_manual(name = "Data", values = c("Synthetic" = "solid", "Treated" = "solid")) + scale_colour_manual(name = "Data", values = c("Synthetic" = sphsu_cols("Turquoise", names = FALSE), "Treated" = sphsu_cols("Thistle", names = FALSE))) + - labs(title = "England vs Synthetic Control, faceted by placebo year") + + labs(title = "England vs Synthetic Control with placebo intervention years") + scale_y_continuous(limits = c(0, 20)) + facet_wrap(~ IntYr) @@ -64,7 +65,7 @@ super_md_u20_filt %>% ) + scale_linetype_manual(name = "Data", values = c("Synthetic" = "solid", "Treated" = "solid")) + scale_colour_manual(name = "Data", values = c("Synthetic" = sphsu_cols("Turquoise", names = FALSE), "Treated" = sphsu_cols("Thistle", names = FALSE))) + - labs(title = "England vs Synthetic Control, faceted by placebo year") + + labs(title = "England vs Synthetic Control with placebo intervention years") + scale_y_continuous(limits = c(0, 80)) + facet_wrap(~ IntYr) @@ -109,6 +110,39 @@ u20_right[["layers"]][[3]][["aes_params"]]$size <- 1 ggsave("graphs/u20_all.png", dpi = 400, width = 155, height = 85, units = "mm") +# joint graphs for poster of primary models ------------------------------- + +u18_left <- gr_u18_sp +u18_right <- pb_plot_u18_sp + +u18_left[["layers"]][[1]][["aes_params"]]$size <- 1 +u18_right[["layers"]][[3]][["aes_params"]]$size <- 1 + + +((u18_left + u18_right) & + theme(legend.position = "bottom")) / + guide_area() + + plot_layout(guides = 'collect', + width = 155, + heights = c(80, 5), + ) + +ggsave("graphs/u18_sp.svg", dpi = 400, width = 240, height = 90, units = "mm") + +u20_left <- gr_u20_sp +u20_right <- pb_plot_u20_sp +u20_left[["layers"]][[1]][["aes_params"]]$size <- 1 +u20_right[["layers"]][[3]][["aes_params"]]$size <- 1 + +((u20_left + u20_right) & + theme(legend.position = "bottom")) / + guide_area() + + plot_layout(guides = 'collect', + width = 155, + heights = c(80, 5) + ) + +ggsave("graphs/u20_sp.svg", dpi = 400, width = 240, height = 90, units = "mm") # comparing UK to other countries ----------------------------------------- diff --git a/R/playing with linearhypothesis.R b/R/playing with linearhypothesis.R new file mode 100644 index 0000000..fe2b5d5 --- /dev/null +++ b/R/playing with linearhypothesis.R @@ -0,0 +1,105 @@ +beta <- -0.13142 +serr <- 0.0882116 +tval <- beta/serr + +2*pnorm(-abs(tval)) + +2*pt(-abs(tval), df = 41) + + + +tnew <- (-0.304-beta)/serr +2*pt(-abs(tnew), df = 42, lower.tail = TRUE) + + +library(tidyverse) +library(readxl) +library(broom) +library(nlme) +library(car) + + +# all.UK.rates - Import conception rates for GBR countries ------------------------------------------- + +all.UK.rates <- + read_xlsx("Conception rates by age and country.xlsx", sheet = "Under 18") + +load("Data/all_uk_rates.rdata") + +# Create datasets -------------------------------------------------------------------------------------------- + +#** EngData - England only ------------------------------------------------------------------------------------- + +EngData <- + all_UK_rates[['Under 18']] %>% + filter(Country == "England") %>% + mutate( + Cat1 = ifelse(Year < 1999, 0, 1), + Cat2 = ifelse(Year <= 2007, 0, 1), + Year = as.numeric(Year), + Time = 1:nrow(.), + Trend1 = ifelse(Cat1 == 0, 0, 1:nrow(.) - nrow(filter(., Cat1 == + 0))), + Trend2 = ifelse(Cat2 == 0, 0, 1:nrow(.) - nrow(filter(., Cat2 == + 0))), + PillScare = ifelse(Year > 1995, 1, 0) + ) + +#** EngScotContro data setup - Eng v Scot ----------------------------------------------- + +EngScotContro <- + all_UK_rates[['Under 18']] %>% + filter(Country %in% c("England", "Scotland")) %>% + filter(Year > 1991,!is.na(Value)) %>% + arrange(Country) %>% + mutate( + England = ifelse(Country == "England", 1, 0), + Year = as.numeric(Year), + Time = Year - min(Year) + 1, + Cat1 = ifelse(Year < 1999, 0, 1), + Cat2 = ifelse(Year <= 2007, 0, 1), + Trend1 = ifelse(Cat1 == 0, 0, Year - 1998), + Trend2 = ifelse(Cat2 == 0, 0, Year - 2007), + PillScare = ifelse(Year > 1995, 1, 0) + ) %>% + mutate_at(., colnames(.)[5:9], list(Eng = ~ .*England)) # Potentially not necessary + +#** EngWalContro data setup - Eng vs Wales as control ---------------------------------------------------------- + +EngWalContro <- + all_UK_rates[['Under 18']] %>% + filter(Country %in% c("England", "Wales")) %>% + filter(Year > 1991,!is.na(Value)) %>% + arrange(Country) %>% + mutate( + England = ifelse(Country == "England", 1, 0), + Year = as.numeric(Year), + Time = Year - min(Year) + 1, + Cat1 = ifelse(Year < 1999, 0, 1), + Cat2 = ifelse(Year <= 2007, 0, 1), + Trend1 = ifelse(Cat1 == 0, 0, Year - 1998), + Trend2 = ifelse(Cat2 == 0, 0, Year - 2007), + PillScare = ifelse(Year > 1995, 1, 0) + ) %>% + mutate_at(., colnames(.)[5:9], list(Eng = ~ .*England)) # Potentially not necessary + + +# engscot with pill scare and shock --------------------------------------- + +mod_esps <- gls( + Value ~ Time + England + Cat1 + Trend1 + Cat1_Eng + Trend1_Eng + Trend2 + PillScare, + data = EngScotContro, + correlation = corARMA( + p = 1, + q = 0, + form = ~ Time | England + ), + method = "ML" +) + +summary(mod_esps) + +linearHypothesis(mod_esps, "Trend1_Eng = -0.4", test = "Chisq") + +2*pt(-abs((beta)/serr), df = 41) +pt(abs((-0.4-beta)/serr), df = 41, lower.tail = FALSE) diff --git a/R/read_in_its_results.R b/R/read_in_its_results.R new file mode 100644 index 0000000..7efd06d --- /dev/null +++ b/R/read_in_its_results.R @@ -0,0 +1,44 @@ +library(tidyverse) + +filenames <- dir("Data/its_outputs") + +results <- map( + filenames, + ~ readxl::read_xlsx( + paste0("Data/its_outputs/", .x), + sheet = "model", + col_types = c("text", rep("numeric", 4)) + ) %>% + mutate(model = str_extract(.x, ".*(?=\\.xlsx)")) %>% + filter(str_detect(Coefficient, "England .* 1999")) %>% + mutate(Coefficient = str_extract(Coefficient, "level|trend")) %>% + nest() +) %>% + transpose() %>% + flatten_df() %>% + relocate(model) %>% + mutate(model = factor(model, levels = paste("model", 1:10))) %>% + arrange(model) %>% + mutate( + comparison = ifelse(model %in% c("model 1", "model 2", "model 5"), 0, 1), + primary = ifelse( + model %in% c("model 3", "model 4"), + "Primary comparison", + "Robustness and sensitivity" + ) + ) + +meta_analyses <- results %>% + group_by(Coefficient, comparison) %>% + group_map( ~ list( + re = metagen( + Estimate, + `Standard Error`, + comb.random = TRUE, + data = ., + prediction = FALSE, + studlab = str_to_sentence(model), + byvar = primary + ), + Coefficient = unique(pull(., Coefficient)) + ), .keep = TRUE) \ No newline at end of file diff --git a/R/testing mspe ratios on normal distribution.R b/R/testing mspe ratios on normal distribution.R new file mode 100644 index 0000000..f5f55c5 --- /dev/null +++ b/R/testing mspe ratios on normal distribution.R @@ -0,0 +1,53 @@ +library(tidyverse) + +log_rank <- rank_u18 %>% + mutate(log_ratio = log(`Post/pre MSPE ratio`)) %>% + select(Country, log_ratio) + + +dist_params <- log_rank %>% + filter(Country != "England and Wales") %>% + summarise(mean = mean(log_ratio), + sd = sd(log_ratio)) + +Eng_ratio <- log_rank %>% + filter(Country == "England and Wales") %>% + pull(log_ratio) + +ggplot(tibble(x = -3:7), aes(x)) + + stat_function(fun = dnorm, n = 100, args = list(dist_params$mean, dist_params$sd)) + + geom_density(aes(log_ratio), log_rank, colour = "red") + + geom_vline(xintercept = Eng_ratio, colour = "blue") + + +pnorm(Eng_ratio, dist_params$mean, dist_params$sd, lower.tail = FALSE) + +qnorm(0.05, dist_params$mean, dist_params$sd, lower.tail = FALSE) + + +## Under20 --------------------------------------------------------------- + + +log_rank <- rank_u20 %>% + mutate(log_ratio = log(`Post/pre MSPE ratio`)) %>% + select(Country, log_ratio) + + +dist_params <- log_rank %>% + filter(Country != "England and Wales") %>% + summarise(mean = mean(log_ratio), + sd = sd(log_ratio)) + +Eng_ratio <- log_rank %>% + filter(Country == "England and Wales") %>% + pull(log_ratio) + +ggplot(tibble(x = -3:7), aes(x)) + + stat_function(fun = dnorm, n = 100, args = list(dist_params$mean, dist_params$sd)) + + geom_density(aes(log_ratio), log_rank, colour = "red") + + geom_vline(xintercept = Eng_ratio, colour = "blue") + + +pnorm(Eng_ratio, dist_params$mean, dist_params$sd, lower.tail = FALSE) + +qnorm(0.05, dist_params$mean, dist_params$sd, lower.tail = FALSE) diff --git a/Synth-report-updated.Rmd b/Synth-report-updated.Rmd index dc20318..991589a 100644 --- a/Synth-report-updated.Rmd +++ b/Synth-report-updated.Rmd @@ -3,22 +3,18 @@ title: "Synth reporting" author: "Andrew Baxter" date: "`r Sys.Date()`" output: - # pdf_document: - # fig_height: 5 - # fig_width: 8 - # toc: true - # toc_depth: 2 - # number_sections: true html_document: toc: true toc_depth: 2 number_sections: true + df_print: !expr DT::datatable toc_float: collapsed: false # word_document: # fig_height: 4.7 # fig_width: 6.1 # reference_docx: C:\Users\2286432b\OneDrive - University of Glasgow\Teenage pregnancy - docs in development\ITS and Synth paper files\BMJ Submission documents\Supplementary File.docx + # pdf_document: always_allow_html: yes params: save_graphs: @@ -47,6 +43,9 @@ knitr::opts_chunk$set( warning = FALSE, out.width = "100%" ) + +options(DT.options = list(rownames = FALSE)) + library(readxl) library(tidyverse) library(stringr) @@ -61,6 +60,7 @@ library(plotly) library(knitr) library(gganimate) library(ggrepel) +library(gridExtra) library(patchwork) load('Data/synth_data_c.rdata') # outputted from 'Synth_data.R' @@ -71,6 +71,9 @@ load("Data/time_placebos_b.rdata") # outputted from 'Synth_time_pbs.R' # load('Data/noScot.rdata') load("Data/other_predictors.rdata") source('R/Synth_functions.R') + +synthData_u20_filt[synthData_u20_filt$Country=="New Zealand","rate"] <- + synthData_u18_filt[synthData_u18_filt$Country=="New Zealand","rate"] ``` ```{r results='asis'} cat(" @@ -87,18 +90,29 @@ caption { # Setting up data +## Under-18 birth rates + Data from Human Mortality Database and Human Fertility Database was used to calculate birth rates. This was tidied to give Under-18 rates: ```{r tidy_u18} -kable(head(synthData_u18_filt %>% mutate_if(is.numeric, ~ round(.,2)))) +DT::datatable(synthData_u18_filt %>% mutate_if(is.numeric, ~ round(.,2)), rownames = FALSE) ``` +Data available to [download here](http://phd.andybaxter.me/data/under-18-birth-rates.csv). + + + +## Under-20 pregnancy rates Abortion estimates were added to give Under-20 rates: ```{r tidy_u_19} -kable(head(synthData_u20_filt %>% mutate_if(is.numeric, ~ round(.,2)))) +DT::datatable(synthData_u20_filt %>% mutate_if(is.numeric, ~ round(.,2)), rownames = FALSE) ``` +Data available to [download here](http://phd.andybaxter.me/data/under-20-pregnancy-rates.csv). + + + # Iterating through year combinations For each comparison, I iterated through all combinations of years as special predictors to minimise MSPE (whilst prioritising fewest groupings). For example, for the under-18 basic model with years as special predictors: @@ -107,7 +121,7 @@ For each comparison, I iterated through all combinations of years as special pre it_u18_sp <- testSynthIterations( yrs = 1990:1998, pred = "rate", - data = synthData_u18[,1:4], + data = synthData_u18_filt[,1:4], ccodes = u_18_ccodes, n = 4, predictors = NULL, @@ -184,16 +198,20 @@ synthPrep(synthData_u18_filt, time.predictors.prior = opt_y1:1998, time.plot = opt_y1:2013 ) + +md_curr <- md_u18_sp + ``` Over the period 1999 to 2013, England and Wales saw a difference of `r rateDiff(md_u18_sp, "under 18")$tot_diff` births (to an average population of `r rateDiff(md_u18_sp, "under 18")$mean_pop` women). ```{r md_u18_sp_graph} -gr_u18_sp <- gg_synth(md = md_u18_sp, post = TRUE) +gr_u18_sp <- gg_synth(md = md_u18_sp, post = TRUE, linesize = 1) gr_u18_sp #+ labs(title = sPredText(dp_u18_sp)) + if (params$save_graphs){ ggsave("graphs/Synth-u18-sp.png", @@ -207,6 +225,14 @@ if (params$save_graphs){ ``` +```{r include=FALSE} +mspe_curr <- pre_MSPE(md_curr) +# ave_pop_curr <- +rsq_curr <- pre_corr(md_curr) +``` + +The MSPE across the pre-intervention period was `r mspe_curr`, (an average error of `r signif(sqrt(mspe_curr), 3)`) and the synthetic predictor was able to account for `r round(rsq_curr, 3)*100`% of the variance (R^2^ = `r round(rsq_curr, 3)`). + ### Weights and balance ```{r st_u18_sp_w} @@ -253,32 +279,34 @@ if (params$plotly_graphs == "plotly" & params$publish_plotly) { View this [live online](https://chart-studio.plotly.com/~andrewbaxter439/43). ```{r rank_u18} -pp_u18_sp <- gg_pre_postMSPE(md_u18_sp, pl_u18_filt) + labs(title = "Post/pre-TPS mean squared prediction error") +pp_u18_sp <- gg_pre_postMSPE(md_u18_sp, pl_u18_filt) + + scale_x_log10(labels = scales::comma_format(accuracy = 1), breaks = c(0,1,10, 100, 1000)) + scale_y_continuous(breaks = c(0,1,2,3)) + theme(plot.margin = unit(c(5.5,12,5.5,5.5), "pt")) p18 <- ggplot_build(pp_u18_sp) rank_u18 <- p18$plot$data %>% - arrange(desc(ratio)) %>% ungroup() %>% - mutate(rank = rank(-ratio)) %>% - select(Country, ratio, rank) + mutate(Rank = rank(-ratio), + `Post/pre MSPE ratio` = round(ratio, 2)) %>% + arrange(Rank) %>% + select(Country, `Post/pre MSPE ratio`, Rank) + +kable(rank_u18) ``` -In placebo-country tests, England and Wales ranked `r rank_u18 %>% filter(Country == "England and Wales") %>% pull(rank)` out of `r nrow(rank_u18)` countries by pre/post-MSPE ratio. +In placebo-country tests, England and Wales ranked `r rank_u18 %>% filter(Country == "England and Wales") %>% pull(Rank)` out of `r nrow(rank_u18)` countries by pre/post-MSPE ratio. ```{r pp_u18_sp} -pp_u18_sp +# + labs(title = "Post/pre-TPS mean squared prediction error") +pp_u18_sp <- gg_pre_postMSPE_tab(md_u18_sp, pl_u18_filt) ``` ```{r save_u18_pb_nat, include=FALSE} if (params$save_graphs){ggsave( - plot = pp_u18_sp + - theme(title = element_text(size = 14), - axis.title = element_text(size = 12), - legend.position = "none"), - dpi = 400, "graphs/Synth-u18-sp-pp-ratio.png", width = 155, height = 100, units = "mm" + plot = pp_u18_sp, + dpi = 400, "graphs/Synth-u18-sp-pp-ratio.png", width = 155, height = 120, units = "mm" )} if (params$save_graphs){ggsave( plot = pb_plot_u18_sp + @@ -377,19 +405,22 @@ gr_u20_rates ### England vs Synthetic Control ```{r u20_sp, include = FALSE} opt_y1 <- 1990 -synthData_u20_filt[synthData_u20_filt$Country=="New Zealand","rate"] <- - synthData_u18_filt[synthData_u18_filt$Country=="New Zealand","rate"] + # dataprep and synth synthPrep(synthData_u20_filt[,1:5], "u20_sp", dependent = "pRate", + # predictors = "pRate", special.predictors = sp_u20_filt, # special.predictors = append(sp_u20_filt, sp_u18_filt), time.optimise.ssr = opt_y1:1998, time.predictors.prior = opt_y1:1998, time.plot = opt_y1:2013 ) + +md_curr <- md_u20_sp + ``` Over the period 1999 to 2013, England and Wales saw a difference of `r rateDiff(md_u20_sp, "under 20")$tot_diff` pregnancies (to an average population of `r rateDiff(md_u20_sp, "under 20")$mean_pop` women). @@ -405,6 +436,14 @@ if (params$save_graphs){ggsave(plot = gr_u20_sp, "graphs/Synth-u20-sp.png", widt ``` +```{r include=FALSE} +mspe_curr <- pre_MSPE(md_curr) +# ave_pop_curr <- +rsq_curr <- pre_corr(md_curr) +``` + +The MSPE across the pre-intervention period was `r mspe_curr`, (an average error of `r signif(sqrt(mspe_curr), 3)`) and the synthetic predictor was able to account for `r round(rsq_curr, 3)*100`% of the variance (R^2^ = `r round(rsq_curr, 3)`). + ### Weights and balance ```{r st_u20_sp_w} # weights kable @@ -446,28 +485,32 @@ if (params$plotly_graphs == "plotly" & params$publish_plotly) { View this [live online](https://chart-studio.plotly.com/~andrewbaxter439/49). -```{r rank_u20, include=FALSE} -pp_u20_sp <- gg_pre_postMSPE(md_u20_sp, pl_u20_filt) + labs(title = "Post/pre-TPS mean squared prediction error") +```{r rank_u20} +pp_u20_sp <- gg_pre_postMSPE(md_u20_sp, pl_u20_filt) + + scale_x_log10(labels = scales::comma_format(accuracy = 1), breaks = c(0,1,10, 100, 1000)) + scale_y_continuous(breaks = c(0,1,2,3)) + theme(plot.margin = unit(c(5.5,12,5.5,5.5), "pt")) p20 <- ggplot_build(pp_u20_sp) rank_u20 <- p20$plot$data %>% - arrange(desc(ratio)) %>% ungroup() %>% - mutate(rank = rank(-ratio)) %>% - select(Country, ratio, rank) + mutate(Rank = rank(-ratio), + `Post/pre MSPE ratio` = round(ratio, 2)) %>% + arrange(Rank) %>% + select(Country, `Post/pre MSPE ratio`, Rank) + +kable(rank_u20) ``` -In placebo-country tests, England and Wales ranked `r rank_u20 %>% filter(Country == "England and Wales") %>% pull(rank)` out of `r nrow(rank_u20)` countries by pre/post-MSPE ratio. +In placebo-country tests, England and Wales ranked `r rank_u20 %>% filter(Country == "England and Wales") %>% pull(Rank)` out of `r nrow(rank_u20)` countries by pre/post-MSPE ratio. ```{r pp_u20_sp} -pp_u20_sp +pp_u20_sp <- gg_pre_postMSPE_tab(md_u20_sp, pl_u20_filt) ``` ```{r save_u20_sp_pb_nat, include=FALSE} -if (params$save_graphs){ggsave(plot = pp_u20_sp, "graphs/Synth-u20-sp-pp-ratio.png", width = 155, height = 100, units = "mm")} +if (params$save_graphs){ggsave(plot = pp_u20_sp, "graphs/Synth-u20-sp-pp-ratio.png", width = 155, height = 120, units = "mm")} if (params$save_graphs){ggsave(plot = pb_plot_u20_sp, "graphs/Synth-u20-sp-gaps.png", width = 155, height = 100, units = "mm")} ``` @@ -526,6 +569,8 @@ synthPrep(sd_noScot, time.predictors.prior = 1990:1998, time.plot = 1990:2013 ) + +md_curr <- md_u18_ns ``` Over the period 1999 to 2013, England and Wales saw a difference of `r rateDiff(md_u18_ns, "under 18")$tot_diff` births (to an average population of `r rateDiff(md_u18_ns, "under 18")$mean_pop` women). @@ -540,7 +585,13 @@ if (params$save_graphs){ggsave("graphs/Synth-u18-ns.png", gr_u18_ns, width = 155 ``` -Loss-V (For optimised period) = `r signif(so_u18_ns$loss.v[[1]], 3)`, MSPE (for whole pre-intervention observation period) = `r pre_MSPE(md_u18_ns)`. +```{r include=FALSE} +mspe_curr <- pre_MSPE(md_curr) +# ave_pop_curr <- +rsq_curr <- pre_corr(md_curr) +``` + +The MSPE across the pre-intervention period was `r mspe_curr`, (an average error of `r signif(sqrt(mspe_curr), 3)`) and the synthetic predictor was able to account for `r round(rsq_curr, 3)*100`% of the variance (R^2^ = `r round(rsq_curr, 3)`). ### Weights and balance @@ -587,27 +638,31 @@ if (params$plotly_graphs == "plotly" & params$publish_plotly) { View this [live online](https://chart-studio.plotly.com/~andrewbaxter439/61). ```{r rank_u18_ns} -pp_u18_ns <- gg_pre_postMSPE(md_u18_ns, pl_u18_filt) + labs(title = "Post/pre-TPS mean squared prediction error") +pp_u18_ns <- gg_pre_postMSPE(md_u18_ns, pl_u18_ns)+ + scale_x_log10(labels = scales::comma_format(accuracy = 1), breaks = c(0,1,10, 100, 1000)) + scale_y_continuous(breaks = c(0,1,2,3)) + theme(plot.margin = unit(c(5.5,12,5.5,5.5), "pt")) p18 <- ggplot_build(pp_u18_ns) rank_u18 <- p18$plot$data %>% - arrange(desc(ratio)) %>% ungroup() %>% - mutate(rank = rank(-ratio)) %>% - select(Country, ratio, rank) + mutate(Rank = rank(-ratio), + `Post/pre MSPE ratio` = round(ratio, 2)) %>% + arrange(Rank) %>% + select(Country, `Post/pre MSPE ratio`, Rank) + +kable(rank_u18) ``` -In placebo-country tests, England and Wales ranked `r rank_u18 %>% filter(Country == "England and Wales") %>% pull(rank)` out of `r nrow(rank_u18)` countries by pre/post-MSPE ratio. +In placebo-country tests, England and Wales ranked `r rank_u18 %>% filter(Country == "England and Wales") %>% pull(Rank)` out of `r nrow(rank_u18)` countries by pre/post-MSPE ratio. ```{r pp_u18_ns} -pp_u18_ns +pp_u18_ns <- gg_pre_postMSPE_tab(md_u18_ns, pl_u18_ns) ``` ```{r save_u18_pb_nat_ns, include=FALSE} -if (params$save_graphs){ggsave(plot = pp_u18_ns, "graphs/Synth-u18-ns-pp-ratio.png", width = 155, height = 100, units = "mm")} +if (params$save_graphs){ggsave(plot = pp_u18_ns, "graphs/Synth-u18-ns-pp-ratio.png", width = 155, height = 120, units = "mm")} if (params$save_graphs){ggsave(plot = pb_plot_u18_ns, "graphs/Synth-u18-ns-gaps.png", width = 155, height = 100, units = "mm")} ``` @@ -663,6 +718,9 @@ synthPrep(sd_noScot, time.predictors.prior = 1990:1998, time.plot = 1990:2013 ) + +md_curr <- md_u20_ns + ``` Over the period 1999 to 2013, England and Wales saw a difference of `r rateDiff(md_u20_ns, "under 20")$tot_diff` pregnancies (to an average population of `r rateDiff(md_u20_ns, "under 20")$mean_pop` women). @@ -676,7 +734,13 @@ gr_u20_ns# + labs(title = sPredText(dp_u20_ns)) if (params$save_graphs){ggsave("graphs/Synth-u20-ns.png", gr_u20_ns, width = 155, height = 100, units = "mm")} ``` -Loss-V (For optimised period) = `r signif(so_u20_ns$loss.v[[1]], 3)`, MSPE (for whole pre-intervention observation period) = `r pre_MSPE(md_u20_ns)`. +```{r include=FALSE} +mspe_curr <- pre_MSPE(md_curr) +# ave_pop_curr <- +rsq_curr <- pre_corr(md_curr) +``` + +The MSPE across the pre-intervention period was `r mspe_curr`, (an average error of `r signif(sqrt(mspe_curr), 3)`) and the synthetic predictor was able to account for `r round(rsq_curr, 3)*100`% of the variance (R^2^ = `r round(rsq_curr, 3)`). ### Weights and balance ```{r st_u20_ns_w} @@ -720,26 +784,30 @@ if (params$plotly_graphs == "plotly" & params$publish_plotly) { View this [live online](https://chart-studio.plotly.com/~andrewbaxter439/102). ```{r rank_u20_ns} -pp_u20_ns <- gg_pre_postMSPE(md_u20_ns, pl_u20_ns) + labs(title = "Post/pre-TPS mean squared prediction error") +pp_u20_ns <- gg_pre_postMSPE(md_u20_ns, pl_u20_ns) + + scale_x_log10(labels = scales::comma_format(accuracy = 1), breaks = c(0,1,10, 100, 1000)) + scale_y_continuous(breaks = c(0,1,2,3)) + theme(plot.margin = unit(c(5.5,12,5.5,5.5), "pt")) p20 <- ggplot_build(pp_u20_ns) rank_u20 <- p20$plot$data %>% - arrange(desc(ratio)) %>% ungroup() %>% - mutate(rank = rank(-ratio)) %>% - select(Country, ratio, rank) + mutate(Rank = rank(-ratio), + `Post/pre MSPE ratio` = round(ratio, 2)) %>% + arrange(Rank) %>% + select(Country, `Post/pre MSPE ratio`, Rank) + +kable(rank_u20) ``` -In placebo-country tests, England and Wales ranked `r rank_u20 %>% filter(Country == "England and Wales") %>% pull(rank)` out of `r nrow(rank_u20)` countries by pre/post-MSPE ratio. +In placebo-country tests, England and Wales ranked `r rank_u20 %>% filter(Country == "England and Wales") %>% pull(Rank)` out of `r nrow(rank_u20)` countries by pre/post-MSPE ratio. ```{r pp_u20_ns} -pp_u20_ns +pp_u20_ns <- gg_pre_postMSPE_tab(md_u20_ns, pl_u20_ns) ``` ```{r save_u20_ns_pb_nat, include=FALSE} -if (params$save_graphs){ggsave(plot = pp_u20_ns, "graphs/Synth-u20-ns-pp-ratio.png", width = 155, height = 100, units = "mm")} +if (params$save_graphs){ggsave(plot = pp_u20_ns, "graphs/Synth-u20-ns-pp-ratio.png", width = 155, height = 120, units = "mm")} if (params$save_graphs){ggsave(plot = pb_plot_u20_ns, "graphs/Synth-u20-ns-gaps.png", width = 155, height = 100, units = "mm")} ``` @@ -805,6 +873,8 @@ synthPrep(sd_noScot %>% filter(Country != "New Zealand"), time.predictors.prior = 1990:1998 ) +md_curr <- md_u18_all + ``` ```{r md_u18_all_graph} @@ -818,7 +888,13 @@ gr_u18_all #+ labs(title = sPredText(dp_u18_all)) # ggsave("graphs/Synth-u18-all-1990.png", width = 200, height = 150, units = "mm") ``` -Loss-V (For optimised period) = `r signif(so_u18_all$loss.v[[1]], 3)`, MSPE (for whole pre-intervention observation period) = `r pre_MSPE(md_u18_all)`. +```{r include=FALSE} +mspe_curr <- pre_MSPE(md_curr) +# ave_pop_curr <- +rsq_curr <- pre_corr(md_curr) +``` + +The MSPE across the pre-intervention period was `r mspe_curr`, (an average error of `r signif(sqrt(mspe_curr), 3)`) and the synthetic predictor was able to account for `r round(rsq_curr, 3)*100`% of the variance (R^2^ = `r round(rsq_curr, 3)`). ### Weights and balance ```{r st_u18_all_w} @@ -856,22 +932,26 @@ if (params$plotly_graphs == "plotly" & params$publish_plotly) { View this [live online](https://chart-studio.plotly.com/~andrewbaxter439/106). ```{r rank_u18_all} -pp_u18_all <- gg_pre_postMSPE(md_u18_all, pl_u18_all) + labs(title = "Post/pre-TPS mean squared prediction error") +pp_u18_all <- gg_pre_postMSPE(md_u18_all, pl_u18_all) + + scale_x_log10(labels = scales::comma_format(accuracy = 1), breaks = c(0,1,10, 100, 1000)) + scale_y_continuous(breaks = c(0,1,2,3)) + theme(plot.margin = unit(c(5.5,12,5.5,5.5), "pt")) p18 <- ggplot_build(pp_u18_all) rank_u18 <- p18$plot$data %>% - arrange(desc(ratio)) %>% ungroup() %>% - mutate(rank = rank(-ratio)) %>% - select(Country, ratio, rank) + mutate(Rank = rank(-ratio), + `Post/pre MSPE ratio` = round(ratio, 2)) %>% + arrange(Rank) %>% + select(Country, `Post/pre MSPE ratio`, Rank) + +kable(rank_u18) ``` -In placebo-country tests, England and Wales ranked `r rank_u18 %>% filter(Country == "England and Wales") %>% pull(rank)` out of `r nrow(rank_u18)` countries by pre/post-MSPE ratio. +In placebo-country tests, England and Wales ranked `r rank_u18 %>% filter(Country == "England and Wales") %>% pull(Rank)` out of `r nrow(rank_u18)` countries by pre/post-MSPE ratio. ```{r pp_u18_all} -pp_u18_all +pp_u18_all <- gg_pre_postMSPE_tab(md_u18_all, pl_u18_all) ``` @@ -895,6 +975,8 @@ synthPrep(sd_noScot %>% filter(Country != "New Zealand"), time.predictors.prior = 1990:1998 ) +md_curr <- md_u20_all + ``` ```{r md_u20_all_graph} @@ -903,7 +985,13 @@ gr_u20_all <- gg_synth(md = md_u20_all, post = TRUE) + xlim(1990, 2013) gr_u20_all ``` -Loss-V (For optimised period) = `r signif(so_u20_all$loss.v[[1]], 3)`, MSPE (for whole pre-intervention observation period) = `r pre_MSPE(md_u20_all)`. +```{r include=FALSE} +mspe_curr <- pre_MSPE(md_curr) +# ave_pop_curr <- +rsq_curr <- pre_corr(md_curr) +``` + +The MSPE across the pre-intervention period was `r mspe_curr`, (an average error of `r signif(sqrt(mspe_curr), 3)`) and the synthetic predictor was able to account for `r round(rsq_curr, 3)*100`% of the variance (R^2^ = `r round(rsq_curr, 3)`). ### Weights and balance ```{r st_u20_all_w} @@ -940,22 +1028,26 @@ if (params$plotly_graphs == "plotly" & params$publish_plotly) { View this [live online](https://chart-studio.plotly.com/~andrewbaxter439/100). ```{r rank_u20_all} -pp_u20_all <- gg_pre_postMSPE(md_u20_all, pl_u20_all) + labs(title = "Post/pre-TPS mean squared prediction error") +pp_u20_all <- gg_pre_postMSPE(md_u20_all, pl_u20_all) + + scale_x_log10(labels = scales::comma_format(accuracy = 1), breaks = c(0,1,10, 100, 1000)) + scale_y_continuous(breaks = c(0,1,2,3)) + theme(plot.margin = unit(c(5.5,12,5.5,5.5), "pt")) p20 <- ggplot_build(pp_u20_all) rank_u20 <- p20$plot$data %>% - arrange(desc(ratio)) %>% ungroup() %>% - mutate(rank = rank(-ratio)) %>% - select(Country, ratio, rank) + mutate(Rank = rank(-ratio), + `Post/pre MSPE ratio` = round(ratio, 2)) %>% + arrange(Rank) %>% + select(Country, `Post/pre MSPE ratio`, Rank) + +kable(rank_u20) ``` -In placebo-country tests, England and Wales ranked `r rank_u20 %>% filter(Country == "England and Wales") %>% pull(rank)` out of `r nrow(rank_u20)` countries by pre/post-MSPE ratio. +In placebo-country tests, England and Wales ranked `r rank_u20 %>% filter(Country == "England and Wales") %>% pull(Rank)` out of `r nrow(rank_u20)` countries by pre/post-MSPE ratio. ```{r pp_u20_all} -pp_u20_all +pp_u20_all <- gg_pre_postMSPE_tab(md_u20_all, pl_u20_all) ``` diff --git a/Synth-report-updated.html b/Synth-report-updated.html index 66d67fd..751746d 100644 --- a/Synth-report-updated.html +++ b/Synth-report-updated.html @@ -11,7 +11,7 @@ - + Synth reporting @@ -22,17 +22,33 @@ + - + - - + + + + + + + + + @@ -46,11 +62,6 @@ - +

Data available to download here.

+ + +
+

1.2 Under-20 pregnancy rates

Abortion estimates were added to give Under-20 rates:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CodeCountryYearpRaterateGDPperCapMF_ratioMobilePhonesUrbanPop
4Denmark199026.519.2026891.441.052.8884.84
4Denmark199125.339.0027011.391.043.4184.87
4Denmark199225.439.7029569.651.044.0884.90
4Denmark199324.819.1427597.971.056.8984.92
4Denmark199424.079.2129995.571.059.6684.95
4Denmark199523.088.7235351.381.0515.7184.98
+
+ +

Data available to download here.

+ +

2 Iterating through year combinations

@@ -462,7 +304,7 @@

2 Iterating through ye
it_u18_sp <- testSynthIterations(
   yrs = 1990:1998,
   pred = "rate",
-  data = synthData_u18[,1:4],
+  data = synthData_u18_filt[,1:4],
   ccodes = u_18_ccodes,
   n = 4,
   predictors = NULL,
@@ -476,12 +318,13 @@ 

3 All countries, no ad

3.1 Model 1: Under-18 birth rates

3.1.1 All Countries graph

-

+

3.1.2 England vs Synthetic Control

Over the period 1999 to 2013, England and Wales saw a difference of -3,744 births (to an average population of 995,340 women).

-

+

+

The MSPE across the pre-intervention period was 0.0923, (an average error of 0.304) and the synthetic predictor was able to account for 77.2% of the variance (R2 = 0.772).

3.1.3 Weights and balance

@@ -640,32 +483,104 @@

3.1.3 Weights and

3.1.4 Placebo testing by country and time

## Countries removed: Switzerland, Scotland, Iceland, United States of America, New Zealand
-
- +
+

View this live online.

-
## # A tibble: 16 x 3
-##    Country                    ratio  rank
-##    <chr>                      <dbl> <int>
-##  1 Switzerland                0.888     1
-##  2 Scotland                   1.39      2
-##  3 England and Wales          1.86      3
-##  4 United States of America   2.97      4
-##  5 Italy                      3.96      5
-##  6 Germany                    6.02      6
-##  7 Finland                    6.54      7
-##  8 Sweden                     8.46      8
-##  9 Denmark                    9.01      9
-## 10 Iceland                    9.73     10
-## 11 Netherlands               12.7      11
-## 12 New Zealand               17.7      12
-## 13 Portugal                  21.5      13
-## 14 Norway                    49.9      14
-## 15 Spain                    118.       15
-## 16 France                   458.       16
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CountryPost/pre MSPE ratioRank
France457.711
Spain117.612
Norway49.903
Portugal21.484
New Zealand17.735
Netherlands12.746
Iceland9.737
Denmark9.018
Sweden8.469
Finland6.5410
Germany6.0211
Italy3.9612
United States of America2.9713
England and Wales1.8614
Scotland1.3915
Switzerland0.8916

In placebo-country tests, England and Wales ranked 14 out of 16 countries by pre/post-MSPE ratio.

-

-
- +

+
+

View this live online.

@@ -678,7 +593,8 @@

3.2.1 All Countrie

3.2.2 England vs Synthetic Control

Over the period 1999 to 2013, England and Wales saw a difference of 152,471 pregnancies (to an average population of 1,668,190 women).

-

+

+

The MSPE across the pre-intervention period was 4.27, (an average error of 2.07) and the synthetic predictor was able to account for 52.1% of the variance (R2 = 0.521).

3.2.3 Weights and balance

@@ -827,13 +743,104 @@

3.2.3 Weights and

3.2.4 Placebo testing by country and time

## Countries removed: United States of America
-
- +
+

View this live online.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CountryPost/pre MSPE ratioRank
Spain654.631
France132.592
Germany93.573
Portugal87.294
Sweden62.025
Netherlands34.466
Italy26.307
Switzerland20.148
Finland10.409
Norway10.1410
England and Wales9.1011
Iceland6.2112
Denmark5.2913
New Zealand3.0514
Scotland1.5915
United States of America0.0616

In placebo-country tests, England and Wales ranked 11 out of 16 countries by pre/post-MSPE ratio.

-

-
- +

+
+

View this live online.

@@ -845,8 +852,8 @@

4.1 Model 3: Under-1

4.1.1 England vs Synthetic Control

Over the period 1999 to 2013, England and Wales saw a difference of -17,765 births (to an average population of 995,340 women).

-

-

Loss-V (For optimised period) = 0.616, MSPE (for whole pre-intervention observation period) = 0.616.

+

+

The MSPE across the pre-intervention period was 0.616, (an average error of 0.785) and the synthetic predictor was able to account for 1% of the variance (R2 = 0.01).

4.1.2 Weights and balance

@@ -1000,32 +1007,99 @@

4.1.2 Weights and

4.1.3 Placebo testing by country and time

## Countries removed: New Zealand, United States of America
-
- +
+

View this live online.

-
## # A tibble: 16 x 3
-##    Country                    ratio  rank
-##    <chr>                      <dbl> <int>
-##  1 Switzerland                0.888     1
-##  2 Scotland                   1.39      2
-##  3 England and Wales          2.92      3
-##  4 United States of America   2.97      4
-##  5 Italy                      3.96      5
-##  6 Germany                    6.02      6
-##  7 Finland                    6.54      7
-##  8 Sweden                     8.46      8
-##  9 Denmark                    9.01      9
-## 10 Iceland                    9.73     10
-## 11 Netherlands               12.7      11
-## 12 New Zealand               17.7      12
-## 13 Portugal                  21.5      13
-## 14 Norway                    49.9      14
-## 15 Spain                    118.       15
-## 16 France                   458.       16
-

In placebo-country tests, England and Wales ranked 14 out of 16 countries by pre/post-MSPE ratio.

-

-
- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CountryPost/pre MSPE ratioRank
France276.841
Spain156.462
Norway110.773
New Zealand15.374
Netherlands12.635
Iceland11.936
Portugal9.987
Denmark8.388
Sweden8.379
Finland6.5010
Italy3.9511
Germany3.2312
United States of America2.9713
England and Wales2.9214
Switzerland0.8915
+

In placebo-country tests, England and Wales ranked 14 out of 15 countries by pre/post-MSPE ratio.

+

+
+

View this live online.

@@ -1034,8 +1108,8 @@

4.2 Model 4: Under-2

4.2.1 England vs Synthetic Control

Over the period 1999 to 2013, England and Wales saw a difference of 250,707 pregnancies (to an average population of 1,668,190 women).

-

-

Loss-V (For optimised period) = 6.03, MSPE (for whole pre-intervention observation period) = 6.03.

+

+

The MSPE across the pre-intervention period was 6.03, (an average error of 2.46) and the synthetic predictor was able to account for 34.7% of the variance (R2 = 0.347).

4.2.2 Weights and balance

@@ -1179,29 +1253,97 @@

4.2.2 Weights and

4.2.3 Placebo testing by country and time

## Countries removed: United States of America
-
- +
+

View this live online.

-
## # A tibble: 15 x 3
-##    Country                     ratio  rank
-##    <chr>                       <dbl> <int>
-##  1 United States of America   0.0710     1
-##  2 Iceland                    5.28       2
-##  3 Norway                     5.94       3
-##  4 Denmark                    6.39       4
-##  5 Finland                   10.3        5
-##  6 New Zealand               12.2        6
-##  7 England and Wales         17.4        7
-##  8 Italy                     33.6        8
-##  9 Netherlands               34.5        9
-## 10 Switzerland               35.1       10
-## 11 Sweden                    61.9       11
-## 12 Portugal                  78.8       12
-## 13 Germany                   93.6       13
-## 14 France                   155.        14
-## 15 Spain                    659.        15
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CountryPost/pre MSPE ratioRank
Spain659.221
France155.232
Germany93.583
Portugal78.804
Sweden61.935
Switzerland35.096
Netherlands34.477
Italy33.648
England and Wales17.399
New Zealand12.2310
Finland10.3111
Denmark6.3912
Norway5.9413
Iceland5.2814
United States of America0.0715

In placebo-country tests, England and Wales ranked 9 out of 15 countries by pre/post-MSPE ratio.

-

+

View this live online.

@@ -1212,8 +1354,8 @@

5 Adding all predictor

5.1 Model 5: Under-18 birth rates

5.1.1 England vs Synthetic Control

-

-

Loss-V (For optimised period) = 1.49, MSPE (for whole pre-intervention observation period) = 1.49.

+

+

The MSPE across the pre-intervention period was 1.49, (an average error of 1.22) and the synthetic predictor was able to account for 5.3% of the variance (R2 = 0.053).

5.1.2 Weights and balance

@@ -1542,36 +1684,100 @@

5.1.2 Weights and

5.1.3 Placebo testing by country

## Countries removed: United States of America
-
- +
+

View this live online.

-
## # A tibble: 14 x 3
-##    Country                   ratio  rank
-##    <chr>                     <dbl> <int>
-##  1 United States of America  0.208     1
-##  2 Switzerland               0.590     2
-##  3 England and Wales         1.56      3
-##  4 Denmark                   1.96      4
-##  5 Italy                     2.18      5
-##  6 Sweden                    2.36      6
-##  7 Norway                    2.69      7
-##  8 Iceland                   3.17      8
-##  9 Finland                   3.41      9
-## 10 Netherlands               3.56     10
-## 11 Portugal                 10.9      11
-## 12 France                   10.9      12
-## 13 Spain                    42.1      13
-## 14 Germany                  55.4      14
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CountryPost/pre MSPE ratioRank
Germany55.451
Spain42.142
France10.933
Portugal10.864
Netherlands3.565
Finland3.416
Iceland3.177
Norway2.698
Sweden2.369
Italy2.1810
Denmark1.9611
England and Wales1.5612
Switzerland0.5913
United States of America0.2114

In placebo-country tests, England and Wales ranked 12 out of 14 countries by pre/post-MSPE ratio.

-

+

5.2 Model 6: Under-20 pregnancy rates

5.2.1 England vs Synthetic Control

-

-

Loss-V (For optimised period) = 11.6, MSPE (for whole pre-intervention observation period) = 11.6.

+

+

The MSPE across the pre-intervention period was 11.6, (an average error of 3.41) and the synthetic predictor was able to account for 22.8% of the variance (R2 = 0.228).

5.2.2 Weights and balance

@@ -1900,28 +2106,92 @@

5.2.2 Weights and

5.2.3 Placebo testing by country

## Countries removed: United States of America
-
- +
+

View this live online.

-
## # A tibble: 14 x 3
-##    Country                   ratio  rank
-##    <chr>                     <dbl> <int>
-##  1 United States of America  0.275     1
-##  2 Iceland                   0.959     2
-##  3 Sweden                    2.65      3
-##  4 Norway                    3.75      4
-##  5 Denmark                   4.04      5
-##  6 Finland                   7.80      6
-##  7 England and Wales        18.7       7
-##  8 Germany                  20.7       8
-##  9 Netherlands              24.9       9
-## 10 Switzerland              33.2      10
-## 11 Portugal                 48.0      11
-## 12 Italy                    62.8      12
-## 13 France                   90.2      13
-## 14 Spain                    92.6      14
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CountryPost/pre MSPE ratioRank
Spain92.571
France90.232
Italy62.813
Portugal48.024
Switzerland33.195
Netherlands24.926
Germany20.687
England and Wales18.678
Finland7.809
Denmark4.0410
Norway3.7511
Sweden2.6512
Iceland0.9613
United States of America0.2814

In placebo-country tests, England and Wales ranked 8 out of 14 countries by pre/post-MSPE ratio.

-

+

@@ -1958,7 +2228,7 @@

5.2.3 Placebo test $(document).ready(function () { $('.tabset-dropdown > .nav-tabs > li').click(function () { - $(this).parent().toggleClass('nav-tabs-open') + $(this).parent().toggleClass('nav-tabs-open'); }); }); diff --git a/its model repetition links b/its model repetition links new file mode 100644 index 0000000..f0fec65 --- /dev/null +++ b/its model repetition links @@ -0,0 +1,29 @@ +Model 1: +https://andybaxter.shinyapps.io/teen_preg_uk_its/?_inputs_&session=%22Full%20Plot%22&ages=%22Under%2018%22&main=%22England%22&control=%22none%22&obRange=%5B1992%2C2016%5D&int1yr=1999&pillscare=false&q=0&p=1 + +Model 2: +https://andybaxter.shinyapps.io/teen_preg_uk_its/?_inputs_&session=%22Full%20Plot%22&ages=%22Under%2018%22&main=%22England%22&control=%22none%22&obRange=%5B1992%2C2016%5D&int1yr=1999&pillscare=true&q=0&p=1 + +Model 3: +https://andybaxter.shinyapps.io/teen_preg_uk_its/?_inputs_&session=%22Full%20Plot%22&ages=%22Under%2018%22&main=%22England%22&control=%22Scotland%22&obRange=%5B1992%2C2016%5D&int1yr=1999&pillscare=true&q=0&p=1¶llel=true + +Model 4: +https://andybaxter.shinyapps.io/teen_preg_uk_its/?_inputs_&session=%22Full%20Plot%22&ages=%22Under%2018%22&main=%22England%22&control=%22Wales%22&obRange=%5B1992%2C2016%5D&int1yr=1999&pillscare=true&q=0&p=1¶llel=true + +Model 5: +https://andybaxter.shinyapps.io/teen_preg_uk_its/?_inputs_&session=%22Full%20Plot%22&ages=%22Under%2018%22&main=%22England%22&control=%22none%22&obRange=%5B1992%2C2016%5D&int1yr=1999&pillscare=true&q=0&p=1¶llel=true&int2yr=2008&int2=true + +Model 6: +https://andybaxter.shinyapps.io/teen_preg_uk_its/?_inputs_&session=%22Full%20Plot%22&ages=%22Under%2018%22&main=%22England%22&control=%22Scotland%22&obRange=%5B1992%2C2016%5D&int1yr=1999&pillscare=true&q=0&p=1¶llel=true&int2yr=2008&int2=true + +Model 7: +https://andybaxter.shinyapps.io/teen_preg_uk_its/?_inputs_&session=%22Full%20Plot%22&ages=%22Under%2018%22&main=%22England%22&control=%22Wales%22&obRange=%5B1992%2C2016%5D&int1yr=1999&pillscare=true&q=0&p=1¶llel=true&int2yr=2008&int2=true + +Model 8: +https://andybaxter.shinyapps.io/teen_preg_uk_its/?_inputs_&session=%22Full%20Plot%22&ages=%22Under%2018%22&main=%22England%20and%20Wales%22&control=%22Scotland%22&obRange=%5B1992%2C2016%5D&int1yr=1999&pillscare=true&q=0&p=1¶llel=true + +Model 9: +https://andybaxter.shinyapps.io/teen_preg_uk_its/?_inputs_&session=%22Full%20Plot%22&ages=%22Under%2016%22&main=%22England%20and%20Wales%22&control=%22Scotland%22&obRange=%5B1994%2C2016%5D&int1yr=1999&pillscare=true&q=0&p=1¶llel=true + +Model 10: +https://andybaxter.shinyapps.io/teen_preg_uk_its/?_inputs_&session=%22Full%20Plot%22&ages=%22Under%2020%22&main=%22England%20and%20Wales%22&control=%22Scotland%22&obRange=%5B1991%2C2016%5D&int1yr=1999&pillscare=true&q=0&p=1¶llel=true \ No newline at end of file diff --git a/newplot.png b/newplot.png new file mode 100644 index 0000000..f9881ab Binary files /dev/null and b/newplot.png differ diff --git a/renv.lock b/renv.lock index be17ab7..1313700 100644 --- a/renv.lock +++ b/renv.lock @@ -175,13 +175,6 @@ "Repository": "CRAN", "Hash": "d9778c960792721e8433daaf3db8f16a" }, - "brio": { - "Package": "brio", - "Version": "1.1.1", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "36758510e65a457efeefa50e1e7f0576" - }, "broom": { "Package": "broom", "Version": "0.7.5", @@ -343,13 +336,6 @@ "Repository": "CRAN", "Hash": "f30247ffeeebe8d9842dc68fe63e043b" }, - "desc": { - "Package": "desc", - "Version": "1.2.0", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "6c8fe8fa26a23b79949375d372c7b395" - }, "devEMF": { "Package": "devEMF", "Version": "4.0-2", @@ -357,13 +343,6 @@ "Repository": "CRAN", "Hash": "6d64bee9dcf472c0ecdf01f841dee4f6" }, - "diffobj": { - "Package": "diffobj", - "Version": "0.3.3", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "55fae7ec1418d2a47bd552571673d1af" - }, "digest": { "Package": "digest", "Version": "0.6.27", @@ -612,13 +591,6 @@ "Repository": "CRAN", "Hash": "a525aba14184fec243f9eaec62fbed43" }, - "isoband": { - "Package": "isoband", - "Version": "0.2.3", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "53647fb507373700028b2ce6cd30751a" - }, "iterators": { "Package": "iterators", "Version": "1.0.13", @@ -864,13 +836,6 @@ "Repository": "CRAN", "Hash": "39a778e4e487ded8b1bf5bb617c567b3" }, - "pkgbuild": { - "Package": "pkgbuild", - "Version": "1.2.0", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "725fcc30222d4d11ec68efb8ff11a9af" - }, "pkgconfig": { "Package": "pkgconfig", "Version": "2.0.3", @@ -878,13 +843,6 @@ "Repository": "CRAN", "Hash": "01f28d4278f15c76cddbea05899c5d6f" }, - "pkgload": { - "Package": "pkgload", - "Version": "1.2.0", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "cb57de933545960a86f03513e4bd2911" - }, "plotly": { "Package": "plotly", "Version": "4.9.3", @@ -906,13 +864,6 @@ "Repository": "CRAN", "Hash": "c396592ecfe9e75cee1013533efafe34" }, - "praise": { - "Package": "praise", - "Version": "1.0.0", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "a555924add98c99d2f411e37e7d25e9f" - }, "prettyunits": { "Package": "prettyunits", "Version": "1.1.1", @@ -997,13 +948,6 @@ "Repository": "CRAN", "Hash": "c66b930d20bb6d858cd18e1cebcfae5c" }, - "rematch2": { - "Package": "rematch2", - "Version": "2.1.2", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "76c9e04c712a05848ae7a23d2f170a40" - }, "renv": { "Package": "renv", "Version": "0.13.0", @@ -1067,13 +1011,6 @@ "Repository": "CRAN", "Hash": "0d34b89b43e900467e60f5449226f3e3" }, - "rprojroot": { - "Package": "rprojroot", - "Version": "2.0.2", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "249d8cd1e74a8f6a26194a91b47f21d1" - }, "rsconnect": { "Package": "rsconnect", "Version": "0.8.16", @@ -1207,13 +1144,6 @@ "Repository": "CRAN", "Hash": "6e899d7c097698d50ec87b1d8e65f246" }, - "testthat": { - "Package": "testthat", - "Version": "3.0.2", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "495e0434d9305716b6a87031570ce109" - }, "tibble": { "Package": "tibble", "Version": "3.1.0", @@ -1291,13 +1221,6 @@ "Repository": "CRAN", "Hash": "ce4f6271baa94776db692f1cb2055bee" }, - "waldo": { - "Package": "waldo", - "Version": "0.2.4", - "Source": "Repository", - "Repository": "CRAN", - "Hash": "29df52c781e572c967f90de9713423c4" - }, "webshot": { "Package": "webshot", "Version": "0.5.2", diff --git a/renv/.gitignore b/renv/.gitignore deleted file mode 100644 index 2129631..0000000 --- a/renv/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -library/ -local/ -lock/ -python/ -staging/ diff --git a/renv/activate.R b/renv/activate.R deleted file mode 100644 index 2cba08a..0000000 --- a/renv/activate.R +++ /dev/null @@ -1,653 +0,0 @@ - -local({ - - # the requested version of renv - version <- "0.13.0" - - # the project directory - project <- getwd() - - # avoid recursion - if (!is.na(Sys.getenv("RENV_R_INITIALIZING", unset = NA))) - return(invisible(TRUE)) - - # signal that we're loading renv during R startup - Sys.setenv("RENV_R_INITIALIZING" = "true") - on.exit(Sys.unsetenv("RENV_R_INITIALIZING"), add = TRUE) - - # signal that we've consented to use renv - options(renv.consent = TRUE) - - # load the 'utils' package eagerly -- this ensures that renv shims, which - # mask 'utils' packages, will come first on the search path - library(utils, lib.loc = .Library) - - # check to see if renv has already been loaded - if ("renv" %in% loadedNamespaces()) { - - # if renv has already been loaded, and it's the requested version of renv, - # nothing to do - spec <- .getNamespaceInfo(.getNamespace("renv"), "spec") - if (identical(spec[["version"]], version)) - return(invisible(TRUE)) - - # otherwise, unload and attempt to load the correct version of renv - unloadNamespace("renv") - - } - - # load bootstrap tools - bootstrap <- function(version, library) { - - # attempt to download renv - tarball <- tryCatch(renv_bootstrap_download(version), error = identity) - if (inherits(tarball, "error")) - stop("failed to download renv ", version) - - # now attempt to install - status <- tryCatch(renv_bootstrap_install(version, tarball, library), error = identity) - if (inherits(status, "error")) - stop("failed to install renv ", version) - - } - - renv_bootstrap_tests_running <- function() { - getOption("renv.tests.running", default = FALSE) - } - - renv_bootstrap_repos <- function() { - - # check for repos override - repos <- Sys.getenv("RENV_CONFIG_REPOS_OVERRIDE", unset = NA) - if (!is.na(repos)) - return(repos) - - # if we're testing, re-use the test repositories - if (renv_bootstrap_tests_running()) - return(getOption("renv.tests.repos")) - - # retrieve current repos - repos <- getOption("repos") - - # ensure @CRAN@ entries are resolved - repos[repos == "@CRAN@"] <- "https://cloud.r-project.org" - - # add in renv.bootstrap.repos if set - default <- c(FALLBACK = "https://cloud.r-project.org") - extra <- getOption("renv.bootstrap.repos", default = default) - repos <- c(repos, extra) - - # remove duplicates that might've snuck in - dupes <- duplicated(repos) | duplicated(names(repos)) - repos[!dupes] - - } - - renv_bootstrap_download <- function(version) { - - # if the renv version number has 4 components, assume it must - # be retrieved via github - nv <- numeric_version(version) - components <- unclass(nv)[[1]] - - methods <- if (length(components) == 4L) { - list( - renv_bootstrap_download_github - ) - } else { - list( - renv_bootstrap_download_cran_latest, - renv_bootstrap_download_cran_archive - ) - } - - for (method in methods) { - path <- tryCatch(method(version), error = identity) - if (is.character(path) && file.exists(path)) - return(path) - } - - stop("failed to download renv ", version) - - } - - renv_bootstrap_download_impl <- function(url, destfile) { - - mode <- "wb" - - # https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17715 - fixup <- - Sys.info()[["sysname"]] == "Windows" && - substring(url, 1L, 5L) == "file:" - - if (fixup) - mode <- "w+b" - - utils::download.file( - url = url, - destfile = destfile, - mode = mode, - quiet = TRUE - ) - - } - - renv_bootstrap_download_cran_latest <- function(version) { - - repos <- renv_bootstrap_download_cran_latest_find(version) - - message("* Downloading renv ", version, " ... ", appendLF = FALSE) - - downloader <- function(type) { - - tryCatch( - utils::download.packages( - pkgs = "renv", - destdir = tempdir(), - repos = repos, - type = type, - quiet = TRUE - ), - condition = identity - ) - - } - - # first, try downloading a binary on Windows + macOS if appropriate - binary <- - !identical(.Platform$pkgType, "source") && - !identical(getOption("pkgType"), "source") && - Sys.info()[["sysname"]] %in% c("Darwin", "Windows") - - if (binary) { - info <- downloader(type = "binary") - if (!inherits(info, "condition")) { - message("OK (downloaded binary)") - return(info[1, 2]) - } - } - - # otherwise, try downloading a source tarball - info <- downloader(type = "source") - if (inherits(info, "condition")) { - message("FAILED") - return(FALSE) - } - - # report success and return - message("OK (downloaded source)") - info[1, 2] - - } - - renv_bootstrap_download_cran_latest_find <- function(version) { - - all <- renv_bootstrap_repos() - - for (repos in all) { - - db <- tryCatch( - as.data.frame( - x = utils::available.packages(repos = repos), - stringsAsFactors = FALSE - ), - error = identity - ) - - if (inherits(db, "error")) - next - - entry <- db[db$Package %in% "renv" & db$Version %in% version, ] - if (nrow(entry) == 0) - next - - return(repos) - - } - - fmt <- "renv %s is not available from your declared package repositories" - stop(sprintf(fmt, version)) - - } - - renv_bootstrap_download_cran_archive <- function(version) { - - name <- sprintf("renv_%s.tar.gz", version) - repos <- renv_bootstrap_repos() - urls <- file.path(repos, "src/contrib/Archive/renv", name) - destfile <- file.path(tempdir(), name) - - message("* Downloading renv ", version, " ... ", appendLF = FALSE) - - for (url in urls) { - - status <- tryCatch( - renv_bootstrap_download_impl(url, destfile), - condition = identity - ) - - if (identical(status, 0L)) { - message("OK") - return(destfile) - } - - } - - message("FAILED") - return(FALSE) - - } - - renv_bootstrap_download_github <- function(version) { - - enabled <- Sys.getenv("RENV_BOOTSTRAP_FROM_GITHUB", unset = "TRUE") - if (!identical(enabled, "TRUE")) - return(FALSE) - - # prepare download options - pat <- Sys.getenv("GITHUB_PAT") - if (nzchar(Sys.which("curl")) && nzchar(pat)) { - fmt <- "--location --fail --header \"Authorization: token %s\"" - extra <- sprintf(fmt, pat) - saved <- options("download.file.method", "download.file.extra") - options(download.file.method = "curl", download.file.extra = extra) - on.exit(do.call(base::options, saved), add = TRUE) - } else if (nzchar(Sys.which("wget")) && nzchar(pat)) { - fmt <- "--header=\"Authorization: token %s\"" - extra <- sprintf(fmt, pat) - saved <- options("download.file.method", "download.file.extra") - options(download.file.method = "wget", download.file.extra = extra) - on.exit(do.call(base::options, saved), add = TRUE) - } - - message("* Downloading renv ", version, " from GitHub ... ", appendLF = FALSE) - - url <- file.path("https://api.github.com/repos/rstudio/renv/tarball", version) - name <- sprintf("renv_%s.tar.gz", version) - destfile <- file.path(tempdir(), name) - - status <- tryCatch( - renv_bootstrap_download_impl(url, destfile), - condition = identity - ) - - if (!identical(status, 0L)) { - message("FAILED") - return(FALSE) - } - - message("OK") - return(destfile) - - } - - renv_bootstrap_install <- function(version, tarball, library) { - - # attempt to install it into project library - message("* Installing renv ", version, " ... ", appendLF = FALSE) - dir.create(library, showWarnings = FALSE, recursive = TRUE) - - # invoke using system2 so we can capture and report output - bin <- R.home("bin") - exe <- if (Sys.info()[["sysname"]] == "Windows") "R.exe" else "R" - r <- file.path(bin, exe) - args <- c("--vanilla", "CMD", "INSTALL", "-l", shQuote(library), shQuote(tarball)) - output <- system2(r, args, stdout = TRUE, stderr = TRUE) - message("Done!") - - # check for successful install - status <- attr(output, "status") - if (is.numeric(status) && !identical(status, 0L)) { - header <- "Error installing renv:" - lines <- paste(rep.int("=", nchar(header)), collapse = "") - text <- c(header, lines, output) - writeLines(text, con = stderr()) - } - - status - - } - - renv_bootstrap_platform_prefix <- function() { - - # construct version prefix - version <- paste(R.version$major, R.version$minor, sep = ".") - prefix <- paste("R", numeric_version(version)[1, 1:2], sep = "-") - - # include SVN revision for development versions of R - # (to avoid sharing platform-specific artefacts with released versions of R) - devel <- - identical(R.version[["status"]], "Under development (unstable)") || - identical(R.version[["nickname"]], "Unsuffered Consequences") - - if (devel) - prefix <- paste(prefix, R.version[["svn rev"]], sep = "-r") - - # build list of path components - components <- c(prefix, R.version$platform) - - # include prefix if provided by user - prefix <- renv_bootstrap_platform_prefix_impl() - if (!is.na(prefix) && nzchar(prefix)) - components <- c(prefix, components) - - # build prefix - paste(components, collapse = "/") - - } - - renv_bootstrap_platform_prefix_impl <- function() { - - # if an explicit prefix has been supplied, use it - prefix <- Sys.getenv("RENV_PATHS_PREFIX", unset = NA) - if (!is.na(prefix)) - return(prefix) - - # if the user has requested an automatic prefix, generate it - auto <- Sys.getenv("RENV_PATHS_PREFIX_AUTO", unset = NA) - if (auto %in% c("TRUE", "True", "true", "1")) - return(renv_bootstrap_platform_prefix_auto()) - - # empty string on failure - "" - - } - - renv_bootstrap_platform_prefix_auto <- function() { - - prefix <- tryCatch(renv_bootstrap_platform_os(), error = identity) - if (inherits(prefix, "error") || prefix %in% "unknown") { - - msg <- paste( - "failed to infer current operating system", - "please file a bug report at https://github.com/rstudio/renv/issues", - sep = "; " - ) - - warning(msg) - - } - - prefix - - } - - renv_bootstrap_platform_os <- function() { - - sysinfo <- Sys.info() - sysname <- sysinfo[["sysname"]] - - # handle Windows + macOS up front - if (sysname == "Windows") - return("windows") - else if (sysname == "Darwin") - return("macos") - - # check for os-release files - for (file in c("/etc/os-release", "/usr/lib/os-release")) - if (file.exists(file)) - return(renv_bootstrap_platform_os_via_os_release(file, sysinfo)) - - # check for redhat-release files - if (file.exists("/etc/redhat-release")) - return(renv_bootstrap_platform_os_via_redhat_release()) - - "unknown" - - } - - renv_bootstrap_platform_os_via_os_release <- function(file, sysinfo) { - - # read /etc/os-release - release <- utils::read.table( - file = file, - sep = "=", - quote = c("\"", "'"), - col.names = c("Key", "Value"), - comment.char = "#", - stringsAsFactors = FALSE - ) - - vars <- as.list(release$Value) - names(vars) <- release$Key - - # get os name - os <- tolower(sysinfo[["sysname"]]) - - # read id - id <- "unknown" - for (field in c("ID", "ID_LIKE")) { - if (field %in% names(vars) && nzchar(vars[[field]])) { - id <- vars[[field]] - break - } - } - - # read version - version <- "unknown" - for (field in c("UBUNTU_CODENAME", "VERSION_CODENAME", "VERSION_ID", "BUILD_ID")) { - if (field %in% names(vars) && nzchar(vars[[field]])) { - version <- vars[[field]] - break - } - } - - # join together - paste(c(os, id, version), collapse = "-") - - } - - renv_bootstrap_platform_os_via_redhat_release <- function() { - - # read /etc/redhat-release - contents <- readLines("/etc/redhat-release", warn = FALSE) - - # infer id - id <- if (grepl("centos", contents, ignore.case = TRUE)) - "centos" - else if (grepl("redhat", contents, ignore.case = TRUE)) - "redhat" - else - "unknown" - - # try to find a version component (very hacky) - version <- "unknown" - - parts <- strsplit(contents, "[[:space:]]")[[1L]] - for (part in parts) { - - nv <- tryCatch(numeric_version(part), error = identity) - if (inherits(nv, "error")) - next - - version <- nv[1, 1] - break - - } - - paste(c("linux", id, version), collapse = "-") - - } - - renv_bootstrap_library_root_name <- function(project) { - - # use project name as-is if requested - asis <- Sys.getenv("RENV_PATHS_LIBRARY_ROOT_ASIS", unset = "FALSE") - if (asis) - return(basename(project)) - - # otherwise, disambiguate based on project's path - id <- substring(renv_bootstrap_hash_text(project), 1L, 8L) - paste(basename(project), id, sep = "-") - - } - - renv_bootstrap_library_root <- function(project) { - - path <- Sys.getenv("RENV_PATHS_LIBRARY", unset = NA) - if (!is.na(path)) - return(path) - - path <- Sys.getenv("RENV_PATHS_LIBRARY_ROOT", unset = NA) - if (!is.na(path)) { - name <- renv_bootstrap_library_root_name(project) - return(file.path(path, name)) - } - - prefix <- renv_bootstrap_profile_prefix() - paste(c(project, prefix, "renv/library"), collapse = "/") - - } - - renv_bootstrap_validate_version <- function(version) { - - loadedversion <- utils::packageDescription("renv", fields = "Version") - if (version == loadedversion) - return(TRUE) - - # assume four-component versions are from GitHub; three-component - # versions are from CRAN - components <- strsplit(loadedversion, "[.-]")[[1]] - remote <- if (length(components) == 4L) - paste("rstudio/renv", loadedversion, sep = "@") - else - paste("renv", loadedversion, sep = "@") - - fmt <- paste( - "renv %1$s was loaded from project library, but this project is configured to use renv %2$s.", - "Use `renv::record(\"%3$s\")` to record renv %1$s in the lockfile.", - "Use `renv::restore(packages = \"renv\")` to install renv %2$s into the project library.", - sep = "\n" - ) - - msg <- sprintf(fmt, loadedversion, version, remote) - warning(msg, call. = FALSE) - - FALSE - - } - - renv_bootstrap_hash_text <- function(text) { - - hashfile <- tempfile("renv-hash-") - on.exit(unlink(hashfile), add = TRUE) - - writeLines(text, con = hashfile) - tools::md5sum(hashfile) - - } - - renv_bootstrap_load <- function(project, libpath, version) { - - # try to load renv from the project library - if (!requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) - return(FALSE) - - # warn if the version of renv loaded does not match - renv_bootstrap_validate_version(version) - - # load the project - renv::load(project) - - TRUE - - } - - renv_bootstrap_profile_load <- function(project) { - - # if RENV_PROFILE is already set, just use that - profile <- Sys.getenv("RENV_PROFILE", unset = NA) - if (!is.na(profile) && nzchar(profile)) - return(profile) - - # check for a profile file (nothing to do if it doesn't exist) - path <- file.path(project, "renv/local/profile") - if (!file.exists(path)) - return(NULL) - - # read the profile, and set it if it exists - contents <- readLines(path, warn = FALSE) - if (length(contents) == 0L) - return(NULL) - - # set RENV_PROFILE - profile <- contents[[1L]] - if (nzchar(profile)) - Sys.setenv(RENV_PROFILE = profile) - - profile - - } - - renv_bootstrap_profile_prefix <- function() { - profile <- renv_bootstrap_profile_get() - if (!is.null(profile)) - return(file.path("renv/profiles", profile)) - } - - renv_bootstrap_profile_get <- function() { - profile <- Sys.getenv("RENV_PROFILE", unset = "") - renv_bootstrap_profile_normalize(profile) - } - - renv_bootstrap_profile_set <- function(profile) { - profile <- renv_bootstrap_profile_normalize(profile) - if (is.null(profile)) - Sys.unsetenv("RENV_PROFILE") - else - Sys.setenv(RENV_PROFILE = profile) - } - - renv_bootstrap_profile_normalize <- function(profile) { - - if (is.null(profile) || profile %in% c("", "default")) - return(NULL) - - profile - - } - - # load the renv profile, if any - renv_bootstrap_profile_load(project) - - # construct path to library root - root <- renv_bootstrap_library_root(project) - - # construct library prefix for platform - prefix <- renv_bootstrap_platform_prefix() - - # construct full libpath - libpath <- file.path(root, prefix) - - # attempt to load - if (renv_bootstrap_load(project, libpath, version)) - return(TRUE) - - # load failed; inform user we're about to bootstrap - prefix <- paste("# Bootstrapping renv", version) - postfix <- paste(rep.int("-", 77L - nchar(prefix)), collapse = "") - header <- paste(prefix, postfix) - message(header) - - # perform bootstrap - bootstrap(version, libpath) - - # exit early if we're just testing bootstrap - if (!is.na(Sys.getenv("RENV_BOOTSTRAP_INSTALL_ONLY", unset = NA))) - return(TRUE) - - # try again to load - if (requireNamespace("renv", lib.loc = libpath, quietly = TRUE)) { - message("* Successfully installed and loaded renv ", version, ".") - return(renv::load()) - } - - # failed to download or load renv; warn the user - msg <- c( - "Failed to find an renv installation: the project will not be loaded.", - "Use `renv::activate()` to re-initialize the project." - ) - - warning(paste(msg, collapse = "\n"), call. = FALSE) - -}) diff --git a/renv/settings.dcf b/renv/settings.dcf deleted file mode 100644 index bf722e8..0000000 --- a/renv/settings.dcf +++ /dev/null @@ -1,7 +0,0 @@ -external.libraries: -ignored.packages: -package.dependency.fields: Imports, Depends, LinkingTo -r.version: -snapshot.type: implicit -use.cache: TRUE -vcs.ignore.library: TRUE diff --git a/test spine plot.png b/test spine plot.png new file mode 100644 index 0000000..80c0913 Binary files /dev/null and b/test spine plot.png differ diff --git a/test.html b/test.html new file mode 100644 index 0000000..4ce6bad --- /dev/null +++ b/test.html @@ -0,0 +1,231 @@ + + + + + + + + + + + + + + + +try button + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
+

R Markdown

+

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

+ +
+ + + + +
+ + + + + + + + + + + + + + + diff --git a/test.rmd b/test.rmd new file mode 100644 index 0000000..4e79168 --- /dev/null +++ b/test.rmd @@ -0,0 +1,17 @@ +--- +title: "try button" +author: "Andrew Baxter" +date: "08/03/2021" +output: html_document +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = TRUE) +``` + +## R Markdown + +This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see . + + + diff --git a/test_plot_1.png b/test_plot_1.png new file mode 100644 index 0000000..e0000fb Binary files /dev/null and b/test_plot_1.png differ