-
Notifications
You must be signed in to change notification settings - Fork 2
/
takeup_analysis2.Rmd
2141 lines (1805 loc) · 86.2 KB
/
takeup_analysis2.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: "TakeUp Analysis Notebook"
author:
- Anne Karing^[University of California Berkeley]
- Karim Naguib^[Evidence Action]
output:
html_notebook:
fig_align: "center"
fig_caption: yes
fig_height: 5
fig_width: 8
number_sections: yes
theme: flatly
toc: yes
toc_float:
collapsed: false
smooth_scroll: false
toc_depth: 5
header-includes:
- \usepackage{bbm}
date: "`r format(Sys.time(), '%B %d, %Y')`"
---
```{r, echo=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
```{r setup, include=FALSE}
library(magrittr)
library(plyr)
library(tidyverse)
# library(multidplyr)
library(lubridate)
library(forcats)
library(haven)
library(lmtest)
library(car)
library(mlogit)
library(broom)
library(ggrepel)
library(sp)
library(rgeos)
library(ggmap)
library(knitr)
library(econometr)
source("takeup_rct_assign_clusters.R")
source("analysis_util.R")
knitr::read_chunk("analysis_util.R", labels = "analysis-util")
config <- yaml::yaml.load_file("../local_config.yaml")
doParallel::registerDoParallel(cores = config$cores)
wgs.84 <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
kenya.proj4 <- "+proj=utm +zone=36 +south +ellps=clrk80 +units=m +no_defs"
do.neyman.analysis <- TRUE
options(dplyr.show_progress = FALSE, digits = 4)
```
# Data
```{r load-data, include=FALSE}
load(file.path("data", "analysis.RData"))
load(file.path("data", "mht_results.RData"))
```
These are the _monitored_: baseline and endline survey respondents, as well as a sample of people from whom we received reconsent without surveying.
```{r, results='asis', eval=FALSE}
census.data %>%
filter(!is.na(wave), # Actually in the study (not in one of the dropped clusters)
monitored) %>% {
count(., endline.type) %>% kable %>% print
filter(., is.na(endline.type)) %>% count(hh.baseline.sample.pool)
} %>%
kable
```
~~Below is the name matching code. We are using this function to identify individuals in a census who received treatment in their cluster's point-of-treatment and were not recorded by enumerators during their take-up monitoring. This is necessary to estimate take-up for non-phone owners, who were not included in the monitoring list provided to enumerators, in four of the six experiment strata (wave 1).~~ (Moved to external script).
We consider two individuals (in the take-up and census data) to be matched if the sum of edit (Levenshtein) distances of the first and last names is less than or equal to 1.
Below we are linking the consent, census (including take-up status), and endline data to generate the analysis data set. At this stage, we are including everyone in the census--the entire cluster populations. For our analysis, we will filter on consent. (Code moved to separate script).
```{r outliers-plot, echo=FALSE, fig.width=12, fig.height=10}
# bind_rows(monitored = cluster.takeup.data, all = unmonitored.cluster.takeup.data, .id = "monitored.sample") %>%
# ggplot(aes(stratum, takeup.prop, color = monitored.sample)) +
# geom_boxplot() + #aes(color = assigned.treatment)) +
# geom_text_repel(aes(label = cluster.id), data = . %>% filter(outlier)) +
# xlab("Strata") +
# scale_y_continuous("Cluster Proportion Proportion", breaks = seq(0, 1, 0.1)) +
# # scale_color_discrete("Treatment") +
# facet_grid(sms.treatment ~ assigned.treatment) +
# theme(legend.position = "bottom", axis.text.x = element_blank())
```
Outlier cells plot:
```{r outlier-cells-plot, echo=FALSE, fig.width=12, fig.height=10}
cell.takeup.data %>%
unite(stratum, county_dist_stratum, mon_status, remove = FALSE) %>%
ggplot(aes(stratum, takeup.prop)) +
geom_boxplot() + #aes(color = assigned.treatment)) +
geom_text_repel(aes(label = cluster.id), data = . %>% filter(outlier)) +
xlab("Strata") +
scale_y_continuous("Cluster Proportion Proportion", breaks = seq(0, 1, 0.1)) +
# scale_color_discrete("Treatment") +
facet_grid(sms.treatment ~ assigned.treatment + mon_status, scales = "free_x") +
theme(legend.position = "bottom", axis.text.x = element_blank())
```
The outlier ~~clusters~~ cells are:
```{r}
# bind_rows(monitored = outlier.clusters, all = unmonitored.outlier.clusters, .id = "monitored.sample") %>%
outlier.cells %>%
select(cluster.id, sms.treatment, mon_status) %>%
arrange(mon_status, sms.treatment) %>%
kable
```
# Knowledge and Beliefs
## Knowledge
```{r}
know.bel.cat.plot("who_worms") + labs(title = "Who is at risk of worms?")
```
```{r}
know.bel.cat.plot("effect_worms") + labs(title = "What are the effects of worms?")
```
```{r}
know.bel.cat.plot("spread_worms") +
labs(title = "Can a worms infected person spread worms to others?")
```
```{r}
know.bel.cat.plot("how_spread") +
labs(title = "How are worms spread?")
```
```{r}
know.bel.cat.plot("stop_worms") +
labs(title = "How to stop worms?")
```
Low proportion know drugs are effective.
```{r}
know.bel.cat.plot("when_treat") +
labs(title = "When should people deworm?")
```
## Externalities
```{r}
know.bel.cat.plot("worms_affect", na.rm = TRUE) +
labs(title = "If infected, can you affect others' health?")
```
```{r}
know.bel.cat.plot("neighbours_worms_affect", na.rm = TRUE) +
labs(title = "Can neighbors or relatives worm infection affect your health?", x = "")
```
### Baseline Only
```{r, fig.height=3, fig.width=8}
baseline.data %>%
select(few_deworm) %>%
ggplot(aes(few_deworm)) +
geom_bar(aes(y = ..count../sum(..count..))) +
coord_flip() +
labs(title = "Deworm if less than half of others deworm?", x = "", y = "Proportion")
```
```{r}
baseline.data %>%
select(many_deworm) %>%
ggplot(aes(many_deworm)) +
geom_bar(aes(y = ..count../sum(..count..))) +
coord_flip() +
labs(title = "Deworm if more than half of others deworm?", x = "", y = "Proportion")
```
```{r}
baseline.data %>%
select(more_less) %>%
ggplot(aes(more_less)) +
geom_bar(aes(y = ..count../sum(..count..))) +
coord_flip() +
labs(title = "Would you be more likely to deworm if few/many others get dewormed?", x = "", y = "Proportion")
```
## Baseline Social Image Questions
I'm dropping information about the question group: _A-D_.
```{r praise-stigma}
praise.stigma.plot <- baseline.data %>%
select(matches("^(praise|stigma)_[^_]+$")) %>%
gather(key = key, value = response) %>%
separate(key, c("praise.stigma", "topic"), "_") %>%
separate(topic, c("topic", "question.group"), -2) %>%
filter(!is.na(response)) %>%
count(praise.stigma, topic, response) %>%
group_by(praise.stigma, topic) %>%
mutate(n = n/sum(n)) %>%
ungroup %>%
mutate_at(vars(praise.stigma, response), funs(fct_relabel(factor(.), str_to_title))) %>%
mutate(topic = fct_recode(factor(topic),
"Wearing/not wearing nice clothes to church" = "clothe",
"Use Latrine/open defecation" = "defecat",
"Deworming/not deworming during MDA" = "dewor",
"Immunize/not immunize children" = "immuniz")) %>%
ggplot(aes(response)) +
geom_col(aes(y = n), alpha = 0.5) +
labs(y = "Proportion", x = "") +
scale_y_continuous(breaks = seq(0.25, 1, 0.25)) +
coord_flip() +
facet_grid(topic ~ praise.stigma, labeller = label_wrap_gen(width = 20)) +
theme_bw() +
theme(legend.position = "bottom",
strip.text.y = element_text(angle = 0),
strip.background = element_rect(colour = NA),
panel.border = element_blank())
```
```{r}
plot(praise.stigma.plot)
```
```{r, fig.width=10}
baseline.data %>%
select(matches("^(praise|stigma)_[^_]+_scale")) %>%
gather(key = key, value = response) %>%
separate(key, c("praise.stigma", "topic"), "_", extra = "merge") %>%
separate(topic, c("topic", "question.group"), "_scale") %>%
filter(!is.na(response)) %>%
ggplot(aes(response)) +
geom_freqpoly(aes(y = ..density.., color = topic), binwidth = 1) +
scale_x_continuous("Scale", breaks = 1:10) +
scale_color_discrete("") +
# facet_grid(topic ~ praise.stigma) +
facet_wrap(~ praise.stigma) +
labs(title = "Praise and Stigma Scale", y = "Density") +
theme(legend.position = "bottom")
```
## Baseline Pre-RCT Experience with Deworming Questions
```{r, fig.width=10, fig.height=5}
baseline.data %>%
select(treated, family_treated) %>%
gather(key = who.treated) %>%
mutate(who.treated = if_else(who.treated == "treated", "self", "family")) %>%
count(who.treated, value) %>%
group_by(who.treated) %>%
mutate(n = n/sum(n)) %>%
ungroup %>%
ggplot(aes(value)) +
geom_col(aes(y = n)) +
coord_flip() +
facet_wrap(~ who.treated) +
labs(title = "Ever been dewormed before?", x = "", y = "Proportion")
```
```{r}
baseline.data %>%
select(family_treated, who_treated) %>%
filter(family_treated == "yes") %>%
ggplot(aes(who_treated)) +
geom_bar(aes(y = ..count../sum(..count..))) +
coord_flip() +
labs(title = "Who in family got dewormed?", x = "", y = "Proportion")
```
```{r}
baseline.data %>%
select(treated, treated_when) %>%
filter(treated == "yes") %>%
ggplot(aes(treated_when)) +
geom_bar(aes(y = ..count../sum(..count..))) +
coord_flip() +
labs(title = "When did you last get dewormed?", x = "", y = "Proportion")
```
```{r, fig.width=10, fig.height=5}
baseline.data %>%
select(treated, family_treated, treated_where, where_family_treated) %>%
gather(key = who.treated, value = value, -c(treated, family_treated)) %>%
mutate(who.treated = if_else(who.treated == "treated_where", "self", "family")) %>%
filter((who.treated == "self" & treated == "yes") | (who.treated == "family" & family_treated == "yes")) %>%
count(who.treated, value) %>%
group_by(who.treated) %>%
mutate(n = n/sum(n)) %>%
ungroup %>%
ggplot(aes(value)) +
geom_col(aes(y = n)) +
coord_flip() +
facet_wrap(~ who.treated) +
labs(title = "Where last get dewormed?", x = "", y = "Proportion")
```
## Endline Treatment Questions
```{r}
endline.data %>%
select(know_deworm) %>%
ggplot(aes(know_deworm)) +
geom_bar(aes(y = ..count../sum(..count..))) +
coord_flip() +
labs(x = "", y = "Proportion", title = "Know of community-based MDA?")
```
```{r}
endline.data %>%
select(treat_begin, treat_end, days_available) %>%
gather %>%
mutate(key = case_when(.$key == "treat_begin" ~ "begin date",
.$key == "treat_end" ~ "end date",
TRUE ~ "days available")) %>%
count(key, value) %>%
group_by(key) %>%
mutate(n = n/sum(n)) %>%
ungroup %>%
ggplot(aes(value)) +
geom_col(aes(y = n)) +
# geom_bar(aes(y = ..count../sum(..count..), group = key)) +
coord_flip() +
facet_wrap(~ key, ncol = 1) +
labs(x = "", y = "Proportion", title = "Know ...?")
```
```{r mda-dates-dist}
day1.wave1 <- as_date("2016-10-03")
day12.wave1 <- day1.wave1 + days(11)
day1.wave2 <- as_date("2016-10-24")
day12.wave2 <- day1.wave2 + days(11)
wave.dates <- tribble(~ wave, ~ begin.end, ~ day,
1, "begin", day1.wave1,
1, "end", day12.wave1,
2, "begin", day1.wave2,
2, "end", day12.wave2)
mda.dates.dist.plot <- endline.data %>%
select(wave, treat_begin, treat_end, treat_begin_date, treat_end_date) %>%
gather(key = begin.end, value = day, -c(treat_begin, treat_end, wave)) %>%
mutate(begin.end = if_else(begin.end == "treat_begin_date", "begin", "end")) %>%
filter((treat_begin == "knows" & begin.end == "begin") | (treat_end == "knows" & begin.end == "end")) %>%
ggplot(aes(day)) +
geom_histogram(aes(fill = begin.end), alpha = 0.75, binwidth = 2, position = "identity") +
geom_vline(aes(xintercept = as.numeric(day)), linetype = "dotted", data = wave.dates) +
# scale_x_date(breaks = c(day1.wave1, day12.wave1, day1.wave2, day12.wave2)) +
scale_x_date("", date_breaks = "4 weeks", date_minor_breaks = "1 week", limits = c(as_date("2016-09-05"), as_date("2016-11-28"))) +
scale_y_continuous("") +
scale_fill_discrete("", labels = c("Begin Date", "End Date")) +
facet_wrap(~ wave, scales = "free_x", labeller = as_labeller(. %>% sprintf("Wave %s", .))) +
labs(title = "When did the MDA begin and end?", caption = "Dotted vertical lines identify correct MDA start and end days.") +
theme(legend.position = "bottom")
```
```{r, fig.width=10, fig.height=6}
plot(mda.dates.dist.plot)
```
```{r}
endline.data %>%
select(treat_days) %>%
ggplot(aes(treat_days)) +
geom_bar(aes(y = ..count../sum(..count..))) +
scale_x_continuous(breaks = seq(0, 40, 2)) +
labs(x = "", y = "Proportion", title = "How many deworming days?")
```
```{r}
know.bel.cat.plot("find_out", .baseline.data = NULL) + labs(title = "From whom did you hear about MDA?")
```
```{r}
know.bel.cat.plot("chv_visit", .baseline.data = NULL) + labs(title = "Did a CHV visit you to tell you about MDA?")
```
## Beliefs
```{r survey-of-10-beliefs, warning=FALSE}
survey.takeup.beliefs.10 <- list(Baseline = baseline.data, Endline = endline.data) %>%
compact %>%
map_df(select, one_of("dworm_rate", "ink_dworm_rate"), .id = "survey.type") %>%
gather(key = incentive, value = value, -survey.type) %>%
mutate(incentive = if_else(incentive == "dworm_rate", "None", "Ink")) %>%
ggplot(aes(value)) +
geom_freqpoly(aes(y = ..density.., color = survey.type, linetype = incentive), binwidth = 1) +
scale_x_continuous("Reported Rate", breaks = 0:10) +
scale_y_continuous("Density") +
scale_color_discrete("") +
scale_linetype_manual("Signal", values = c("dashed", "solid")) +
theme(legend.position = "bottom") +
labs(title = "How many out of 10 will come for deworming?")
```
```{r}
plot(survey.takeup.beliefs.10)
```
```{r survey-of-10-beliefs-boxplot, warning=FALSE}
survey.takeup.beliefs.10.boxplot <- list(Baseline = baseline.data, Endline = endline.data) %>%
compact %>%
map_df(select, one_of("dworm_rate", "ink_dworm_rate"), .id = "survey.type") %>%
gather(key = incentive, value = value, -survey.type) %>%
mutate(incentive = if_else(incentive == "dworm_rate", "None", "Ink")) %>%
ggplot(aes(survey.type)) +
geom_boxplot(aes(y = value, color = survey.type, linetype = incentive), position = position_dodge(width = 1.1)) +
scale_y_continuous("Reported Rate", breaks = 0:10) +
scale_color_discrete("") +
scale_x_discrete("") +
coord_flip() +
scale_linetype_manual("Signal", values = c("dotdash", "solid")) +
theme(legend.position = "bottom", axis.text.y = element_blank(), axis.ticks.y = element_blank())
```
```{r}
plot(survey.takeup.beliefs.10.boxplot)
```
```{r, fig.width=10}
endline.data %>%
filter(sms.treatment == "sms.control", sms.ctrl.subpop == "non.phone.owner") %>%
ggplot(aes(x = dworm_rate)) +
geom_freqpoly(aes(y = ..density.., color = dist.pot.group), binwidth = 1) +
scale_x_continuous("Rate", breaks = 1:10) +
scale_y_continuous("Density") +
scale_color_discrete("") +
facet_wrap(~ assigned.treatment) +
theme(legend.position = "bottom") +
labs(title = "How many out of 10 will come for deworming?")
```
```{r, fig.width=10}
endline.data %>%
filter(sms.treatment != "sms.control" | sms.ctrl.subpop == "phone.owner") %>%
mutate(sms.treated = if_else(sms.treatment != "sms.control", "treated", "control")) %>%
ggplot(aes(x = assigned.treatment)) +
geom_boxplot(aes(y = dworm_rate, color = dist.pot.group)) +
facet_wrap(~ sms.treated) +
scale_color_discrete("") +
theme(legend.position = "bottom")
```
```{r}
reg.endline.beliefs <- endline.data %>%
filter(sms.treatment != "sms.control" | sms.ctrl.subpop == "phone.owner", sms.treatment != "reminder.only") %>%
mutate(sms.treated = if_else(sms.treatment != "sms.control", "treated", "control"),
sms.treatment = factor(sms.treatment) %>% relevel(ref = "social.info")) %>%
group_by(sms.treated, assigned.treatment, dist.pot.group) %>%
do(filter(., !is_outlier(.$dworm_rate))) %>%
ungroup %>%
run_strat_reg(dworm_rate ~ assigned.treatment * dist.pot.group * sms.treatment, .strat.by = "county", .cluster = "cluster.id", .covariates = c("school", "floor", "ethnicity"))
reg.endline.beliefs %>%
tidy %>%
kable(digits = 4)
```
```{r, echo=TRUE}
linear_tester(reg.endline.beliefs,
# Effect of incentive
c("far",
"far + far:sms.control",
"ink",
"ink + ink:sms.control",
"ink + ink:far",
"ink + ink:far + ink:far:sms.control + ink:sms.control",
"calendar",
"calendar + calendar:sms.control",
"calendar + calendar:far",
"calendar + calendar:far + calendar:far:sms.control + calendar:sms.control",
"bracelet",
"bracelet + bracelet:sms.control",
"bracelet + bracelet:far",
"bracelet + bracelet:far + bracelet:far:sms.control + bracelet:sms.control",
# Effect of distance
"calendar:far + calendar:far:sms.control + far:sms.control + far",
"calendar:far + far",
"bracelet:far + bracelet:far:sms.control + far:sms.control + far",
"bracelet:far + far",
# Effect of SMS
"- sms.control",
"- sms.control - far:sms.control",
"- ink:sms.control - ink:far:sms.control - far:sms.control - sms.control",
"- ink:sms.control - sms.control",
"- ink:sms.control - ink:far:sms.control - far:sms.control - sms.control",
"- calendar:sms.control - sms.control",
"- calendar:sms.control - calendar:far:sms.control - far:sms.control - sms.control",
"- bracelet:sms.control - sms.control",
"- bracelet:sms.control - bracelet:far:sms.control - far:sms.control - sms.control")) %>%
kable(digits = 4)
```
```{r}
baseline.data %>%
select(dworm_proportion) %>%
ggplot(aes(dworm_proportion)) +
geom_bar() +
labs(title = "How many will come for deworming?", x = "")
```
```{r}
baseline.data %>%
select(ink_more_less) %>%
ggplot(aes(ink_more_less)) +
geom_bar() +
coord_flip() +
labs(title = "More/less will come with ink?", x = "")
```
# Treatment Assignment
## Balance
```{r, echo=TRUE}
balance.test.covar <- c(setdiff(reg.covar, "ethnicity"), "ethnicity2", "dist.pot.group")
balance.data <- analysis.data %>%
filter(!sms.treated, #!hh.baseline.sample,
!is.na(floor), !is.na(school), !is.na(dist.pot.group), !is.na(ethnicity)) %>%
# anti_join(outlier.cells, c("assigned.treatment", "sms.treatment", "mon_status", "cluster.id", "phone_owner")) %>%
select_(.dots = c("assigned.treatment", balance.test.covar)) %>%
mlogit.data(choice = "assigned.treatment", shape = "wide")
# Had to remove "floor" so the covariates are non-singular
unrestricted.reg <- balance.data %>%
mlogit::mlogit(as.formula(sprintf("assigned.treatment ~ 0 | %s", paste(balance.test.covar, collapse = " + "))), data = .)
restricted.reg <- balance.data %>%
na.omit %>%
mlogit::mlogit(assigned.treatment ~ 0 | 1, data = .)
waldtest(unrestricted.reg, restricted.reg)
```
## Distance Assignment
```{r actual-distance-distribution}
analysis.data %>%
# anti_join(unmonitored.outlier.clusters, c("sms.treatment", "cluster.id")) %>%
anti_join(outlier.cells, c("assigned.treatment","sms.treatment", "mon_status", "cluster.id")) %>%
mutate(assigned.treatment = fct_relabel(assigned.treatment, str_to_title)) %>%
ggplot(aes(dist.to.pot)) +
geom_density(aes(color = dist.pot.group, linetype = "Household")) +
geom_density(aes(color = dist.pot.group, linetype = "Cluster Center"),
data = mutate(village.centers, assigned.treatment = fct_relabel(assigned.treatment, str_to_title))) +
geom_vline(xintercept = c(1250), linetype = "dashed") +
labs(y = "Density",
caption = "Cluster centers were calculated as the centroid location of all households in cluster.") +
scale_x_continuous("Distance to Treatment Location (meters)", breaks = seq(0, 10000, 2500/4)) +
scale_color_discrete("Cluster Distance Assignment", labels = c("Close", "Far")) +
scale_linetype_discrete("Distance From") +
theme(legend.position = "bottom") +
facet_wrap(~ assigned.treatment)
```
# Incentive Preferences
## Self-reported Preferences (Endline)
```{r reported-gift-pref}
reported.gift.pref.plot <- analysis.data %>%
plot.pref.unfaceted() +
facet_wrap(~ assigned.treatment, nrow = 1)
```
```{r, fig.width=8}
plot(reported.gift.pref.plot)
```
```{r reported-gift-pref-deworm}
reported.gift.pref.dewormed.plot <- analysis.data %>%
mutate(dewormed.any = if_else(dewormed.any, "Dewormed", "Not Dewormed")) %>%
plot.pref.unfaceted("dewormed.any") +
facet_grid(dewormed.any ~ assigned.treatment)
```
```{r, fig.width=8}
plot(reported.gift.pref.dewormed.plot)
```
```{r other-incentive-plot}
other.have.incentive.plot <- analysis.data %>%
# filter(!is.na(gift_choice), monitored, !hh.baseline.sample, !is.na(hh_cal) | !is.na(hh_bracelet),
filter(!is.na(gift_choice), monitored, !is.na(hh_cal) | !is.na(hh_bracelet),
assigned.treatment %in% c("calendar", "bracelet")) %>%
anti_join(outlier.cells, c("assigned.treatment","sms.treatment", "mon_status", "cluster.id")) %>%
gather(hh.incentive, hh_switch, hh_cal, hh_bracelet) %>%
filter(!is.na(hh_switch)) %>%
mutate(dewormed.any = if_else(dewormed.any, "Dewormed", "Not Dewormed"),
assigned.treatment = fct_relabel(assigned.treatment, . %>% paste("arm")),
hh_switch = fct_recode(hh_switch, "Other in household got calendar" = "yes", "No one else got calendar" = "no")) %>%
group_by(dewormed.any, assigned.treatment, hh_switch) %>%
mutate(arm.size = n()) %>%
group_by(gift_choice, add = TRUE) %>%
summarize(pref.prop = n() / first(arm.size)) %>%
ungroup %>%
mutate_at(vars(gift_choice, assigned.treatment), funs(fct_relabel(., str_to_title))) %>%
ggplot(aes(gift_choice, pref.prop)) +
geom_col(aes(fill = assigned.treatment), position = "dodge", alpha = 0.5, color = alpha("black", 0.5)) +
scale_fill_discrete("") +
labs(x = "Gift", y = "Preferred Proportion", title = "Endline Gift Preference",
subtitle = "Split by whether household has other calendar(s) and deworming take-up") +
facet_grid(dewormed.any ~ assigned.treatment + hh_switch) +
theme(legend.position = "bottom")
```
```{r, fig.width=8}
plot(other.have.incentive.plot)
```
The above graph seems to show that conditional on someone in my household having a calendar my desire for a calendar is the same regardless of whether I already have a calendar (i.e. dewormed) or do not have a calendar (i.e. not dewormed). Meaning one of my household members obtaining a calendar is the same as me having a calendar. However, given that overall the calendar is still prefered to the bracelet (see graph before that combines households) since for most households (70$\%$ in data) no one came for deworming, I think we are fine. Ideally, we find a way to control for these negatively correlated preferences in calendars but not sure how exactly.
Irrespective of whether you have come for deworming or not, or whether someone else has come for deworming in your households and received a bracelet, you still prefer the calendar. People just did not really like the bracelets! If you did not come for deworming you value a bracelet the same regardless of whether no one else in your household has a bracelet or someone else has a bracelet. There is no evidence for a complementarity or substitution here.
```{r, fig.width=8}
analysis.data %>%
filter(monitored, !is.na(cal_value), assigned.treatment == "calendar") %>% # !hh.baseline.sample,
anti_join(outlier.cells, c("assigned.treatment","sms.treatment", "mon_status", "cluster.id")) %>%
mutate(dewormed.any = if_else(dewormed.any, "Dewormed", "Not Dewormed"),
cal_value = fct_recode(cal_value, "Would still want a calendar" = "yes", "Would not want another calendar" = "no")) %>%
group_by(dewormed.any) %>%
mutate(arm.size = n()) %>%
group_by(cal_value, add = TRUE) %>%
summarize(pref.prop = n() / first(arm.size)) %>%
ungroup %>%
ggplot(aes(cal_value, pref.prop)) +
geom_col(alpha = 0.5, color = "black") +
labs(x = "", y = "Proportion", title = "Would Still Value a Calendar When Household Already Has One",
subtitle = "Split by deworming take-up",
caption = "This is only for the calendar arm of the experiment and limited to those who reported other calendar(s) in their household") +
facet_wrap(~ dewormed.any, ncol = 1) +
coord_flip()
```
```{r, fig.width=8}
analysis.data %>%
filter(monitored, !is.na(cal_value), !is.na(gift_choice), assigned.treatment == "calendar") %>% # !hh.baseline.sample,
anti_join(outlier.cells, c("assigned.treatment","sms.treatment", "mon_status", "cluster.id")) %>%
mutate(dewormed.any = if_else(dewormed.any, "Dewormed", "Not Dewormed"),
cal_value = fct_recode(cal_value, "Would still want a calendar" = "yes", "Would not want another calendar" = "no")) %>%
group_by(dewormed.any, cal_value) %>%
mutate(arm.size = n()) %>%
group_by(gift_choice, add = TRUE) %>%
summarize(pref.prop = n() / first(arm.size)) %>%
ungroup %>%
ggplot(aes(gift_choice, pref.prop)) +
geom_col(alpha = 0.5, color = "black") +
labs(x = "Gift", y = "Preferred Proportion", title = "Endline Gift Preference",
subtitle = "Split by stated desire for another calendar if household already has one and deworming take-up",
caption = "This is only for the calendar arm of the experiment and limited to those who reported other calendar(s) in their household") +
facet_grid(dewormed.any ~ cal_value)
```
## Willing-to-Pay Survey
```{r first-choice-wtp}
first.choice.wtp.plot <- wtp.data %>%
filter(!is.na(first_choice)) %>%
ggplot() +
geom_bar(aes(fct_relabel(first_choice, str_to_title), y = ..count../sum(..count..)), alpha = 0.5) +
labs(x = "First Choice", title = "First Choice When Offered Calendars or Bracelets",
caption = "This data is for the control arm only.") +
scale_y_continuous("Proportion", breaks = seq(0, 1, 0.1)) +
coord_flip()
```
```{r, fig.height=2, fig.width=8}
plot(first.choice.wtp.plot)
```
```{r}
wtp.data %>%
ggplot() +
geom_bar(aes(factor(price), y = ..count../sum(..count..)), alpha = 0.5, color = "black") +
labs(x = "Offered Price (KSh)", y = "Proportion", title = "Prices Offered to Switch Gift Choice")
```
```{r switch-price-wtp}
switch.price.plot <- wtp.data %>%
filter(!is.na(first_choice)) %>%
mutate(first_choice = fct_relabel(first_choice, str_to_title) %>% fct_relevel("Calendar")) %>%
group_by(first_choice, price) %>%
summarize(prop.switch = sum(second_choice == "switch")/n()) %>%
ungroup %>%
ggplot(aes(factor(price), prop.switch, group = first_choice)) +
geom_point(aes(color = first_choice)) +
geom_line(aes(color = first_choice)) +
scale_color_discrete("First Choice") +
labs(x = "Offered Price (KSh)", y = "Proportion", title = "Proportion Switching From First Choice of Gift When Offered Cash",
caption = "This data is for the control arm only.")
```
```{r}
plot(switch.price.plot)
```
## Estimate utility difference Calendar Bracelet
```{r}
wtp.cdf <- wtp.data %>%
select(first_choice,second_choice,price) %>%
filter(is.na(first_choice) == FALSE)
table(wtp.cdf$first_choice)
n_bra <- sum(wtp.cdf$first_choice == "bracelet")
n_cal <- sum(wtp.cdf$first_choice == "calendar")
N <- nrow(wtp.cdf)
bra_share <- n_bra/N
cal_share <- n_cal/N
wtp.cdf$price[wtp.cdf$first_choice == "bracelet"] <- - wtp.cdf$price[wtp.cdf$first_choice == "bracelet"]
wtp.cdf <- wtp.cdf %>%
group_by(price) %>%
summarise(N = n(), Pr = sum(second_choice == "switch")/N)
wtp.cdf$tot_pr <- NA
wtp.cdf$tot_pr[wtp.cdf$price >0] <- bra_share + cal_share*wtp.cdf$Pr[wtp.cdf$price >0]
wtp.cdf$tot_pr[wtp.cdf$price <0] <- bra_share - bra_share*wtp.cdf$Pr[wtp.cdf$price <0]
ggplot(wtp.cdf, aes(x=price,y=tot_pr)) +
geom_point() +
geom_line() +
scale_x_continuous(breaks = seq(-100, 100, 10)) +
theme_bw()
```
Note: -60 KSH is a problem of small sample in bracelet choice group. should not observe 100 percent switching. Median u diff approx. KSH 40. Next step: fit CDF through LPM incl. possibly interaction terms.
```{r, eval=FALSE}
wtp.data %>%
select(first_choice, second_choice, price) %>%
filter(!is.na(first_choice)) %>%
mutate(choice.calendar = first_choice == if_else(second_choice == "keep", "calendar", "bracelet"),
price = (1 - 2 * (first_choice == "calendar")) * price) %>%
bind_rows(mutate(.,
choice.calendar = first_choice == "calendar",
price = 0)) %>%
group_by(price) %>%
summarize(prop.pref.calendar = mean(choice.calendar),
price.prop = n() / nrow(.)) %>%
ungroup %>%
arrange(price) %>%
mutate(cumul.prop.pref.calendar = cumsum(prop.pref.calendar * price.prop) / cumsum(price.prop)) %>%
arrange(desc(price)) %>%
mutate(cumul.prop.pref.bracelet = cumsum((1 - prop.pref.calendar) * price.prop) / cumsum(price.prop)) %>%
gather(ref.incentive, cumul.prop.pref, cumul.prop.pref.bracelet, cumul.prop.pref.calendar) %>%
# mutate(#price = (1 - 2 * (ref.incentive == "cumul.prop.pref.bracelet")) * price,
# cumul.prop.pref = if_else(ref.incentive == "cumul.prop.pref.bracelet", 1 - cumul.prop.pref, cumul.prop.pref)) %>%
ggplot(aes(factor(price), cumul.prop.pref, group = ref.incentive)) +
geom_point() +
geom_line() +
scale_y_continuous(breaks = seq(0, 1, 0.05)) +
labs(x = "Offered Price (KSh)", y = "Proportion", title = "Proportion Switching From First Choice of Gift When Offered Cash",
caption = "This data is for the control arm only.")
```
# Reduced Form Analysis
Below is the main regression specification, where $m(\cdot)$ and $m_1(\cdot)\dots m_{K-1}(\cdot)$ define the causal effects to estimate. $l(\cdot)$ and $l_1(\cdot)\dots l_{K-1}(\cdot)$ define the regression intercepts.
$$
\begin{equation}
Y_{ij} = \left(m(Z_j, B_j;\theta) + l(B_j;\theta^c) + X_{ij} \cdot \beta \right) \cdot \frac{B_{j}(K)}{N(K)/N} + \sum_{k=1}^{K-1} \left(m_k(Z_j, B_j;\theta_k) + l_k(B_j;\theta^c_k) + X_{ij} \cdot \beta_k \right) \cdot \left( B_{j}(k) - B_{j}(K)\cdot\frac{N(k)}{N(K)} \right) + \varepsilon_{ij}
\end{equation}
$$
* $i$ indexes individuals, $j$ clusters
* $Z_j \in \mathcal{Z} = \{ control, ink, calendar, bracelet \}$
* $Z_{j}(z) = \mathbf{1}\{Z_j = z\}$ is an indicator for whether cluster $j$ was assigned treatment $z$.
* $B_{j}(k) = \mathbf{1}\{B_j = k\}$ is an indicator for whether cluster $j$ is in stratum $k$.
* $X_{ij}$ is a vector of covariates
* $N(k)$ is the size of stratum $k$.
* $N$ is the total number of observations
To clarify what this stratified regression is doing, we are estimating
$$
\tau(z) = E[Y_{ij}(z) - Y_{ij}(control)] = \sum_{k = 1}^{K} \frac{N(k)}{N} E[Y_{ij}(z) - Y_{ij}(control)|B_j = k]
$$
## Basic Treatment Effect
Here we estimate the below models
$$
\begin{align}
m(Z_j, B_j; \theta) &= \sum_{z \in \mathcal{Z}\setminus \{control\}} \tau(z) \cdot Z_{j}(z) \\
m_k(Z_j, B_j; \theta_k) &= \sum_{z\in \mathcal{Z}\setminus\{control\}} \tau_k(z) \cdot Z_{j}(z) \\
l(B_j; \theta^c) &= \alpha \\
l_k(B_j; \theta^c_k) &= \alpha_k
\end{align}
$$
where $E[Y_{ij}(z) - Y_{ij}(control)] = \tau(z)$ and $E[Y_{ij}(control)] = \alpha$.
### Regression Without Controls
Without controls (using cluster robust standard errors). ~~Also including block bootstrapped standard errors and p-values.~~
```{r}
# analysis.data %>%
# filter(monitored, monitor.consent, sms.treatment == "sms.control", !hh.baseline.sample) %>%
# anti_join(outlier.clusters, c("sms.treatment", "cluster.id")) %>%
# unite(stratum, county, dist.pot.group, sep = ".") %>%
# select(dewormed.any, assigned.treatment, stratum, cluster.id) %>%
# na.omit %>%
# group_by(stratum) %>%
# mutate(stratum.weight = n()) %>%
# ungroup %>%
# lm(dewormed.any ~ assigned.treatment, data = ., weights = stratum.weight)
```
```{r basic-reg}
reg.output.sms.ctrl <- analysis.data %>%
filter(monitored, sms.treatment.2 == "sms.control") %>% #, !hh.baseline.sample) %>%
anti_join(outlier.cells, c("assigned.treatment","sms.treatment", "mon_status", "cluster.id", "phone_owner")) %>%
run_strat_reg(dewormed.any ~ assigned.treatment,
.strat.by = "county_dist_stratum", .cluster = "cluster.id", .covariates = census.reg.covar)
reg.output.sms.ctrl.calendar <- analysis.data %>%
filter(monitored, sms.treatment.2 == "sms.control") %>% #, !hh.baseline.sample) %>%
anti_join(outlier.cells, c("assigned.treatment","sms.treatment", "mon_status", "cluster.id", "phone_owner")) %>%
mutate( assigned.treatment = relevel(assigned.treatment, ref = "calendar")) %>%
run_strat_reg(dewormed.any ~ assigned.treatment, .strat.by = "county_dist_stratum", .cluster = "cluster.id", .covariates = census.reg.covar)
```
```{r}
kable(tidy(reg.output.sms.ctrl), digits = 4)
```
With _calendar_ as the omitted category, to estimate $E[Y_{ij}(bracelet) - Y_{ij}(calendar)] = \tau(bracelet) - \tau(calendar)$:
```{r}
reg.output.sms.ctrl.calendar %>%
tidy %>%
filter(term %in% c("(intercept)", "bracelet")) %>%
kable(digits = 4)
```
```{r, fig.width=10}
prep.sms.ctrl.plot.data(reg.output.sms.ctrl) %>% {
plot.sms.ctrl.takeup(.) +
labs(subtitle = "Without control")
}
```
Running regression without controls with the same sample as in the with controls regression:
```{r, warning=FALSE}
reg.output.sms.ctrl.lim <- analysis.data %>%
filter(monitored, sms.treatment == "sms.control", !is.na(floor)) %>% # !hh.baseline.sample,
anti_join(outlier.cells, c("assigned.treatment","sms.treatment", "mon_status", "cluster.id", "phone_owner")) %>%
run_strat_reg(dewormed.any ~ assigned.treatment, .strat.by = "county_dist_stratum", .cluster = "cluster.id", .covariates = census.reg.covar)
reg.output.sms.ctrl.calendar.lim <- analysis.data %>%
filter(monitored, sms.treatment == "sms.control", !is.na(floor)) %>% # !hh.baseline.sample,
anti_join(outlier.cells, c("assigned.treatment","sms.treatment", "mon_status", "cluster.id", "phone_owner")) %>%
mutate( assigned.treatment = relevel(assigned.treatment, ref = "calendar")) %>%
run_strat_reg(dewormed.any ~ assigned.treatment, .strat.by = "county_dist_stratum", .cluster = "cluster.id", .covariates = census.reg.covar)
kable(tidy(reg.output.sms.ctrl.lim), digits = 4)
```
With _calendar_ as the omitted category for the limited sample, to estimate $E[Y_{ij}(bracelet) - Y_{ij}(calendar)] = \tau(bracelet) - \tau(calendar)$:
```{r}
reg.output.sms.ctrl.calendar.lim %>%
tidy %>%
filter(term %in% c("(intercept)", "bracelet")) %>%
kable(digits = 4)
```
```{r, fig.width=10}
prep.sms.ctrl.plot.data(reg.output.sms.ctrl.lim) %>% {
plot.sms.ctrl.takeup(.) +
labs(subtitle = "Without control restricted sample")
}
```
We can see that changes in coefficients e.g. for ink are not due to controlling for covariates but due to the fact that we are restricting the sample to only those individuals for whom we observe covariates. Let's talk about this and make a decision on how to best move forward. Commonly from presentations I remember people working with one sample - without controls - and then showing same sample with controls to show "show" that coefficient estimates do not change and increase precision.
```{r}
neyman.results <- analysis.data %>%
filter(monitored, sms.treatment == "sms.control") %>% #, !hh.baseline.sample) %>%
anti_join(outlier.cells, c("assigned.treatment","sms.treatment", "mon_status", "cluster.id")) %>%
analyze.neyman.blk.bs(0) %>%
# analyze.neyman.blk.bs(2000) %>%
mutate(treatment.group = factor(treatment.group, levels = c("control", "ink", "calendar", "bracelet")))
```
```{r}
# neyman.results %>%
# unnest(treatment.data) %>%
# filter(rhs.treatment.group == "control" | (treatment.group == "bracelet" & rhs.treatment.group == "calendar")) %>%
# select(treatment.group, rhs.treatment.group, ate, ate_sd, ate_tstat, ate_pvalue) %>%
# kable(digits = 4)
```
Stratum-level deworming probability
```{r}
neyman.results %>%
unnest(strata.data) %>%
select(county, dist.pot.group, treatment.group, stratum.assign.mean.dewormed) %>%
spread(treatment.group, stratum.assign.mean.dewormed) %>%
kable(digits = 4)
```
```{r}
neyman.results %>%
unnest(treatment.data) %>%
distinct(treatment.group, .keep_all = TRUE) %>%
ggplot() +
geom_col(aes(treatment.group, treatment.mean.dewormed), alpha = 0.5, color = "black") +
scale_x_discrete("Treatment") +
scale_y_continuous("Proportion Dewormed", breaks = seq(0, 0.6, 0.05))
```
```{r}
neyman.results %>%
unnest(strata.data) %>%
ggplot(aes(factor(treatment.group))) +
geom_col(aes(y = stratum.assign.mean.dewormed), color = "black", alpha = 0.5) +
scale_x_discrete("") +
scale_y_continuous("Take-up Proportion") +
facet_grid(county ~ dist.pot.group)
```
Strata sizes:
```{r}
neyman.results %>%
unnest(strata.data) %>%
select(county, dist.pot.group, treatment.group, stratum.assign.size) %>%
spread(treatment.group, stratum.assign.size) %>%
kable()
```
#### Unmonitored
```{r unmon-basic-reg}
unmon.reg.output.sms.ctrl <- analysis.data %>%
filter(sms.treatment.2 == "sms.control") %>% #, !hh.baseline.sample) %>%
anti_join(outlier.cells, c("assigned.treatment","sms.treatment", "mon_status", "cluster.id", "phone_owner")) %>%
run_strat_reg(dewormed.any ~ assigned.treatment * mon_status, .strat.by = "county_dist_stratum", .cluster = "cluster.id")
restrict.unmon.reg.output.sms.ctrl <- analysis.data %>%
filter(sms.treatment.2 == "sms.control") %>% #, !hh.baseline.sample) %>%
anti_join(outlier.cells, c("assigned.treatment","sms.treatment", "mon_status", "cluster.id", "phone_owner")) %>%
run_strat_reg(dewormed.any ~ assigned.treatment + mon_status, .strat.by = "county_dist_stratum", .cluster = "cluster.id", .covariates = census.reg.covar)
```
```{r}
kable(tidy(unmon.reg.output.sms.ctrl), digits = 4)
```
```{r}
linear_tester(unmon.reg.output.sms.ctrl, str_c(c("ink", "calendar", "bracelet"), "unmonitored", sep = ":"), joint = TRUE) %>%
tidy() %>%
kable()
```
```{r}
kable(tidy(restrict.unmon.reg.output.sms.ctrl), digits = 4)
```
```{r, fig.width=10}
prep.sms.ctrl.plot.data(unmon.reg.output.sms.ctrl) %>% {
plot.sms.ctrl.takeup(.) +
labs(subtitle = "Entire census sample, without controls")
}
```
```{r, fig.width=10}
prep.sms.ctrl.plot.data(restrict.unmon.reg.output.sms.ctrl) %>% {
plot.sms.ctrl.takeup(.) +
labs(subtitle = "Entire census sample, without controls, restricted")
}
```
### Regression With Controls
These are the regressors we are controlling for:
```{r covariates}
reg.covar