-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhow_unusual_was_2015.rmd
1247 lines (1066 loc) · 45.6 KB
/
how_unusual_was_2015.rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Was the fall in Scottish life expectancy in 2014-15 a chance event?"
output:
html_document:
df_print: paged
html_notebook: default
word_document: default
---
```{r}
rm(list = ls())
pacman::p_load(
tidyverse
)
dta_e0 <- read_csv("hmd_explorer/data/hmd_e0.csv")
```
We also want to take the estimates for Scotland for 2017 from the NRS.
```{r}
data_nrs <- tribble(
~code, ~year, ~gender, ~e0,
"GBR_SCO", 2017, "female", 81.15,
"GBR_SCO", 2017, "male", 77.14
)
dta_e0 <- bind_rows(
dta_e0,
data_nrs
)
```
# Introduction
* Risk of rare ecological events, such as a severe flood, are often expressed in terms of frequencies rather than probabilities. For example, a 1-in-100 year flood means that a flood of that severity or greater is expected to have a 1% probability of occurring in any particular year. However, this expectation is dependent on the models used to predict such risks, and these models are dependent on assumptions about how much the past is a reliable guide to the future.
* It is now becoming clear that many 1-in-100 year ecological events are occurring much more often than once every 100 years. For example [examples here] . The appearance of many very rare events in quick succession suggests that the models are wrong: what used to be a 1-in-100 year event is now a 1-in-20 year or 1-in-10 year event instead. The fundamentals have shifted, and the past is a less reliable guide to the future than it used to be.
* In recent years there have been concerns about life expectancies in Scotland either falling from the previous year, or not improving. This is against a backdrop of life expectancies tending to improve almost every year for many generations. [EXAMPLES]
* From 2014 to 2015 there was a notable fall in life expectancy in Scotland, by 0.30 years (3.6 months) for females and by 0.37 years (4.4 months) for males. This is in contrast to an average annual gain in life expectancy of 0.23 years (2.8 months) per year for females, and 0.23 years (2.7 months) per year for males, in Scotland since 1855; and an average gain of 0.18 years per year (2.2 months per year) for females and 0.20 years per year (2.4 months per year) for males, in the 60 year period between 1955 and 2014.
* The aim of this short report is to explore how likely it was that Scotland's 2014-15 fall in life expectancy was simply a 'chance event', a bad outlier like a particularly severe flood, that 'just happens' once every few decades, without the long-term fundamental drift towards ever longer lives really having changed. We conclude by asking whether the fall in 2014-15, and (lack of) improvement in gains subsequently, should give us concern that, like '1-in-100 year' floods occurring surprisingly frequently in the last decade or so, rare events like the 2014-15 life expectancy fall are no longer as rare as they used to be, and that the kinds of gains in longevity experienced by previous generations will not be experienced by subsequent generations.
```{r}
dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015) %>%
mutate(change_e0_months = change_e0 * 12)
```
# Methods
* Data on life expectancy at birth ($e_0$) in Scotland was extracted from the Human Mortality Database for all available years (First year 1855, last year 2016). The annual change in life expectancy ($\Delta e_0$) was then calculated for each year by sex. Change in life expectancy was then plotted against time, to help understand how unusual the 2014-15 fall in life expectancy was in a longer term context. Based on visual exploration of the data, the 60 year period 1955-2014 was selected as providing a range of observations both long-term enough, and recent enough, for the 2015 annual fall to be compared against.
* The rarity, probability and estimated frequency of the fall in 2014-15 was estimated using the data from 1955-2014 in two ways: firstly by counting the number of years where annual falls in life expectancy were as or more severe than that seen in 2014-15, and secondly by using sample means and standard deviations of the life expectancy changes to produce a normal distribution function for each sex, and calculating the cumulative probability of falls in life expectancy as or more severe than the 2014-15 fall from the 1955-2014 distribution of annual changes.
# Results
## Figure 1: Long term trend of change
* The figure below shows annual change in life expectancy in Scotland over time by sex. The point marking the 2014-15 fall is highlighted with a red point. Throughout the latter half of 19th century, and first half of the 20th century, there were much greater swings in annual changes in life expectancy than in the latter half of the 20th century and start of 21st century. Because high annual variability has not been observed for many decades, only data from 1955-2014 (highlighted grey) are used in subsequent analyses. [Though results with all data could be included in an appendix?] We can see from this figure that, though the 2014-15 fall in life expectancy is rare, it is not unprecedented in the 1955-2014 period.
* Some summary numbers?
```{r}
dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
ggplot(aes(x = year, y = change_e0)) +
geom_line() + geom_point() +
facet_grid(gender ~ .) +
geom_hline(yintercept = 0) +
scale_x_continuous(breaks = seq(1860, 2010, by = 10)) +
annotate("rect", xmin = 1955, xmax = 2014, ymin = -Inf, ymax = Inf, alpha = 0.2) +
labs(
title = "Annual changes in life expectancy over time in Scotland, 1855-2017",
subtitle = "Highlighted region: 1955-2014. Highlighted point: 2015",
caption = "Source: HMD, except 2017: courtesy of NRS",
x = "Year",
y = "Change in life expectancy from previous year in years"
) +
geom_point(
aes(x = year, y = change_e0),
size = 2, shape = 15, colour = "red",
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015)
)
```
## Figure 1b: Change from 1955
```{r}
dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
filter(year >= 1955) %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
ggplot(aes(x = year, y = change_e0)) +
geom_line() + geom_point() +
facet_grid(gender ~ .) +
geom_hline(yintercept = 0) +
scale_x_continuous(breaks = seq(1860, 2010, by = 10)) +
labs(
title = "Annual changes in life expectancy over time in Scotland, 1955-2017",
subtitle = "Highlighted region: 1955-2014. Highlighted point: 2015",
caption = "Source: HMD, except 2017: courtesy of NRS",
x = "Year",
y = "Change in life expectancy from previous year in years"
) +
geom_point(
aes(x = year, y = change_e0),
size = 2, shape = 15, colour = "red",
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015)
)
```
## Figure 2: Distribution
* Figure 2 below shows the distribution of annual changes in life expectancy over the 1955-2014 period. Each observation is represented as a vertical 'tick', and the years corresponding to the two largest annual increases and declines are labelled. The black vertical line indicates no change from the previous year, the thinner blue vertical line shows the average annual change over the period, and the dashed red line indicates the change observed in 2014-15. The grey shape above the points shows the density of the distribution.
* We can see from this that for males, only one year, 1967-68, has seen a sharper annual fall in life expectancy than the change in 2014-15. We can also see that 1967-68 was preceeded by an especially high rate of improvement the previous year, 1966-67. Over the 60 year period, only one year saw a faster fall in life expectancy for males, whereas for females four years saw greater annual declines than occurred in 2014-15.
```{r}
dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1955, 2014)) %>%
ggplot(aes(x = change_e0)) +
stat_density(alpha = 0.2) +
geom_rug() +
facet_grid(gender ~ .) +
geom_vline(xintercept = 0, size = 1.5) +
geom_vline(
aes(xintercept =change_e0),
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015),
colour = "red",
linetype = "dashed"
) +
geom_vline(
aes(xintercept =mean_change_e0),
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1955, 2014)) %>%
group_by(gender) %>%
summarise(mean_change_e0 = mean(change_e0)) %>%
ungroup(),
colour = "blue"
) +
labs(
title = "Range of falls and gains in annual life expectancy in Scotland, 1955-2014",
x = "Change in life expectancy from previous year in years",
y = "Density of distribution of changes"
) +
geom_text(
aes(x = mean_change_e0), y = 0.75,
label = "Average\nChange", fontface = "bold", colour = "white",
nudge_y = 0.01, nudge_x = 0.0025,
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1955, 2014)) %>%
group_by(gender) %>%
summarise(mean_change_e0 = mean(change_e0)) %>%
ungroup()
) +
geom_text(
aes(x = mean_change_e0), y = 0.75,
label = "Average\nChange", fontface = "bold",
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1955, 2014)) %>%
group_by(gender) %>%
summarise(mean_change_e0 = mean(change_e0)) %>%
ungroup()
) +
geom_text(
aes(x = change_e0), y = 0.75,
label = "Change from\n2014-2015", fontface = "bold", colour = "white",
nudge_y = 0.01, nudge_x = 0.0025,
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015)
) +
geom_text(
aes(x = change_e0), y = 0.75,
label = "Change from\n2014-2015", fontface = "bold",
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015)
) +
geom_text(
aes(x = change_e0), y = 0.75,
label = "Change from\n2014-2015", fontface = "bold",
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015)
) +
geom_text(
aes(x = change_e0, label = year), y = 0.1,
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1955, 2014)) %>%
mutate(rank_ch = rank(change_e0)) %>%
filter(rank_ch <= 2 | rank_ch >= 59)
)
```
## Modelling
## How rare was the 2014-15 change? The simple approach
* As there was one event as or more severe than the 2014-15 fall for males, and four events as more severe than the 2014-15 fall for females, and there were 60 observations for each sex, the simple estimates for the 2014-15 fall are 1/60 (around 1.7%) for males and 4/60 (around 6.7%) for females.
* If needed, credible intervals for the above could be produced through bootstrapping. (i.e. repeatedly resampling from the same data).
## How rare was the 2014-15 change? A slightly more complicated approach
The table below shows the mean and standard deviation of the annual changes that occurred between 1955-2014. The average (mean) annual improvement was 0.18 years per year for females and 0.20 years per year for males, with a standard deviation of 0.31 for females and 0.27 for males. These values are used to estimate the probability, and so expected frequency, of the 2014-15 decline, using a normal distribution. This approach suggestes there is a 6.0% change of an event as or more severe than the 2014-15 decline for females, and a 1.7% probability of observing an event as or more severe than the 2014-15 decline for males. This suggests the 2014-15 fall was a 1-in-17 year event for females, and a 1-in-60 year event for males.
```{r}
summary_stats <- dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1955, 2014)) %>%
group_by(gender) %>%
summarise(
mean_ch_e0 = mean(change_e0),
sd_ch_e0 = sd(change_e0)
) %>%
ungroup()
summary_stats
```
```{r}
summary_stats %>%
left_join(
dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015) %>%
select(gender, change_in_2015 = change_e0)
) %>%
mutate(
prob_2015_chance = pmap_dbl(
list(
q = change_in_2015,
mean = mean_ch_e0,
sd = sd_ch_e0
),
.f = pnorm
),
one_in = 1/ prob_2015_chance,
prob_no_improvovement = pmap_dbl(
list(
q = c(0,0),
mean = mean_ch_e0,
sd = sd_ch_e0
),
.f = pnorm
)
)
```
# Discussion
* The simple analyses above has indicated that the fall in life expectancy in Scotland from 2014-15 was rare but not unprecedented. It was a rare event for both sexes, but more so for males than females. Considering the ups and downs in life expectancy changes in Scotland from 1955-2014, a fall in life expectancy as or more severe than that seen in 2014-15 could be expected to occur once every 17 years on average for females, and once every 60 years on average for males.
* Limitations
* Comparison with other findings
* This result might be taken to suggest that the possibility that the 2014-15 was simply a 'chance event', rather than the start of a long-term slowdown or stagnation in improving life expectancy, cannot be ruled out. Variation in mortality rates from one year to the next can occur due to random seasonal variation in temperature and infectious diseases, especially influenza. [REFS]
* However, perhaps more unusual and concerning than the fall in life expectancy from 2014-15 was the lack of any substantial increase in life expectancy which occurred in the following year. This should be concerning because, unlike the very simple modelling approach used for illustration and estimation above, changes in life expectancy over a year are likely to be *negatively correlated* (rather than *uncorrelated*) with changes in the previous year.
* Analysis of annual mortality changes *does* suggest that the data for Scotland exhibits this negative correlation pattern. (See appendix?) This means the lack of improvement in life expectancy from 2015-16, after the substantial fall in life expectancy in 2014-15, is particularly unusual, and that recent trends in changes in life expectancy should be monitored and analysed very carefully to determine whether 2014-15 represents a change in the 'population climate', a chance event, or a combination of both.
* Final summary statement
# Appendix? Quick exploration: negative autocorrelation
The model above assumes that the change in life expectancy in any year is not dependent on that in the previous year.
Put another way, the model is 'memoryless', and has not predictor terms (i.e. 'right hand' terms in regression formula).
The next simplest model approach would be to build a model that includes the previous year's change as a predictor variable. So, a one year lag term.
The prior hypothesis - consistent with 'harvesting' - is that the change in one year will be negatively correlated with the previous year.
This can be done by building a linear regression model with the previous year as a predictor variable
```{r}
mdls <- dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
mutate(last_change_e0 = lag(change_e0)) %>%
filter(between(year, 1955, 2014)) %>%
group_by(gender) %>%
nest() %>%
mutate(mdl_nolag = map(data, ~lm(change_e0 ~ 1, data = .))) %>%
mutate(mdl_lag = map(data, ~lm(change_e0 ~ last_change_e0, data = .))) %>%
mutate(anova = map2(mdl_nolag, mdl_lag, anova)) %>%
mutate(p_autocorrelation = map_dbl(anova, ~.[2,6])) %>%
mutate(model_lag_tidy = map(mdl_lag, broom::tidy))
lag_mdl_summary <- mdls %>%
select(gender, model_lag_tidy) %>%
unnest()
p_autocorr_female <- mdls %>% filter(gender == "female") %>% pull("p_autocorrelation")
p_autocorr_male <- mdls %>% filter(gender == "male") %>% pull("p_autocorrelation")
```
Two model specifications have been built.
* `mdl_nolag` is effectively the model specification used above, which has no predictor terms.
* `mdl_lag` includes the previous year's change as a predictor variable.
As `mdl_nolag` is the same as `mdl_lag` with one of its terms set to zero, `mdl_nolag` is a restricted version of `mdl_lag`, and so ANOVA can be used to test whether the move from the unrestricted model (`mdl_nolag`) to the restricted (`mdl_lag`) is justified in terms of improved fit to the data. In effect, the ANOVA test gives us an estimated probability that the data contains autocorrelation. These probabilities are `r round(p_autocorr_female, 5)` for females, and `r round(p_autocorr_male, 5)` for males, and so provide strong evidence that autocorrelation exists in the data.
The specific type of autocorrelation of interest is negative autocorrelation. Negative autocorrelation would be present if the `estimate` column for the term `last_change_e0` were negative. The coefficient of this term is statistically significant at p < 0.05 if the corresponding row in the column `p.value` is below 0.05. We can see from the table below that both of these conditions are true, though the magnitude of the negative autocorrelation is larger for females than males, and the associated p value for females much smaller than for males.
```{r}
lag_mdl_summary
```
One conclusion we might draw from this evidence that the data contains negative autocorrelation is that the most troubling aspect of changes in life expectancy in Scotland since 2014 is not necessarily the fall in life expectancy from 2014-15, but the lack of any notable recovery in life expectancy increases from 2015-16. Negative autocorrelation would imply that a year showing a substantial fall in life expectancy is more likely to be followed by a substantial improvement in life expectancy, above the long-term average improvement, the following year. Instead, life expectancy improvement in 2015-16 was close to zero.
# Breakpoint models
We've seen earlier how, using data up to 2014, including a lag(1) term leads to a better model fit, as assessed using ANOVA.
We now want to return to the breakpoint approach used in the previous paper with Lynda and Gerry. This will help get a sense of how much additional value explicitly adding a breakpoint post 2012 adds to the model fit. There's a subsidiary hypothesis: that rates of improvement in the 1990s were atypically high. This can also be assessed formally.
```{r}
mdls_brk <- dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
mutate(last_change_e0 = lag(change_e0)) %>%
mutate(nineties = between(year, 1990, 1999)) %>%
mutate(brkpoint = year >= 2012) %>%
filter(between(year, 1955, 2017)) %>%
group_by(gender) %>%
nest() %>%
mutate(mdl_nobrk = map(data, ~lm(change_e0 ~ 1, data = .))) %>%
mutate(mdl_brk = map(data, ~lm(change_e0 ~ brkpoint, data = .))) %>%
mutate(mdl_nineties_good = map(data, ~lm(change_e0 ~ nineties, data = .))) %>%
mutate(anova_brk = map2(mdl_nobrk, mdl_brk, anova)) %>%
mutate(anova_90s = map2(mdl_nobrk, mdl_nineties_good, anova)) %>%
mutate(p_breakpoint = map_dbl(anova_brk, ~.[2,6])) %>%
mutate(p_nineties_good = map_dbl(anova_90s, ~.[2,6])) %>%
mutate(model_brk_tidy = map(mdl_brk, broom::tidy)) %>%
mutate(model_90s_tidy = map(mdl_nineties_good, broom::tidy))
brk_mdl_summary <- mdls_brk %>%
select(gender, model_brk_tidy) %>%
unnest()
nineties_mdl_summary <- mdls_brk %>%
select(gender, model_90s_tidy) %>%
unnest()
p_brk_female <- mdls_brk %>% filter(gender == "female") %>% pull("p_breakpoint")
p_brk_male <- mdls_brk %>% filter(gender == "male") %>% pull("p_breakpoint")
p_90s_female <- mdls_brk %>% filter(gender == "female") %>% pull("p_nineties_good")
p_90s_male <- mdls_brk %>% filter(gender == "male") %>% pull("p_nineties_good")
```
Based on this approach, it seems there's not strong evidence (p ~ 0.35) for a post-2012 breakpoint, though there's even weaker evidence (p ~ 0.75) that the 90s were an 'exceptionally good' period of continual health improvement. This provides a little reassurance that analyses which use 1990 as the start of the time series aren't completely wrong.
# Appendix: What if all available years were used for Scotland?
This supplementary analysis will explore the effect of using all available years for Scotland, rather than 1955-2014. This should be useful for avoiding any accusation of 'cherry picking' the selection of years.
```{r}
dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1855, 2014)) %>%
ggplot(aes(x = change_e0)) +
stat_density(alpha = 0.2) +
geom_rug() +
facet_grid(gender ~ .) +
geom_vline(xintercept = 0, size = 1.5) +
geom_vline(
aes(xintercept =change_e0),
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015),
colour = "red",
linetype = "dashed"
) +
geom_vline(
aes(xintercept =mean_change_e0),
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1855, 2014)) %>%
group_by(gender) %>%
summarise(mean_change_e0 = mean(change_e0, na.rm = T)) %>%
ungroup(),
colour = "blue"
) +
labs(
title = "Range of falls and gains in annual life expectancy in Scotland, 1855-2014",
x = "Change in life expectancy from previous year in years",
y = "Density of distribution of changes"
) +
geom_text(
aes(x = mean_change_e0), y = 0.15,
label = "Average\nChange", fontface = "bold", colour = "white",
nudge_y = 0.01, nudge_x = 0.0025,
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1855, 2014)) %>%
group_by(gender) %>%
summarise(mean_change_e0 = mean(change_e0, na.rm = T)) %>%
ungroup()
) +
geom_text(
aes(x = mean_change_e0), y = 0.15,
label = "Average\nChange", fontface = "bold",
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1855, 2014)) %>%
group_by(gender) %>%
summarise(mean_change_e0 = mean(change_e0, na.rm = T)) %>%
ungroup()
) +
geom_text(
aes(x = change_e0), y = 0.45,
label = "Change from\n2014-2015", fontface = "bold", colour = "white",
nudge_y = 0.01, nudge_x = 0.0025,
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015)
) +
geom_text(
aes(x = change_e0), y = 0.45,
label = "Change from\n2014-2015", fontface = "bold",
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015)
) +
geom_text(
aes(x = change_e0), y = 0.45,
label = "Change from\n2014-2015", fontface = "bold",
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015)
) +
geom_text(
aes(x = change_e0, label = year), y = 0.1,
data = dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1855, 2014)) %>%
mutate(rank_ch = rank(change_e0)) %>%
filter(rank_ch <= 2 | rank_ch >= 158)
)
```
It's clear that there used to be much more variability in annual changes before the Second World War than after, and that a Normal distribution is much less appropriate. However if summarising the data in this way the mean and sd are as follows:
```{r}
summary_stats_full <- dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1855, 2014)) %>%
group_by(gender) %>%
summarise(
mean_ch_e0 = mean(change_e0, na.rm = T),
sd_ch_e0 = sd(change_e0, na.rm = T)
) %>%
ungroup()
summary_stats_full
```
The mean increases were a bit higher, but the SDs were much, much higher.
If making the assumption that the kind of extreme variability in annual changes observed in the 19th century and first half of the 20th century should still be considered relevant, then the probability of seeing a fall as or more severe than seen in 2014-15 falls to one-in-3. (See below)
```{r}
summary_stats_full %>%
left_join(
dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015) %>%
select(gender, change_in_2015 = change_e0)
) %>%
mutate(
prob_2015_chance = pmap_dbl(
list(
q = change_in_2015,
mean = mean_ch_e0,
sd = sd_ch_e0
),
.f = pnorm
),
one_in = 1/ prob_2015_chance,
prob_no_improvovement = pmap_dbl(
list(
q = c(0,0),
mean = mean_ch_e0,
sd = sd_ch_e0
),
.f = pnorm
)
)
```
# Appendix: How does this compare with England & Wales?
```{r}
dta_e0 %>%
filter(code == "GBRCENW") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
ggplot(aes(x = year, y = change_e0)) +
geom_line() + geom_point() +
facet_grid(gender ~ .) +
geom_hline(yintercept = 0) +
scale_x_continuous(breaks = seq(1840, 2010, by = 10)) +
annotate("rect", xmin = 1955, xmax = 2014, ymin = -Inf, ymax = Inf, alpha = 0.2) +
labs(
title = "Annual changes in life expectancy over time in England & Wales, 1841-2016",
subtitle = "Highlighted region: 1955-2014. Highlighted point: 2015",
caption = "Source: HMD",
x = "Year",
y = "Change in life expectancy from previous year in years"
) +
geom_point(
aes(x = year, y = change_e0),
size = 2, shape = 15, colour = "red",
data = dta_e0 %>%
filter(code == "GBRCENW") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015)
)
```
The range of variability is much higher, due to much greater exposure to the 1918 influenza pandemic/end of First World War. Let's now look again just at the range starting 1955
```{r}
dta_e0 %>%
filter(code == "GBRCENW") %>%
filter(year >= 1955) %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
ggplot(aes(x = year, y = change_e0)) +
geom_line() + geom_point() +
facet_grid(gender ~ .) +
geom_hline(yintercept = 0) +
scale_x_continuous(breaks = seq(1860, 2010, by = 10)) +
labs(
title = "Annual changes in life expectancy over time in England & Wales, 1955-2016",
subtitle = "Highlighted point: 2015",
caption = "Source: HMD",
x = "Year",
y = "Change in life expectancy from previous year in years"
) +
geom_point(
aes(x = year, y = change_e0),
size = 2, shape = 15, colour = "red",
data = dta_e0 %>%
filter(code == "GBRCENW") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015)
)
```
Now to show the distribution in comparison to 2014-15
```{r}
dta_e0 %>%
filter(code == "GBRCENW") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1955, 2014)) %>%
ggplot(aes(x = change_e0)) +
stat_density(alpha = 0.2) +
geom_rug() +
facet_grid(gender ~ .) +
geom_vline(xintercept = 0, size = 1.5) +
geom_vline(
aes(xintercept =change_e0),
data = dta_e0 %>%
filter(code == "GBRCENW") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015),
colour = "red",
linetype = "dashed"
) +
geom_vline(
aes(xintercept =mean_change_e0),
data = dta_e0 %>%
filter(code == "GBRCENW") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1955, 2014)) %>%
group_by(gender) %>%
summarise(mean_change_e0 = mean(change_e0)) %>%
ungroup(),
colour = "blue"
) +
labs(
title = "Range of falls and gains in annual life expectancy in England & Wales, 1955-2014",
x = "Change in life expectancy from previous year in years",
y = "Density of distribution of changes"
) +
geom_text(
aes(x = mean_change_e0), y = 0.75,
label = "Average\nChange", fontface = "bold", colour = "white",
nudge_y = 0.01, nudge_x = 0.0025,
data = dta_e0 %>%
filter(code == "GBRCENW") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1955, 2014)) %>%
group_by(gender) %>%
summarise(mean_change_e0 = mean(change_e0)) %>%
ungroup()
) +
geom_text(
aes(x = mean_change_e0), y = 0.75,
label = "Average\nChange", fontface = "bold",
data = dta_e0 %>%
filter(code == "GBRCENW") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1955, 2014)) %>%
group_by(gender) %>%
summarise(mean_change_e0 = mean(change_e0)) %>%
ungroup()
) +
geom_text(
aes(x = change_e0), y = 0.75,
label = "Change from\n2014-2015", fontface = "bold", colour = "white",
nudge_y = 0.01, nudge_x = 0.0025,
data = dta_e0 %>%
filter(code == "GBRCENW") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015)
) +
geom_text(
aes(x = change_e0), y = 0.75,
label = "Change from\n2014-2015", fontface = "bold",
data = dta_e0 %>%
filter(code == "GBRCENW") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015)
) +
geom_text(
aes(x = change_e0), y = 0.75,
label = "Change from\n2014-2015", fontface = "bold",
data = dta_e0 %>%
filter(code == "GBRCENW") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015)
) +
geom_text(
aes(x = change_e0, label = year), y = 0.1,
data = dta_e0 %>%
filter(code == "GBRCENW") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1955, 2014)) %>%
mutate(rank_ch = rank(change_e0)) %>%
filter(rank_ch <= 2 | rank_ch >= 59)
)
```
The 2014-15 fall looks to be a comparably rarer event for England & Wales than for Scotland. Let's quantify this
```{r}
summary_stats <- dta_e0 %>%
filter(code == "GBRCENW") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(between(year, 1955, 2014)) %>%
group_by(gender) %>%
summarise(
mean_ch_e0 = mean(change_e0),
sd_ch_e0 = sd(change_e0)
) %>%
ungroup()
summary_stats
```
And now the estimated probability/frequency
```{r}
summary_stats %>%
left_join(
dta_e0 %>%
filter(code == "GBRCENW") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
filter(year == 2015) %>%
select(gender, change_in_2015 = change_e0)
) %>%
mutate(
prob_2015_chance = pmap_dbl(
list(
q = change_in_2015,
mean = mean_ch_e0,
sd = sd_ch_e0
),
.f = pnorm
),
one_in = 1/ prob_2015_chance,
prob_no_improvovement = pmap_dbl(
list(
q = c(0,0),
mean = mean_ch_e0,
sd = sd_ch_e0
),
.f = pnorm
)
)
```
The initial visual impression, based largely on just counting the ticks to the left of the red dashed line, was a bit misleading.
The 2014-15 fall was a 1-in-27 year event (cf 1-in-16 for Scotland) for males, and a 1-in-42 year event (cf 1-in-60) for females.
# Appendix: visual exploration of 1 year and 2 year autocorrelation
This section will visually look at autocorrelation of 1 and 2 lags in Scotland, and England & Wales
```{r}
dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
mutate(lag_1 = lag(change_e0)) %>%
mutate(lag_2 = lag(change_e0, 2)) %>%
filter(between(year, 1955, 2014)) %>%
gather(key = "lag", value = "value", lag_1, lag_2) %>%
group_by(gender) %>%
ggplot(aes(x = change_e0, y = value)) +
geom_point() +
geom_smooth(method = "lm") +
facet_grid(lag ~ gender)
```
As might be expected, the autocorrelation with the previous year (`lag_1`) is stronger than the autocorrelation with two years previously (`lag_2`).
Let's quantify this
```{r}
dta_e0 %>%
filter(code == "GBR_SCO") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
mutate(lag_1 = lag(change_e0)) %>%
mutate(lag_2 = lag(change_e0, 2)) %>%
filter(between(year, 1955, 2014)) %>%
gather(key = "lag", value = "value", lag_1, lag_2) %>%
group_by(gender, lag) %>%
nest() %>%
mutate(corr = map_dbl(data, ~ cor(.x[,c("change_e0", "value")]) %>% .[2,1])) %>%
select(-data) %>%
spread(lag, corr)
```
So, the change over a year is autocorrelated with the previous year's change, and more weakly for two years' prior.
The autocorrelation to the previous year's change is -0.47 for females and -0.29 for males.
And now for England & Wales
```{r}
dta_e0 %>%
filter(code == "GBRCENW") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
mutate(lag_1 = lag(change_e0)) %>%
mutate(lag_2 = lag(change_e0, 2)) %>%
filter(between(year, 1955, 2014)) %>%
gather(key = "lag", value = "value", lag_1, lag_2) %>%
group_by(gender) %>%
ggplot(aes(x = change_e0, y = value)) +
geom_point() +
geom_smooth(method = "lm") +
facet_grid(lag ~ gender)
```
Lag-2 autocorrelation looks even weaker for England & Wales than for Scotland. Again, let's quantify this
```{r}
dta_e0 %>%
filter(code == "GBRCENW") %>%
filter(gender != "total") %>%
group_by(gender) %>%
arrange(year) %>%
mutate(change_e0 = e0 - lag(e0)) %>%
mutate(lag_1 = lag(change_e0)) %>%
mutate(lag_2 = lag(change_e0, 2)) %>%
filter(between(year, 1955, 2014)) %>%
gather(key = "lag", value = "value", lag_1, lag_2) %>%
group_by(gender, lag) %>%
nest() %>%
mutate(corr = map_dbl(data, ~ cor(.x[,c("change_e0", "value")]) %>% .[2,1])) %>%
select(-data) %>%
spread(lag, corr)
```
Pretty much no lag-2 autocorrelation.
But a very similar magnitude of lag-1 autocorrelation by sex as for Scotland.
# Additional data production
The aim of this section is to produce a dataset that can be visualised in Excel.
This dataset will show the change in e0 since 1955 for each country in the HMD.