-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrnotebook.Rmd
910 lines (745 loc) · 30.5 KB
/
rnotebook.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
---
title: "Vaccination rates - data exploration"
subtitle: "Everything here is exploratory and only content in the [article](https://www.nzherald.co.nz/nz/news/article.cfm?c_id=1&objectid=12250703) should be regarded as final"
author: "Chris Knox"
date: "`r Sys.Date()`"
output:
tint::tintHtml:
toc: true
toc_depth: 2
number_sections: true
includes:
in_header:
- og.html
- twitter.html
---
```{r setup, include=FALSE}
library(tint)
library(tidyverse)
library(ggthemes)
library(knitr)
library(scales)
library(r2d3)
library(ggrepel)
library(sf)
# invalidate cache when the package version changes
knitr::opts_chunk$set(tidy = FALSE,
cache.extra = packageVersion('tint'),
cache = TRUE,
autodep = TRUE,
echo = FALSE,
message = FALSE,
error = FALSE,
warning = FALSE
)
options(htmltools.dir.version = FALSE)
drake::r_make()
vaccinations <- drake::readd(oia_data)
vaccinations_geo <- drake::readd(oia_data_geo)
dom <- drake::readd(whole_dom)
```
# Introduction
This is the working document for a New Zealand Herald investigation of vaccination rates in New
Zealand - the final article is [here](https://www.nzherald.co.nz/nz/news/article.cfm?c_id=1&objectid=12250703)
and the source code is [here](https://github.com/nzherald/vaccination-rates)
This document has been released largely as-is and hopefully will provide some insight into and
transparency for the numerical aspects of the investigation. If you have any questions or comments
please get in touch with Chris Knox - https://twitter.com/vizowl or chris.knox@nzherald.co.nz
The document was created iteratively via duscussion between Kirsty Johnston
(https://twitter.com/kirsty_johnston) and Chris Knox as we tried to understand the data.
The [source code](https://github.com/nzherald/vaccination-rates/blob/master/rnotebook.Rmd) may
be more informative our intent than this document.
The source code for the analysis and interactive is open source. Although, if you use
it we would appreciate it if you could acknowledge the New Zealand Herald.
## Data
Immunisation data came from the Ministry of Health's [reporting](https://www.health.govt.nz/our-work/preventative-health-wellness/immunisation/immunisation-coverage/national-and-dhb-immunisation-data)
and from data released to the New Zealand Herald under the Official Information Act (OIA). The OIA'd
data is a breakdown of vaccination rates by Health Domicile - Health Domiciles are loosely similar
to suburbs.
This analysis is used data from StatsNZ - specifically area unit boundaries and geographic area
concordances.
All the government data is Crown Copyright released under a [creative commons licence](https://creativecommons.org/licenses/by/4.0/).
## Interactive
The charts were made as a simple [react](https://reactjs.org/) using the excellent
[semiotic](https://semiotic.nteract.io/) visualisation library.
# Data from immunisation coverage reports
```{r,fig.fullwidth=T,fig.width=10,fig.height=10}
reports <- drake::readd(reports)
ggplot(reports %>%
filter(Measure=='Percentage',
Breakdown=='Ethnicity',
Category != 'Dep Unknown',
DHB=='National'), aes(x=Quarter,y=Value,color=Category)) +
geom_line() +
facet_wrap(. ~ Milestone) +
scale_color_brewer(palette='RdYlGn', direction=-1, name="Deprivation") +
theme_fivethirtyeight() +
labs(title="National vaccination milestones by ethnicity")
```
```{r,fig.fullwidth=T,fig.width=10,fig.height=10}
ggplot(reports %>%
filter(Measure=='Percentage',
Breakdown=='Deprivation',
Category != 'Dep Unknown',
DHB=='National'), aes(x=Quarter,y=Value,color=Category)) +
geom_line() +
facet_wrap(. ~ Milestone) +
scale_color_brewer(palette='RdYlGn', direction=-1, name="Deprivation") +
theme_fivethirtyeight() +
labs(title="National vaccination milestones by deprivation")
```
## Explore
```{r}
m6 <- drake::readd(month6)
m12 <- drake::readd(month12)
m18 <- drake::readd(month18)
m24 <- drake::readd(month24)
m60 <- drake::readd(month60)
worst6 <- top_n(m6, -1, Rate)
overall <- drake::readd(overall18) %>% ungroup
worstO <- top_n(overall, -1, Rate)
```
The worst vaccination rate at 6 months is `r percent(worst6 %>% pull(Rate))` in
`r worst6 %>% pull(DOMICILE_NAME)` which is in `r worst6 %>% pull(DHB_NAME)`.
The worst overall (which might not mean anything) vaccination rate is `r percent(worstO %>% pull(Rate))` in
`r worstO %>% pull(DOMICILE_NAME)` which is in `r worstO %>% pull(DHB_NAME)`.
Well that isn't so surprising - let's look at the worst 10.
```{r}
kable(top_n(m6, -10, Rate) %>% arrange(Rate) %>%
select(DHB_NAME, DOMICILE_NAME, NUMBER_ELIGIBLE, Dep=CAU_average_NZDep2013, Rate),
caption="The worst 10 domiciles at 6 months in 2018")
```
and overall.
```{r}
kable(top_n(overall, -10, Rate) %>% arrange(Rate) %>%
select(DHB_NAME, DOMICILE_NAME, Dep=CAU_average_NZDep2013, Rate),
caption="The worst 10 domiciles overall in 2018")
```
Let's use the score not the deciles.
```{r}
ggplot(m6, aes(x=CAU_average_NZDep_score_2013,y=Rate)) +
geom_point() +
geom_smooth() +
theme_fivethirtyeight() +
labs(title = "Deprivation versus 6 month vaccination rates", subtitle="Points are domiciles") +
scale_y_continuous(labels=percent)
```
How does it look by DHB
```{r,fig.fullwidth=T,fig.width=10,fig.height=14}
ggplot(m6, aes(x=CAU_average_NZDep_score_2013,y=Rate)) +
geom_point() +
geom_smooth() +
theme_fivethirtyeight() +
labs(title = "Deprivation versus 6 month vaccination rates", subtitle="Points are domiciles") +
scale_y_continuous(labels=percent,limits=c(0.5,1)) +
facet_wrap(. ~ DHB_NAME, ncol=4)
```
Most of Auckland is better than most of Bay of Plenty.
How does it look at 12 months?
```{r,fig.fullwidth=T,fig.width=10,fig.height=14}
ggplot(m12, aes(x=CAU_average_NZDep_score_2013,y=Rate)) +
geom_point() +
geom_smooth() +
theme_fivethirtyeight() +
labs(title = "Deprivation versus 12 month vaccination rates", subtitle="Points are domiciles") +
scale_y_continuous(labels=percent,limits=c(0.5,1)) +
facet_wrap(. ~ DHB_NAME, ncol=4)
```
```{r,fig.fullwidth=T,fig.width=10,fig.height=14}
ggplot(m18, aes(x=CAU_average_NZDep_score_2013,y=Rate)) +
geom_point() +
geom_smooth() +
theme_fivethirtyeight() +
labs(title = "Deprivation versus 18 month vaccination rates", subtitle="Points are domiciles") +
scale_y_continuous(labels=percent,limits=c(0.5,1)) +
facet_wrap(. ~ DHB_NAME, ncol=4)
```
```{r,fig.fullwidth=T,fig.width=10,fig.height=14}
ggplot(m24, aes(x=CAU_average_NZDep_score_2013,y=Rate)) +
geom_point() +
geom_smooth() +
theme_fivethirtyeight() +
labs(title = "Deprivation versus 24 month vaccination rates", subtitle="Points are domiciles") +
scale_y_continuous(labels=percent,limits=c(0.5,1)) +
facet_wrap(. ~ DHB_NAME, ncol=4)
```
```{r,fig.fullwidth=T,fig.width=10,fig.height=14}
ggplot(m60, aes(x=CAU_average_NZDep_score_2013,y=Rate)) +
geom_point() +
geom_smooth() +
theme_fivethirtyeight() +
labs(title = "Deprivation versus 60 month vaccination rates", subtitle="Points are domiciles") +
scale_y_continuous(labels=percent,limits=c(0.5,1)) +
facet_wrap(. ~ DHB_NAME, ncol=4)
```
## Trends by deprivation
```{r}
ggplot(vaccinations %>%
filter(AGE_IN_MONTHS == 6) %>%
group_by(CAU_average_NZDep2013, MILESTONE_YEAR) %>%
summarise(Rate=sum(NUMBER_FULLY_IMMUNISED)/sum(NUMBER_ELIGIBLE)),
aes(x=MILESTONE_YEAR,y=Rate,color=coalesce(str_pad(CAU_average_NZDep2013, 2, pad='0'),'??'))) +
geom_line() +
scale_color_brewer(palette='RdYlGn', direction=-1, name="Deprivation") +
theme_fivethirtyeight() +
labs(title="6 month vaccination rates by deprivation")
```
```{r}
ggplot(vaccinations %>%
filter(AGE_IN_MONTHS == 12) %>%
group_by(CAU_average_NZDep2013, MILESTONE_YEAR) %>%
summarise(Rate=sum(NUMBER_FULLY_IMMUNISED)/sum(NUMBER_ELIGIBLE)),
aes(x=MILESTONE_YEAR,y=Rate,color=coalesce(str_pad(CAU_average_NZDep2013, 2, pad='0'),'??'))) +
geom_line() +
scale_color_brewer(palette='RdYlGn', direction=-1, name="Deprivation") +
theme_fivethirtyeight() +
labs(title="12 month vaccination rates by deprivation")
```
So it looks like drop-off is definitely occurring in more deprived areas. And
# Load the data
## The data
The data covered the number of children who are vaccinated to each of the vaccination milestone by
health domicle and year.
It was provided by the Ministry of Health under the Official Information Act, as a spreadsheet with
68,385 rows and 8 columns. The columns are:
- **DHB_CODE**
- **DHB_NAME**
- **DOMICILE_CODE**
- **DOMICILE_NAME**
- **AGE_IN_MONTHS** - the age for each milestone
- **MILESTONE_YEAR** - the year the milestone
- **NUMBER_ELIGIBLE** - the number of children within the milestone age range
- **NUMBER_FULLY_IMMUNISED**
If there are less than ten eligible children in a domicile in a given year they have been aggregated
with other small domiciles in the DHB.
I haved used Stats NZ geographic areas data to match domicile codes
to 2013 area units and then too Otago's deprivation index data.
### Initial look
Calculate an overall rate for every domicile - this probably isn't something we
would use later - it is the average rate across all milestone ages and years.
```{r,fig.fullwidth=T,fig.width=10}
drake::readd(initialPlot1)
```
The scatter to the left and right around the individual deciles does not mean anything.
It is just _jitter_ that is randomly introduced to make it easier to read.
```{r,fig.fullwidth=T,fig.width=10,fig.height=20}
drake::readd(initialPlot2)
```
```{r,fig.height=20,fig.fullwidth=T,fig.width=10}
drake::readd(fitted_facets)
```
How does ethnicity effect things?
```{r}
ethnicity <- tbl(con, "census") %>% collect() %>%
left_join(dom, by=c("code"="AU2013_code"))
ggplot(ethnicity, aes(x=Rate,y=maori,color=CAU_average_NZDep2013)) +
geom_point()
```
Graphically I would have to say it doesn't ...
# For Emma
## National chart
```{r}
ggplot(reports %>% filter(DHB=='National',Measure=="Percentage",Category=="Total"),
aes(x=Quarter,y=Value, color=Milestone)) +
geom_line() +
scale_color_brewer(palette='Dark2', direction=-1) +
theme_fivethirtyeight() +
labs(title="New Zealand Immunisation Rates", subtitle="By Milestone Age") +
scale_y_continuous(labels=percent) +
ggsave('nz-immunisation.png')
```
# More questions
## Dropoff by DHB
### 6 Months
```{r}
dhb_total <- reports %>%
filter(Measure=='Percentage',Category=="Total",Breakdown=='Ethnicity')
dhbNow <- dhb_total %>%
filter(Quarter=='2019-03-01') %>%
select(DHB,Milestone,Now=Value)
dropoffs <- dhb_total %>%
group_by(DHB, Milestone) %>%
summarise(Max=max(Value,na.rm=T)) %>%
ungroup() %>%
inner_join(dhb_total %>% select(DHB, Milestone, Quarter, Value),
by=c("DHB","Milestone","Max"="Value")) %>%
group_by(DHB,Milestone,Max) %>%
summarise(`Best Quarter`=max(Quarter)) %>%
inner_join(dhbNow, by=c("DHB","Milestone")) %>%
mutate(Drop=Now-Max) %>%
ungroup()
kable(dropoffs %>% filter(Milestone == '06 months') %>%
arrange(Drop) %>%
select(-Milestone) %>%
mutate(Drop=percent(Drop),
Max=percent(Max),
Now=percent(Now)),
caption="Drop from each DHB's best 6 month immunisation rate until now")
```
### 8 Months
```{r}
kable(dropoffs %>% filter(Milestone == '08 months') %>%
arrange(Drop) %>%
select(-Milestone) %>%
mutate(Drop=percent(Drop),
Max=percent(Max),
Now=percent(Now)),
caption="Drop from each DHB's best 8 month immunisation rate until now")
```
### 12 Months
```{r}
kable(dropoffs %>% filter(Milestone == '12 months') %>%
arrange(Drop) %>%
select(-Milestone) %>%
mutate(Drop=percent(Drop),
Max=percent(Max),
Now=percent(Now)),
caption="Drop from each DHB's best 12 month immunisation rate until now")
```
## Dropoff by DHB and Ethnicity
### 6 Months
```{r}
dhb_total_eth <- reports %>%
filter(Measure=='Percentage',Category != "Total",Breakdown=='Ethnicity')
dhbNow_eth <- dhb_total_eth %>%
filter(Quarter=='2019-03-01') %>%
select(DHB,Milestone,Now=Value,Category)
dropoffs_eth <- dhb_total_eth %>%
group_by(DHB, Milestone,Category) %>%
summarise(Max=max(Value,na.rm=T)) %>%
ungroup() %>%
inner_join(dhb_total_eth %>% select(DHB, Milestone, Quarter, Value,Category),
by=c("DHB","Milestone","Max"="Value","Category")) %>%
group_by(DHB,Milestone,Max,Category) %>%
summarise(`Best Quarter`=max(Quarter)) %>%
inner_join(dhbNow_eth, by=c("DHB","Milestone","Category")) %>%
mutate(Drop=Now-Max) %>%
ungroup()
kable(spread(dropoffs_eth %>%
filter(Milestone=='06 months') %>%
select(DHB,Drop,Category), Category, Drop) %>%
arrange(Māori) %>%
mutate(Asian=percent(Asian),
Māori=percent(Māori),
Pākehā=percent(Pākehā),
Other=percent(Other),
Pacific=percent(Pacific)),
caption="Drop by ethnicity from each DHB's best 6 month immunisation rate until now")
```
### 8 Months
```{r}
kable(spread(dropoffs_eth %>%
filter(Milestone=='08 months') %>%
select(DHB,Drop,Category), Category, Drop) %>%
arrange(Māori) %>%
mutate(Asian=percent(Asian),
Māori=percent(Māori),
Pākehā=percent(Pākehā),
Other=percent(Other),
Pacific=percent(Pacific)),
caption="Drop by ethnicity from each DHB's best 8 month immunisation rate until now")
```
### 12 Months
```{r}
kable(spread(dropoffs_eth %>%
filter(Milestone=='12 months') %>%
select(DHB,Drop,Category), Category, Drop) %>%
arrange(Māori) %>%
mutate(Asian=percent(Asian),
Māori=percent(Māori),
Pākehā=percent(Pākehā),
Other=percent(Other),
Pacific=percent(Pacific)),
caption="Drop by ethnicity from each DHB's best 12 month immunisation rate until now")
```
## Dropoff by DHB and Deprivation
### 6 Months
```{r}
dhb_total_dep <- reports %>%
filter(Measure=='Percentage',Breakdown=='Deprivation')
dhbNow_dep <- dhb_total_dep %>%
filter(Quarter=='2019-03-01') %>%
select(DHB,Milestone,Now=Value,Category)
dropoffs_dep <- dhb_total_dep %>%
group_by(DHB, Milestone,Category) %>%
summarise(Max=max(Value,na.rm=T)) %>%
ungroup() %>%
inner_join(dhb_total_dep %>% select(DHB, Milestone, Quarter, Value,Category),
by=c("DHB","Milestone","Max"="Value","Category")) %>%
group_by(DHB,Milestone,Max,Category) %>%
summarise(`Best Quarter`=max(Quarter)) %>%
inner_join(dhbNow_dep, by=c("DHB","Milestone","Category")) %>%
mutate(Drop=Now-Max) %>%
ungroup()
kable(spread(dropoffs_dep %>%
filter(Milestone=='06 months') %>%
select(DHB,Drop,Category), Category, Drop) %>%
arrange(`Dep 9-10`) %>%
mutate(`Dep 1-2`=percent(`Dep 1-2`),
`Dep 3-4`=percent(`Dep 3-4`),
`Dep 5-6`=percent(`Dep 5-6`),
`Dep 7-8`=percent(`Dep 7-8`),
`Dep 9-10`=percent(`Dep 9-10`),
`Dep Unknown`=percent(`Dep Unknown`)),
caption="Drop by deprivation from each DHB's best 6 month immunisation rate until now")
```
### 8 Months
```{r}
kable(spread(dropoffs_dep %>%
filter(Milestone=='08 months') %>%
select(DHB,Drop,Category), Category, Drop) %>%
arrange(`Dep 9-10`) %>%
mutate(`Dep 1-2`=percent(`Dep 1-2`),
`Dep 3-4`=percent(`Dep 3-4`),
`Dep 5-6`=percent(`Dep 5-6`),
`Dep 7-8`=percent(`Dep 7-8`),
`Dep 9-10`=percent(`Dep 9-10`),
`Dep Unknown`=percent(`Dep Unknown`)
),
caption="Drop by deprivation from each DHB's best 8 month immunisation rate until now")
```
### 12 Months
```{r}
kable(spread(dropoffs_dep %>%
filter(Milestone=='12 months') %>%
select(DHB,Drop,Category), Category, Drop) %>%
arrange(`Dep 9-10`) %>%
mutate(`Dep 1-2`=percent(`Dep 1-2`),
`Dep 3-4`=percent(`Dep 3-4`),
`Dep 5-6`=percent(`Dep 5-6`),
`Dep 7-8`=percent(`Dep 7-8`),
`Dep 9-10`=percent(`Dep 9-10`),
`Dep Unknown`=percent(`Dep Unknown`)),
caption="Drop by deprivation from each DHB's best 12 month immunisation rate until now")
```
# Comparisons
## Domicile's reaching 95%
What percentage of domicile's reach 95% vaccination by 12 months
```{r}
target12 <- m12 %>% count(DHB_NAME) %>%
left_join(m12 %>% filter(Rate >= 0.95) %>% count(DHB_NAME),
by="DHB_NAME") %>%
mutate(Frac=n.y/n.x) %>%
select(-n.x,-n.y) %>%
arrange(Frac)
kable(target12 %>% mutate(Frac=percent(Frac)), caption = "Percentage of Domiciles that reach 95% by 12 months")
```
What are the characteristics of those domiciles?
```{r}
characteristics <- m12 %>%
group_by(DHB_NAME) %>%
summarise(DHB.DepScore=mean(CAU_average_NZDep_score_2013, na.rm=T),
DHB.Size=mean(NUMBER_ELIGIBLE), DHB.Children =sum(NUMBER_ELIGIBLE))
missed_target12 <- m12 %>%
filter(Rate < 0.95) %>%
group_by(DHB_NAME) %>%
summarise(Under.DepScore=mean(CAU_average_NZDep_score_2013, na.rm=T),
Under.Size=mean(NUMBER_ELIGIBLE),
Under.Children=sum(NUMBER_ELIGIBLE))
target12char <- characteristics %>%
inner_join(m12 %>%
filter(Rate >= 0.95) %>%
group_by(DHB_NAME) %>%
summarise(DepScore=mean(CAU_average_NZDep_score_2013, na.rm=T),
Size=mean(NUMBER_ELIGIBLE),
Children=sum(NUMBER_ELIGIBLE)),
by = "DHB_NAME")
kable(characteristics %>% left_join(target12char, by="DHB_NAME") %>% arrange(DepScore))
kable(target12char)
```
Let's plot % target reached vs difference in deprivation score for those that reach the target
and those that don't
```{r}
ggplot(missed_target12 %>% left_join(target12char, by="DHB_NAME") %>%
left_join(target12, by="DHB_NAME"),
aes(x=DepScore-Under.DepScore,y=Frac)) +
geom_point() +
geom_text(aes(label=DHB_NAME),vjust=1.2) +
theme_fivethirtyeight() +
scale_y_continuous(labels=percent) +
labs(title="Percentage of domiciles reaching target",
subtitle="Versus the difference in DepScore")
ggsave('clusters.png')
```
Do the same plot but versus percentage of children - not domiciles.
```{r}
ggplot(missed_target12 %>% left_join(target12char, by="DHB_NAME") %>%
left_join(target12, by="DHB_NAME"),
aes(x=DepScore-Under.DepScore,y=Children/DHB.Children,label=paste(DHB_NAME,comma(DHB.Children-Children)))) +
geom_point(colour="red") +
theme_fivethirtyeight() +
scale_y_continuous(labels=percent) +
labs(title="Deprivation versus Vaccination",
subtitle="Percentage of children fully vaccinated at 12 months versus the difference
in deprivation for target reaching and not-reaching areas",
caption="Labels include number of children living in domiciles that haven't reached the target.") +
geom_text_repel()
ggsave('clusters2.png')
```
Let's look at the averages for the acheived and failed domiciles by DHB
```{r,fig.height=12}
af <- missed_target12 %>%
left_join(target12char, by="DHB_NAME") %>%
left_join(target12, by="DHB_NAME") %>%
mutate(Achieved=Children/DHB.Children,Failed=Under.Children/DHB.Children) %>%
select(DHB_NAME,Achieved,DepScore,Under.DepScore) %>%
gather(Deprivation, Value, -Achieved, -DHB_NAME) %>%
mutate(Status=case_when(Deprivation=="DepScore" ~ "Achieved", TRUE ~ "Not Achieved"),
Children=case_when(Deprivation=="DepScore" ~ Achieved, TRUE ~ 1-Achieved),
Deprivation=Value) %>%
select(-Value,-Achieved)
ggplot(af,
aes(x=Deprivation,y=Children,label=DHB_NAME)) +
geom_point(aes(color=Status)) +
geom_line(aes(group=DHB_NAME)) +
theme_fivethirtyeight() +
scale_y_continuous(labels=percent) +
labs(title="Deprivation versus Vaccination",
subtitle="Percentage of children fully vaccinated at 12 months versus the difference
in deprivation for target reaching and not-reaching areas",
caption="Labels include number of children living in domiciles that haven't reached the target.") +
facet_wrap(. ~ DHB_NAME)
ggsave('clusters3.png', height=12)
```
What do these look like at 6 months?
```{r}
target6 <- m6 %>% count(DHB_NAME) %>%
left_join(m6 %>% filter(Rate >= 0.95) %>% count(DHB_NAME),
by="DHB_NAME") %>%
mutate(Frac=n.y/n.x) %>%
select(-n.x,-n.y) %>%
arrange(Frac)
characteristics6 <- m6 %>%
group_by(DHB_NAME) %>%
summarise(DHB.DepScore=mean(CAU_average_NZDep_score_2013, na.rm=T),
DHB.Size=mean(NUMBER_ELIGIBLE), DHB.Children =sum(NUMBER_ELIGIBLE))
missed_target6 <- m6 %>%
filter(Rate < 0.95) %>%
group_by(DHB_NAME) %>%
summarise(Under.DepScore=mean(CAU_average_NZDep_score_2013, na.rm=T),
Under.Size=mean(NUMBER_ELIGIBLE),
Under.Children=sum(NUMBER_ELIGIBLE))
target6char <- characteristics6 %>%
left_join(m6 %>%
filter(Rate >= 0.95) %>%
group_by(DHB_NAME) %>%
summarise(DepScore=mean(CAU_average_NZDep_score_2013, na.rm=T),
Size=mean(NUMBER_ELIGIBLE),
Children=sum(NUMBER_ELIGIBLE)),
by = "DHB_NAME")
```
```{r}
ggplot(missed_target6 %>% left_join(target6char, by="DHB_NAME") %>%
left_join(target6, by="DHB_NAME") %>%
filter(DHB_NAME != "Overseas and undefined"),
aes(x=coalesce(DepScore-Under.DepScore,0),y=coalesce(Children/DHB.Children,0),label=paste(DHB_NAME,comma(DHB.Children-coalesce(Children,0))))) +
geom_point(colour="red") +
theme_fivethirtyeight() +
scale_y_continuous(labels=percent, limits=c(-0.02,0.1)) +
labs(title="Deprivation versus Vaccination",
subtitle="Percentage of children fully vaccinated at 6 months versus the difference
in deprivation for target reaching and not-reaching areas",
caption="Labels include number of children living in domiciles that haven't reached the target.") +
geom_text_repel()
ggsave('clusters4.png')
```
# Population denisty
```{r,fig.fullwidth=T,fig.width=10,fig.height=14}
dp <- ggplot(vaccinations_geo %>% filter(AGE_IN_MONTHS==6),
aes(x=log(NUMBER_ELIGIBLE/AREA_SQ_KM),y=NUMBER_FULLY_IMMUNISED/NUMBER_ELIGIBLE,color=CAU_average_NZDep_score_2013)) +
facet_wrap(. ~ DHB_NAME) +
scale_color_viridis_c(option="C",direction=-1,position="bottom")
dp + geom_point()
ggsave('density.png', plot=dp+theme(legend.position="none")+geom_point(size=0.5),width=6,height=3.35,dpi=100)
```
It does not look like population density (which I think is an OK proxy for remoteness is a factor).
```{r}
missing <- reports %>% filter(Milestone=='06 months',Category=='Total',DHB=='National',Measure!='Percentage') %>% spread(Measure,Value) %>% mutate(Missing=Eligible-Immunised)
small_areas6nz <- vaccinations %>% filter(str_detect(DOMICILE_NAME, 'other domiciles'), AGE_IN_MONTHS==6) %>% group_by(MILESTONE_YEAR) %>% summarise(Total=sum(NUMBER_ELIGIBLE), Missed=sum(NUMBER_ELIGIBLE)-sum(NUMBER_FULLY_IMMUNISED))
```
# Maps
```{r}
vaccinations_geo <- vaccinations_geo %>%
filter(AGE_IN_MONTHS==6,MILESTONE_YEAR==2016) %>%
mutate(OK=case_when(NUMBER_FULLY_IMMUNISED/NUMBER_ELIGIBLE >= 0.75 ~ 'Yes', TRUE ~ 'No'))
ggplot(vaccinations_geo %>% filter(DHB_NAME=='Bay of Plenty'),
aes(geometry=geometry,fill=OK)) +
geom_sf() +
scale_fill_viridis_d(option='C',name="Rate") +
theme_map() +
labs(subtitle="Bay of Plenty at 6 months", title="75% of children vaccinated")
```
```{r}
ggplot(vaccinations_geo %>% filter(DHB_NAME=='Counties Manukau'),
aes(geometry=geometry,fill=OK)) +
geom_sf() +
scale_fill_viridis_d(option='C',name="Rate") +
theme_map() +
labs(subtitle="Counties Manukau at 6 months", title="75% of children vaccinated")
```
```{r}
ggplot(vaccinations_geo %>% filter(DHB_NAME=='Waikato'),
aes(geometry=geometry,fill=OK)) +
geom_sf() +
scale_fill_viridis_d(option='C',name="Rate") +
theme_map() +
labs(subtitle="Waikato at 6 months", title="75% of children vaccinated")
```
```{r}
ggplot(vaccinations_geo %>% filter(DHB_NAME=='Northland'),
aes(geometry=geometry,fill=OK)) +
geom_sf() +
scale_fill_viridis_d(option='C',name="Rate") +
theme_map() +
labs(subtitle="Northland at 6 months", title="75% of children vaccinated")
```
# Numbers
## What is the difference between December 2015 and now?
670 kids - that is all that are missing.
Peak 6 month overall rate was 82% - now it is 77%. In the most recent quarter there were
14745 kids - so vaccinating 670 more would get to 82%.
## Demographics of drop.
Deprivation
```{r}
mdall6 <- reports %>%
filter(Breakdown=='Deprivation', Milestone=='06 months',DHB=='National')
kable(mdall6 %>%
filter(Measure=="Percentage",Quarter=="2015-12-01") %>%
select(Category, Value) %>%
inner_join(mdall6 %>%
filter(Measure=="Percentage",Quarter=="2019-03-01") %>%
select(Category, Value), by="Category") %>%
mutate(Drop=Value.x-Value.y) %>%
inner_join(mdall6 %>%
filter(Measure=="Eligible",Quarter=="2015-12-01") %>%
select(Category, Value), by="Category") %>%
mutate(Lost=round(Value*Drop)) %>%
mutate(Drop=round(Drop*100,2),`Dec 2015`=percent(Value.x),`Mar 2019`=percent(Value.y)) %>%
select(-Value.x,-Value.y) %>%
rename(Eligible=Value),
caption="Additional number of children that would have been vaccinated at 6 months in March this
year if vaccination rate was the same as Dec 2015", align=c('l', rep('r',5)))
```
Ethnicity
```{r}
meall6 <- reports %>%
filter(Breakdown=='Ethnicity', Milestone=='06 months',DHB=='National')
kable(meall6 %>%
filter(Measure=="Percentage",Quarter=="2015-12-01") %>%
select(Category, Value) %>%
inner_join(meall6 %>%
filter(Measure=="Percentage",Quarter=="2019-03-01") %>%
select(Category, Value), by="Category") %>%
mutate(Drop=Value.x-Value.y) %>%
inner_join(meall6 %>%
filter(Measure=="Eligible",Quarter=="2015-12-01") %>%
select(Category, Value), by="Category") %>%
mutate(Lost=round(Value*Drop)) %>%
mutate(Drop=round(Drop*100,2),`Dec 2015`=percent(Value.x),`Mar 2019`=percent(Value.y)) %>%
select(-Value.x,-Value.y) %>%
rename(Eligible=Value),
caption="Additional number of children that would have been vaccinated at 6 months in March this
year if vaccination rate was the same as Dec 2015", align=c('l', rep('r',5)))
```
# DHB Numbers
Deprivation
```{r}
mdall6 <- reports %>%
filter(Breakdown=='Deprivation', Milestone=='06 months',DHB != 'National')
kable(mdall6 %>%
filter(Measure=="Percentage",Quarter=="2015-12-01") %>%
select(Category, Value, DHB) %>%
inner_join(mdall6 %>%
filter(Measure=="Percentage",Quarter=="2019-03-01") %>%
select(Category, Value, DHB), by=c("Category","DHB")) %>%
mutate(Drop=Value.x-Value.y) %>%
inner_join(mdall6 %>%
filter(Measure=="Eligible",Quarter=="2015-12-01") %>%
select(Category, Value, DHB), by=c("Category","DHB")) %>%
mutate(Lost=round(Value*Drop)) %>%
mutate(Drop=round(Drop*100,2),`Dec 2015`=percent(Value.x),`Mar 2019`=percent(Value.y)) %>%
select(-Value.x,-Value.y) %>%
rename(Eligible=Value) %>%
arrange(DHB, Category),
caption="Additional number of children that would have been vaccinated at 6 months in March this
year if vaccination rate was the same as Dec 2015", align=c('l', rep('r',5)))
```
Ethnicity
```{r}
mdall6 <- reports %>%
filter(Breakdown=='Ethnicity', Milestone=='06 months',DHB != 'National')
kable(mdall6 %>%
filter(Measure=="Percentage",Quarter=="2015-12-01") %>%
select(Category, Value, DHB) %>%
inner_join(mdall6 %>%
filter(Measure=="Percentage",Quarter=="2019-03-01") %>%
select(Category, Value, DHB), by=c("Category","DHB")) %>%
mutate(Drop=Value.x-Value.y) %>%
inner_join(mdall6 %>%
filter(Measure=="Eligible",Quarter=="2015-12-01") %>%
select(Category, Value, DHB), by=c("Category","DHB")) %>%
mutate(Lost=round(Value*Drop)) %>%
mutate(Drop=round(Drop*100,2),`Dec 2015`=percent(Value.x),`Mar 2019`=percent(Value.y)) %>%
select(-Value.x,-Value.y) %>%
rename(Eligible=Value) %>%
arrange(Category, DHB),
caption="Additional number of children that would have been vaccinated at 6 months in March this
year if vaccination rate was the same as Dec 2015", align=c('l', rep('r',5)))
```
# Final charts
```{r}
ggplot(reports %>%
filter(Milestone=='06 months',
Measure=='Percentage',
Breakdown=='Deprivation',
Category != 'Dep Unknown',
DHB=='National'), aes(x=Quarter,y=Value,color=Category)) +
geom_line() +
facet_wrap(. ~ Milestone) +
scale_y_continuous(labels=percent) +
scale_color_brewer(palette='RdYlGn', direction=-1, name="Deprivation") +
theme_fivethirtyeight() +
labs(title="Fully vaccinated six month olds")
ggsave('deprivation.svg')
```
```{r}
ggplot(reports %>%
filter(Milestone=='06 months',
Measure=='Percentage',
Breakdown=='Ethnicity',
DHB=='National'), aes(x=Quarter,y=Value,color=Category)) +
geom_line() +
facet_wrap(. ~ Milestone) +
scale_y_continuous(labels=percent) +
scale_color_brewer(palette='RdYlGn', direction=-1, name="Ethnicity") +
theme_fivethirtyeight() +
labs(title="Fully vaccinated six month olds")
ggsave('ethnicity.svg')
```
```{r}
ggplot(reports %>%
filter(Milestone=='06 months',
Measure=='Percentage',
Breakdown=='Ethnicity',
Category == 'Total',
DHB=='National'), aes(x=Quarter,y=Value,color=Category)) +
geom_line() +
facet_wrap(. ~ Milestone) +
scale_y_continuous(labels=percent) +
scale_color_brewer(palette='RdYlGn', direction=-1) +
theme_fivethirtyeight() +
theme(legend.position="none") +
labs(title="Fully vaccinated six month olds")
ggsave('total.svg')
```
```{r}
headR::add_og_card(card_type = "website",
title = "Vaccination rates - data exploration",
image = "https://nzherald.github.io/vaccination-rates/density.png",
url = "https://nzherald.github.io/vaccination-rates/",
description = "Data used for a New Zealand Herald investigation of vaccination rates",
file = "og.html")
headR::add_twitter_card(title = "Vaccination rates - data exploration",
file = "twitter.html",
image = "https://nzherald.github.io/vaccination-rates/density.png")
```