Commit ·
c35658f
0
Parent(s):
Duplicate from chuxuan/REPRO-Bench
Browse filesCo-authored-by: Anonymous Submission <anonymous-submission-acl2025@users.noreply.huggingface.co>
This view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +92 -0
- .gitignore +4 -0
- 1/paper.pdf +0 -0
- 1/replication_package/README.txt +3 -0
- 1/replication_package/data/tpnw_aware_raw.csv +3 -0
- 1/replication_package/data/tpnw_orig_income.csv +3 -0
- 1/replication_package/data/tpnw_raw.csv +3 -0
- 1/replication_package/meta/hbg_codebook.txt +3 -0
- 1/replication_package/meta/hbg_instrument.pdf +0 -0
- 1/replication_package/meta/hbg_pap.pdf +0 -0
- 1/replication_package/scripts/hbg_analysis.R +1033 -0
- 1/replication_package/scripts/hbg_cleaning.R +406 -0
- 1/replication_package/scripts/hbg_group_cue.R +53 -0
- 1/replication_package/scripts/helper_functions.R +16 -0
- 1/replication_package/scripts/run_hbg_replication.R +36 -0
- 1/should_reproduce.txt +3 -0
- 10/paper.pdf +3 -0
- 10/replication_package/Codebook for Dyadic Party Dataset.docx +0 -0
- 10/replication_package/Codebook for Gender Disaggregated Dyadic Party Dataset.docx +0 -0
- 10/replication_package/Codebook for Multilevel Dataset.docx +0 -0
- 10/replication_package/dyadic_data_1-4-22.Rdata +3 -0
- 10/replication_package/gender_disagregated_8-8-21.rds +3 -0
- 10/replication_package/multilevel_1-5-22.Rdata +3 -0
- 10/replication_package/readme.rtf +28 -0
- 10/replication_package/replication_code.R +716 -0
- 10/should_reproduce.txt +3 -0
- 100/paper.pdf +3 -0
- 100/replication_package/journal.pone.0278164.s002.xlsx +3 -0
- 100/should_reproduce.txt +3 -0
- 101/paper.pdf +3 -0
- 101/replication_package/.gitignore +30 -0
- 101/replication_package/.gitmodules +0 -0
- 101/replication_package/LICENSE.md +395 -0
- 101/replication_package/README.md +105 -0
- 101/replication_package/WALS_reanalysis_controlled_setup.R +140 -0
- 101/replication_package/WALS_reanalysis_controlled_setup_high_coverage.R +181 -0
- 101/replication_package/WALS_reanalysis_setup.R +40 -0
- 101/replication_package/WALS_sparseness.R +70 -0
- 101/replication_package/all_scripts.R +91 -0
- 101/replication_package/assigning_AUTOTYP_areas.R +85 -0
- 101/replication_package/create_pop_table.R +117 -0
- 101/replication_package/creating_boundness_metric.R +48 -0
- 101/replication_package/creating_informativity_score.R +51 -0
- 101/replication_package/data/GB_wide/parameters.csv +3 -0
- 101/replication_package/data/complexity_data_WALS.csv +3 -0
- 101/replication_package/data/glottolog-cldf_wide_df.tsv +3 -0
- 101/replication_package/data/lang_endangerment_predictors.xlsx +3 -0
- 101/replication_package/data/phylogenies/EDGE6635-merged-relabelled.tree +3 -0
- 101/replication_package/data_wrangling/ethnologue_pop_SM.tsv +3 -0
- 101/replication_package/data_wrangling/ethnologue_pop_SM_morph_compl_reanalysis.tsv +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.lz4 filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
# Audio files - uncompressed
|
| 38 |
+
*.pcm filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
*.sam filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
*.raw filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
# Audio files - compressed
|
| 42 |
+
*.aac filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
*.flac filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
*.ogg filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
*.wav filter=lfs diff=lfs merge=lfs -text
|
| 47 |
+
# Image files - uncompressed
|
| 48 |
+
*.bmp filter=lfs diff=lfs merge=lfs -text
|
| 49 |
+
*.gif filter=lfs diff=lfs merge=lfs -text
|
| 50 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
| 51 |
+
*.tiff filter=lfs diff=lfs merge=lfs -text
|
| 52 |
+
# Image files - compressed
|
| 53 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 54 |
+
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 55 |
+
*.webp filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
# Video files - compressed
|
| 57 |
+
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 58 |
+
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 59 |
+
*.csv filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
*.dta filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
*.sav filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
*.xls filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
*.xlsx filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
*.rdata filter=lfs diff=lfs merge=lfs -text
|
| 65 |
+
*.rds filter=lfs diff=lfs merge=lfs -text
|
| 66 |
+
*.txt filter=lfs diff=lfs merge=lfs -text
|
| 67 |
+
*.dat filter=lfs diff=lfs merge=lfs -text
|
| 68 |
+
*.pdf filter=lfs diff=lfs merge=lfs -text
|
| 69 |
+
4/paper.pdf filter=lfs diff=lfs merge=lfs -text
|
| 70 |
+
*.img filter=lfs diff=lfs merge=lfs -text
|
| 71 |
+
*.rrd filter=lfs diff=lfs merge=lfs -text
|
| 72 |
+
*.shp filter=lfs diff=lfs merge=lfs -text
|
| 73 |
+
*.mxd filter=lfs diff=lfs merge=lfs -text
|
| 74 |
+
*.dbf filter=lfs diff=lfs merge=lfs -text
|
| 75 |
+
*.mat filter=lfs diff=lfs merge=lfs -text
|
| 76 |
+
*.tif filter=lfs diff=lfs merge=lfs -text
|
| 77 |
+
*.adf filter=lfs diff=lfs merge=lfs -text
|
| 78 |
+
*.pptx filter=lfs diff=lfs merge=lfs -text
|
| 79 |
+
*.Rda filter=lfs diff=lfs merge=lfs -text
|
| 80 |
+
*.smcl filter=lfs diff=lfs merge=lfs -text
|
| 81 |
+
*.ster filter=lfs diff=lfs merge=lfs -text
|
| 82 |
+
*.exe filter=lfs diff=lfs merge=lfs -text
|
| 83 |
+
*.shx filter=lfs diff=lfs merge=lfs -text
|
| 84 |
+
*.shp filter=lfs diff=lfs merge=lfs -text
|
| 85 |
+
*.mpk filter=lfs diff=lfs merge=lfs -text
|
| 86 |
+
*.log filter=lfs diff=lfs merge=lfs -text
|
| 87 |
+
*.dct filter=lfs diff=lfs merge=lfs -text
|
| 88 |
+
*.gph filter=lfs diff=lfs merge=lfs -text
|
| 89 |
+
*.sas7bdat filter=lfs diff=lfs merge=lfs -text
|
| 90 |
+
*.tsv filter=lfs diff=lfs merge=lfs -text
|
| 91 |
+
*.tree filter=lfs diff=lfs merge=lfs -text
|
| 92 |
+
*.docx filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.DS_Store
|
| 2 |
+
72/paper.pdf
|
| 3 |
+
72/replication_package/*
|
| 4 |
+
|
1/paper.pdf
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
1/replication_package/README.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:591b8bd1ed84ebf13e4c3052d3d98fcf4a7e33ab4a2be787061ad97eb5dea5c1
|
| 3 |
+
size 6048
|
1/replication_package/data/tpnw_aware_raw.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f15f6cf1386eb15f6412a917e06777cbe9f628415eb5e0e5389fad8d1fdd2944
|
| 3 |
+
size 222617
|
1/replication_package/data/tpnw_orig_income.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:39cfbdce237bdd88638c0e559db179ea2bb3d34847e8482ef764b44d01991401
|
| 3 |
+
size 7133
|
1/replication_package/data/tpnw_raw.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dbad02b01d1e0a31d6dbdf8c53460278c016864b72f8e7388a2b18e8f8c6ce64
|
| 3 |
+
size 353061
|
1/replication_package/meta/hbg_codebook.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5edd9b84c0e52d121e8996dd0e176850d103dc94a29c61795ab806d30bdd4f8b
|
| 3 |
+
size 29133
|
1/replication_package/meta/hbg_instrument.pdf
ADDED
|
Binary file (132 kB). View file
|
|
|
1/replication_package/meta/hbg_pap.pdf
ADDED
|
Binary file (264 kB). View file
|
|
|
1/replication_package/scripts/hbg_analysis.R
ADDED
|
@@ -0,0 +1,1033 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Initialize workspace.
|
| 2 |
+
## Clear workspace.
|
| 3 |
+
rm(list = ls(all = TRUE))
|
| 4 |
+
|
| 5 |
+
## Confirm working directory.
|
| 6 |
+
setwd("~/Downloads/hbg_replication")
|
| 7 |
+
|
| 8 |
+
## Set seed.
|
| 9 |
+
set.seed(123)
|
| 10 |
+
|
| 11 |
+
## Set number of iterations for bootstrap replication.
|
| 12 |
+
n_iter <- 10000
|
| 13 |
+
|
| 14 |
+
## Load relevant packages.
|
| 15 |
+
library(sandwich)
|
| 16 |
+
library(car)
|
| 17 |
+
|
| 18 |
+
## Load relevant helper functions.
|
| 19 |
+
source("scripts/helper_functions.R")
|
| 20 |
+
|
| 21 |
+
## Load data.
|
| 22 |
+
# Load experimental data.
|
| 23 |
+
tpnw <- read.csv("data/tpnw_data.csv", row.names = 1,
|
| 24 |
+
stringsAsFactors = FALSE)
|
| 25 |
+
|
| 26 |
+
# Load YouGov data.
|
| 27 |
+
aware <- read.csv("data/tpnw_aware.csv", row.names = 1,
|
| 28 |
+
stringsAsFactors = FALSE)
|
| 29 |
+
|
| 30 |
+
### Define relevant objects.
|
| 31 |
+
## Define objects specifying outcomes.
|
| 32 |
+
# Specify join_tpnw object, representing main outcome.
|
| 33 |
+
join_tpnw <- "join_tpnw"
|
| 34 |
+
|
| 35 |
+
# Specify tpnw_atts object, representing attitudinal outcomes.
|
| 36 |
+
tpnw_atts <- names(tpnw)[startsWith(names(tpnw), "tpnw_atts")]
|
| 37 |
+
|
| 38 |
+
# Specify all_outs object, concatenating main and attitudinal outcomes.
|
| 39 |
+
all_outs <- c(join_tpnw, tpnw_atts)
|
| 40 |
+
|
| 41 |
+
## Define objects specifying predictors.
|
| 42 |
+
# Define object specifying main treatments.
|
| 43 |
+
treats <- c("group_cue", "security_cue", "norms_cue", "institutions_cue")
|
| 44 |
+
|
| 45 |
+
# Define object specifying general demographics.
|
| 46 |
+
demos <- c("age", "female", "midwest", "west", "south", "income", "educ")
|
| 47 |
+
|
| 48 |
+
# Define object specifying politically relevant demographics.
|
| 49 |
+
pol_demos <- c("ideo", "pid3")
|
| 50 |
+
|
| 51 |
+
# Define list of conditioning sets (NULL corresponds to Model 1, whereas the use
|
| 52 |
+
# of demographic and political covariates corresponds to Model 2).
|
| 53 |
+
covars <- list(NULL, c(demos, pol_demos))
|
| 54 |
+
|
| 55 |
+
### Produce analysis.
|
| 56 |
+
## Produce balance table.
|
| 57 |
+
# Specify covariates to be used for balance table.
|
| 58 |
+
bal_covars <- c("age", "female", "northeast", "midwest", "west",
|
| 59 |
+
"south", "income", "educ", "ideo", "pid3")
|
| 60 |
+
|
| 61 |
+
# Produce balance table matrix output, looping over treatment group.
|
| 62 |
+
bal_mat <- lapply(0:4, function (i) {
|
| 63 |
+
# For each treatment value ...
|
| 64 |
+
apply(tpnw[bal_covars][tpnw$treatment == i,], 2, function (x) {
|
| 65 |
+
|
| 66 |
+
# Calculate the mean of each covariate.
|
| 67 |
+
mean_x <- mean(x)
|
| 68 |
+
|
| 69 |
+
# Calculate SE estimates using 10,000 bootstrap replicates.
|
| 70 |
+
sd_x <- sd(replicate(10000, {
|
| 71 |
+
samp <- x[sample(length(x), replace = TRUE)]
|
| 72 |
+
return(mean(samp))
|
| 73 |
+
}))
|
| 74 |
+
|
| 75 |
+
# Return a list containing both point estimates.
|
| 76 |
+
return(list(mean = mean_x, sd = sd_x))
|
| 77 |
+
})
|
| 78 |
+
})
|
| 79 |
+
|
| 80 |
+
# Bind point estimates for each treatment group.
|
| 81 |
+
bal_mat <- lapply(bal_mat, function (treat) {
|
| 82 |
+
do.call("rbind", unlist(treat, recursive = FALSE))
|
| 83 |
+
})
|
| 84 |
+
|
| 85 |
+
# Convert list into a matrix, with columns representing treatment group.
|
| 86 |
+
bal_mat <- do.call("cbind", bal_mat)
|
| 87 |
+
|
| 88 |
+
# Round all estimates to within three decimal points and convert to character
|
| 89 |
+
# for the purposes of producing tabular output.
|
| 90 |
+
bal_tab <- apply(bal_mat, 2, function (x) format(round(x, 3), digits = 3))
|
| 91 |
+
|
| 92 |
+
# Specify rows containing mean point estimates.
|
| 93 |
+
mean_rows <- endsWith(rownames(bal_tab), ".mean")
|
| 94 |
+
|
| 95 |
+
# Specify rows containing SE point estimates.
|
| 96 |
+
se_rows <- endsWith(rownames(bal_tab), ".sd")
|
| 97 |
+
|
| 98 |
+
# Reformat SE estimates to be within parentheses.
|
| 99 |
+
bal_tab[se_rows,] <- apply(bal_tab[se_rows,], 2, function (x) {
|
| 100 |
+
paste0("(", x, ")")
|
| 101 |
+
})
|
| 102 |
+
|
| 103 |
+
# Remove row names for rows with SE estimates.
|
| 104 |
+
rownames(bal_tab)[se_rows] <- ""
|
| 105 |
+
|
| 106 |
+
# Remove ".mean" string in row names for rows with mean estimates.
|
| 107 |
+
rownames(bal_tab)[mean_rows] <- gsub(".mean", "", rownames(bal_tab)[mean_rows])
|
| 108 |
+
|
| 109 |
+
# Concatenate data to comport with LaTeX tabular markup.
|
| 110 |
+
bal_tab <- paste(paste(paste(
|
| 111 |
+
capwords(rownames(bal_tab)), apply(bal_tab, 1, function (x) {
|
| 112 |
+
paste(x, collapse = " & ")
|
| 113 |
+
}),
|
| 114 |
+
sep = " & "), collapse = " \\\\\n"), "\\\\\n")
|
| 115 |
+
bal_tab <- gsub("\\( ", "\\(", bal_tab)
|
| 116 |
+
|
| 117 |
+
# Produce tabular output.
|
| 118 |
+
sink("output/balance_tab.tex")
|
| 119 |
+
cat("\\begin{table}\n",
|
| 120 |
+
"\\caption{Covariate Balance Across Treatment Arms}\n",
|
| 121 |
+
"\\centering\\small\n",
|
| 122 |
+
"\\sisetup{\n",
|
| 123 |
+
"\tdetect-all,\n",
|
| 124 |
+
"\ttable-number-alignment = center,\n",
|
| 125 |
+
"\ttable-figures-integer = 1,\n",
|
| 126 |
+
"\ttable-figures-decimal = 3,\n",
|
| 127 |
+
"\tinput-symbols = {()}\n",
|
| 128 |
+
"}\n",
|
| 129 |
+
paste0("\\begin{tabular}{@{\\extracolsep{5pt}}L{2.75cm}*{5}",
|
| 130 |
+
"{S[table-number-alignment = center, table-column-width = 1.75cm]}}\n"),
|
| 131 |
+
"\\toprule\n",
|
| 132 |
+
"& \\multicolumn{5}{c}{Arm}\\\\\\cmidrule{2-6}\n",
|
| 133 |
+
"& {Control} & {Group} & {Security} & {Norms} & {Institutions} \\\\\\midrule\n",
|
| 134 |
+
bal_tab,
|
| 135 |
+
"\\bottomrule\n",
|
| 136 |
+
"\\end{tabular}\n",
|
| 137 |
+
"\\end{table}\n")
|
| 138 |
+
sink()
|
| 139 |
+
|
| 140 |
+
## Produce main results.
|
| 141 |
+
# Compute main results, looping over conditioning sets.
|
| 142 |
+
main_results <- lapply(covars, function (covar) {
|
| 143 |
+
# For each conditioning set ...
|
| 144 |
+
# Specify the relevant regression formula.
|
| 145 |
+
form <- as.formula(paste(join_tpnw, paste(c(treats, covar),
|
| 146 |
+
collapse = " + "), sep = " ~ "))
|
| 147 |
+
|
| 148 |
+
# Fit the OLS model per the specification.
|
| 149 |
+
fit <- lm(form, data = tpnw)
|
| 150 |
+
|
| 151 |
+
# Compute HC2 robust standard errors.
|
| 152 |
+
ses <- sqrt(diag(vcovHC(fit, type = "HC2")))
|
| 153 |
+
|
| 154 |
+
# Bind coefficient and SE output.
|
| 155 |
+
reg_out <- cbind(fit$coef[2:5], ses[2:5])
|
| 156 |
+
|
| 157 |
+
# Name output matrix columns and rows.
|
| 158 |
+
colnames(reg_out) <- c("coef", "se")
|
| 159 |
+
rownames(reg_out) <- treats
|
| 160 |
+
|
| 161 |
+
# Return output
|
| 162 |
+
return(as.data.frame(reg_out))
|
| 163 |
+
})
|
| 164 |
+
|
| 165 |
+
# Name results to distinguish between Model 1 and Model 2 estimates.
|
| 166 |
+
names(main_results) <- c("model_1", "model_2")
|
| 167 |
+
|
| 168 |
+
## Assess significance of effect estimates and differences.
|
| 169 |
+
# Estimate Bonferroni-Holm-adjusted p-values.
|
| 170 |
+
bf_ps <- lapply(main_results, function (x) {
|
| 171 |
+
round(p.adjust(pnorm(x[, 1] / x[, 2], lower.tail = TRUE),
|
| 172 |
+
method = "holm"), 3)
|
| 173 |
+
})
|
| 174 |
+
|
| 175 |
+
# Estimate FDR-adjusted p-values, as an added robustness check.
|
| 176 |
+
fdr_ps <- lapply(main_results, function (x) {
|
| 177 |
+
round(p.adjust(pnorm(x[, 1] / x[, 2], lower.tail = TRUE),
|
| 178 |
+
method = "fdr"), 3)
|
| 179 |
+
})
|
| 180 |
+
|
| 181 |
+
# Redefine the main model (Model 2), and store full VCOV matrix.
|
| 182 |
+
main_model <- lm(join_tpnw ~ group_cue + security_cue + norms_cue +
|
| 183 |
+
institutions_cue + age + female + midwest +
|
| 184 |
+
west + south + income + educ + ideo + pid3, tpnw)
|
| 185 |
+
main_vcov <- vcovHC(main_model, "HC2")
|
| 186 |
+
|
| 187 |
+
# Specify diff_sig function for assessing significance between two effect
|
| 188 |
+
# estimates (defined here for the sake of clarity).
|
| 189 |
+
diff_sig <- function (eff_1, eff_2) {
|
| 190 |
+
diff <- main_model$coef[eff_1] - main_model$coef[eff_2]
|
| 191 |
+
se <- sqrt(main_vcov[eff_1, eff_1] + main_vcov[eff_2, eff_2] -
|
| 192 |
+
2 * main_vcov[eff_1, eff_2])
|
| 193 |
+
p <- 2 * (1 - pnorm(abs(diff) / se))
|
| 194 |
+
return (p)
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
# Assess the significance of the difference between institution and security cue
|
| 198 |
+
# effect estimates .
|
| 199 |
+
inst_sec_diff_p <- diff_sig("institutions_cue", "security_cue")
|
| 200 |
+
|
| 201 |
+
# Assess the significance of the difference between institution and group cue
|
| 202 |
+
# effect estimates
|
| 203 |
+
inst_grp_diff_p <- diff_sig("institutions_cue", "group_cue")
|
| 204 |
+
|
| 205 |
+
# Assess the significance of the difference between security and group cue
|
| 206 |
+
# effect estimates
|
| 207 |
+
sec_grp_diff_p <- diff_sig("security_cue", "group_cue")
|
| 208 |
+
|
| 209 |
+
# Assess the significance of the difference between security and norms cue
|
| 210 |
+
# effect estimates
|
| 211 |
+
sec_norms_diff_p <- diff_sig("security_cue", "norms_cue")
|
| 212 |
+
|
| 213 |
+
# Assess the significance of the difference between institution and group cue
|
| 214 |
+
# effect estimates
|
| 215 |
+
inst_norms_diff_p <- diff_sig("institutions_cue", "norms_cue")
|
| 216 |
+
|
| 217 |
+
# Assess the significance of the difference between institution and group cue
|
| 218 |
+
# effect estimates
|
| 219 |
+
grp_norms_diff_p <- diff_sig("group_cue", "norms_cue")
|
| 220 |
+
|
| 221 |
+
# The significance of differences between effect estimates was also assessed
|
| 222 |
+
# using 10,000 bootstrap replicates and two-tailed p-values; relevant code is
|
| 223 |
+
# included below with the institutions and security cues, for posterity, but is
|
| 224 |
+
# not run.
|
| 225 |
+
|
| 226 |
+
# Compute SE estimates.
|
| 227 |
+
# diffs <- replicate(10000, {
|
| 228 |
+
# samp <- tpnw[sample(nrow(tpnw), replace = TRUE),]
|
| 229 |
+
# model <- lm(join_tpnw ~ group_cue + security_cue + norms_cue +
|
| 230 |
+
# institutions_cue + age + female + midwest +
|
| 231 |
+
# west + south + income + educ + ideo + pid3, samp)
|
| 232 |
+
# model$coef[5] - model$coef[3]
|
| 233 |
+
# })
|
| 234 |
+
# diffs_se <- sd(diffs)
|
| 235 |
+
#
|
| 236 |
+
# # Fit model.
|
| 237 |
+
# model <- lm(join_tpnw ~ group_cue + security_cue + norms_cue +
|
| 238 |
+
# institutions_cue + age + female + midwest +
|
| 239 |
+
# west + south + income + educ + ideo + pid3, tpnw)
|
| 240 |
+
#
|
| 241 |
+
# # Compute two-tailed p-value.
|
| 242 |
+
# 2 * (1 - pnorm(abs((model$coef[5] - model$coef[3])/diffs_se)))
|
| 243 |
+
|
| 244 |
+
## Assess YouGov results.
|
| 245 |
+
# Tabulate responses.
|
| 246 |
+
aware_table <- table(aware$awareness, useNA = "ifany")
|
| 247 |
+
names(aware_table) <- c("Yes, support", "Yes, oppose",
|
| 248 |
+
"No, support", "No, oppose", "Skipped")
|
| 249 |
+
|
| 250 |
+
# Compute both weighted and unweighted means.
|
| 251 |
+
aware_results <- lapply(1:4, function (resp) {
|
| 252 |
+
# Calculate weighted mean.
|
| 253 |
+
wt_mean <- with(aware, weighted.mean(awareness == resp,
|
| 254 |
+
w = weight, na.rm = TRUE))
|
| 255 |
+
|
| 256 |
+
# Calculate raw mean.
|
| 257 |
+
rw_mean <- with(aware, mean(awareness == resp, na.rm = TRUE))
|
| 258 |
+
|
| 259 |
+
# Concatenate means and rename vector.
|
| 260 |
+
means <- c(wt_mean, rw_mean)
|
| 261 |
+
names(means) <- c("weighted_mean", "raw_mean")
|
| 262 |
+
|
| 263 |
+
# Calculate SE estimates with 10,000 bootstrap replicates.
|
| 264 |
+
ses <- replicate(10000, {
|
| 265 |
+
samp <- aware[sample(nrow(aware),
|
| 266 |
+
replace = TRUE),]
|
| 267 |
+
wt_mean <- with(samp, weighted.mean(awareness == resp,
|
| 268 |
+
w = weight, na.rm = TRUE))
|
| 269 |
+
rw_mean <- with(samp, mean(awareness == resp,
|
| 270 |
+
na.rm = TRUE))
|
| 271 |
+
return(c(wt_mean, rw_mean))
|
| 272 |
+
})
|
| 273 |
+
ses <- apply(ses, 1, sd)
|
| 274 |
+
names(ses) <- c("weighted_mean", "raw_mean")
|
| 275 |
+
|
| 276 |
+
# Bind mean and SE estimates.
|
| 277 |
+
outs <- rbind(means, ses)
|
| 278 |
+
rownames(outs) <- paste(names(aware_table)[resp],
|
| 279 |
+
c("mean", "se"), sep = "_")
|
| 280 |
+
return(outs)
|
| 281 |
+
})
|
| 282 |
+
|
| 283 |
+
# Name results to distinguish between responses.
|
| 284 |
+
names(aware_results) <- c("Yes, support", "Yes, oppose",
|
| 285 |
+
"No, support", "No, oppose")
|
| 286 |
+
|
| 287 |
+
## Assess covariate means for experimental and YouGov data (used in Table A1).
|
| 288 |
+
# Indicate the list of covariates to be assessed.
|
| 289 |
+
demo_tab_vars <- c("age", "female", "northeast", "midwest", "west", "south")
|
| 290 |
+
|
| 291 |
+
# Compute covariate averages for experimental data.
|
| 292 |
+
tpnw_means <- apply(tpnw[demo_tab_vars], 2, mean, na.rm = TRUE)
|
| 293 |
+
|
| 294 |
+
# Compute covariate averages for YouGov data.
|
| 295 |
+
aware_means <- apply(aware[demo_tab_vars], 2, function (x) {
|
| 296 |
+
weighted.mean(x, na.rm = TRUE, w = aware$weight)
|
| 297 |
+
})
|
| 298 |
+
|
| 299 |
+
# Compute bootstrap standard errors for demographic means.
|
| 300 |
+
demo_ses <- replicate(10000, {
|
| 301 |
+
# Sample the experimental data.
|
| 302 |
+
samp_tpnw <- tpnw[sample(nrow(tpnw), replace = TRUE), demo_tab_vars]
|
| 303 |
+
|
| 304 |
+
# Sample the YouGov data.
|
| 305 |
+
samp_aware <- aware[sample(nrow(aware), replace = TRUE),
|
| 306 |
+
c(demo_tab_vars, "weight")]
|
| 307 |
+
|
| 308 |
+
# Compute bootstrap means for experimental data.
|
| 309 |
+
tpnw_means <- apply(samp_tpnw[demo_tab_vars], 2, mean, na.rm = TRUE)
|
| 310 |
+
|
| 311 |
+
# Compute bootstrap means for YouGov data.
|
| 312 |
+
aware_means <- apply(samp_aware[demo_tab_vars], 2, function (x) {
|
| 313 |
+
weighted.mean(x, na.rm = TRUE, w = samp_aware$weight)
|
| 314 |
+
})
|
| 315 |
+
|
| 316 |
+
# Return the results as a list, and ensure that replicate() also returns a
|
| 317 |
+
# list.
|
| 318 |
+
return(list(tpnw = tpnw_means, aware = aware_means))
|
| 319 |
+
}, simplify = FALSE)
|
| 320 |
+
|
| 321 |
+
# Compute SE estimates for each set of demographics.
|
| 322 |
+
demo_ses <- lapply(c("tpnw", "aware"), function (dataset) {
|
| 323 |
+
# Group all estimates from each dataset.
|
| 324 |
+
sep_res <- lapply(demo_ses, function (iteration) {
|
| 325 |
+
return(iteration[[dataset]])
|
| 326 |
+
})
|
| 327 |
+
|
| 328 |
+
# Bind estimates.
|
| 329 |
+
sep_res <- do.call("rbind", sep_res)
|
| 330 |
+
|
| 331 |
+
# Compute SE estimates.
|
| 332 |
+
sep_ses <- apply(sep_res, 2, sd)
|
| 333 |
+
|
| 334 |
+
# Return SE estimates.
|
| 335 |
+
return(sep_ses)
|
| 336 |
+
})
|
| 337 |
+
|
| 338 |
+
## Assess responses to the attitudinal battery.
|
| 339 |
+
# Assess responses to the attitudinal battery, looping over treatment group. For
|
| 340 |
+
# each treatment value ...
|
| 341 |
+
att_results <- lapply(0:4, function (i) {
|
| 342 |
+
# Calculate the average response to each attitudinal battery question.
|
| 343 |
+
atts_mean <- apply(tpnw[tpnw$treatment == i, tpnw_atts], 2, function (x) {
|
| 344 |
+
mean(x, na.rm = TRUE)
|
| 345 |
+
})
|
| 346 |
+
|
| 347 |
+
# Calculate SE estimates using 10,000 bootstrap replicates.
|
| 348 |
+
bl_atts_boot <- replicate(10000, {
|
| 349 |
+
dat <- tpnw[tpnw$treatment == i, tpnw_atts]
|
| 350 |
+
samp <- dat[sample(nrow(dat), replace = TRUE),]
|
| 351 |
+
apply(samp, 2, function (x) mean(x, na.rm = TRUE))
|
| 352 |
+
})
|
| 353 |
+
bl_atts_ses <- apply(bl_atts_boot, 1, sd)
|
| 354 |
+
|
| 355 |
+
# Combine mean and SE estimates and return results.
|
| 356 |
+
return(cbind(atts_mean, bl_atts_ses))
|
| 357 |
+
})
|
| 358 |
+
|
| 359 |
+
# Compute treatment effects on responses to the attitudinal battery, looping
|
| 360 |
+
# over conditioning sets.
|
| 361 |
+
att_effs <- lapply(covars, function (covar) {
|
| 362 |
+
# For each conditioning set ...
|
| 363 |
+
model_res <- lapply(tpnw_atts, function (out) {
|
| 364 |
+
# Specify the relevant regression formula.
|
| 365 |
+
form <- as.formula(paste(out,
|
| 366 |
+
paste(c(treats, covar),
|
| 367 |
+
collapse = " + "),
|
| 368 |
+
sep = " ~ "))
|
| 369 |
+
|
| 370 |
+
# Fit the OLS model per the specification.
|
| 371 |
+
fit <- lm(form, data = tpnw)
|
| 372 |
+
|
| 373 |
+
# Compute HC2 robust standard errors.
|
| 374 |
+
ses <- sqrt(diag(vcovHC(fit, type = "HC2")))
|
| 375 |
+
|
| 376 |
+
# Bind coefficient and SE output.
|
| 377 |
+
reg_out <- cbind(fit$coef[2:5], ses[2:5])
|
| 378 |
+
|
| 379 |
+
# Name output matrix columns and rows.
|
| 380 |
+
colnames(reg_out) <- c("coef", "se")
|
| 381 |
+
rownames(reg_out) <- treats
|
| 382 |
+
|
| 383 |
+
# Return output.
|
| 384 |
+
return(as.data.frame(reg_out))
|
| 385 |
+
})
|
| 386 |
+
# Name results to distinguish between each attitudinal battery
|
| 387 |
+
# outcome and return results.
|
| 388 |
+
names(model_res) <- tpnw_atts
|
| 389 |
+
return(model_res)
|
| 390 |
+
})
|
| 391 |
+
|
| 392 |
+
# Name results to distinguish between Model 1 and Model 2 estimates.
|
| 393 |
+
names(att_effs) <- c("model_1", "model_2")
|
| 394 |
+
|
| 395 |
+
## Perform subgroup analysis.
|
| 396 |
+
# Compute mean support by political party, looping over treatment group.
|
| 397 |
+
pid_results <- lapply(0:4, function (treat) {
|
| 398 |
+
# For each partisan group ...
|
| 399 |
+
out <- lapply(-1:1, function (i) {
|
| 400 |
+
# Calculate average support.
|
| 401 |
+
pid_mean <- with(tpnw,
|
| 402 |
+
mean(join_tpnw[pid3 == i &
|
| 403 |
+
treatment == treat],
|
| 404 |
+
na.rm = TRUE))
|
| 405 |
+
|
| 406 |
+
# Calculate SE estimates with 10,000
|
| 407 |
+
# bootstrap replicates.
|
| 408 |
+
pid_boot <- replicate(10000, {
|
| 409 |
+
dat <- tpnw$join_tpnw[tpnw$pid3 == i &
|
| 410 |
+
tpnw$treatment == treat]
|
| 411 |
+
samp <- dat[sample(length(dat),
|
| 412 |
+
replace = TRUE)]
|
| 413 |
+
mean(samp, na.rm = TRUE)
|
| 414 |
+
})
|
| 415 |
+
|
| 416 |
+
# Concatenate and return mean and SE
|
| 417 |
+
# estimates.
|
| 418 |
+
return(c(mean = pid_mean, se = sd(pid_boot)))
|
| 419 |
+
})
|
| 420 |
+
|
| 421 |
+
# Name results to distinguish estimates by political party,
|
| 422 |
+
# and return output.
|
| 423 |
+
names(out) <- c("dem", "ind", "rep")
|
| 424 |
+
return(as.data.frame(out))
|
| 425 |
+
})
|
| 426 |
+
|
| 427 |
+
# Name results to distinguish between treatment groups.
|
| 428 |
+
names(pid_results) <- c("Control", paste(c("Group", "Security", "Norms",
|
| 429 |
+
"Institutions"), "Cue"))
|
| 430 |
+
|
| 431 |
+
# Assess significance between control-group means; for 10,000 bootstrap
|
| 432 |
+
# replicates ...
|
| 433 |
+
pid_diff_ses <- replicate(10000, {
|
| 434 |
+
# Sample with replacement.
|
| 435 |
+
samp <- tpnw[sample(nrow(tpnw), replace = TRUE),]
|
| 436 |
+
|
| 437 |
+
# Compute the difference between Democrats' and
|
| 438 |
+
# Independents' support.
|
| 439 |
+
dem_ind_diff <- with(samp[samp$treatment == 0,],
|
| 440 |
+
mean(join_tpnw[pid3 == -1],
|
| 441 |
+
na.rm = TRUE) -
|
| 442 |
+
mean(join_tpnw[pid3 == 0],
|
| 443 |
+
na.rm = TRUE))
|
| 444 |
+
# Compute the difference between Democrats' and
|
| 445 |
+
# Republicans' support.
|
| 446 |
+
dem_rep_diff <- with(samp[samp$treatment == 0,],
|
| 447 |
+
mean(join_tpnw[pid3 == -1],
|
| 448 |
+
na.rm = TRUE) -
|
| 449 |
+
mean(join_tpnw[pid3 == 1],
|
| 450 |
+
na.rm = TRUE))
|
| 451 |
+
# Compute the difference between Independents' and
|
| 452 |
+
# Republicans' support.
|
| 453 |
+
ind_rep_diff <- with(samp[samp$treatment == 0,],
|
| 454 |
+
mean(join_tpnw[pid3 == 1],
|
| 455 |
+
na.rm = TRUE) -
|
| 456 |
+
mean(join_tpnw[pid3 == 0],
|
| 457 |
+
na.rm = TRUE))
|
| 458 |
+
|
| 459 |
+
# Concatenate and name results.
|
| 460 |
+
out <- c(dem_ind_diff, dem_rep_diff, ind_rep_diff)
|
| 461 |
+
names(out) <- c("dem_ind", "dem_rep", "ind_rep")
|
| 462 |
+
return(out)
|
| 463 |
+
})
|
| 464 |
+
|
| 465 |
+
# Compute SE estimates for each difference.
|
| 466 |
+
pid_diff_ses <- apply(pid_diff_ses, 1, sd)
|
| 467 |
+
|
| 468 |
+
# Assess significance for each difference.
|
| 469 |
+
dem_ind_p <- 2 * (1 - pnorm(abs(pid_results$Control["mean", "dem"] -
|
| 470 |
+
pid_results$Control["mean", "ind"]) / pid_diff_ses["dem_ind"]))
|
| 471 |
+
dem_rep_p <- 2 * (1 - pnorm(abs(pid_results$Control["mean", "dem"] -
|
| 472 |
+
pid_results$Control["mean", "rep"]) / pid_diff_ses["dem_rep"]))
|
| 473 |
+
ind_rep_p <- 2 * (1 - pnorm(abs(pid_results$Control["mean", "ind"] -
|
| 474 |
+
pid_results$Control["mean", "rep"]) / pid_diff_ses["ind_rep"]))
|
| 475 |
+
|
| 476 |
+
# Compute mean support by political ideology, looping over treatment group.
|
| 477 |
+
tpnw$ideo <- recode(tpnw$ideo, "c(-2, -1) = 'liberal';
|
| 478 |
+
0 = 'moderate';
|
| 479 |
+
c(1, 2) = 'conservative'")
|
| 480 |
+
ideo_results <- lapply(0:4, function (treat) {
|
| 481 |
+
# For each ideological group ...
|
| 482 |
+
out <- lapply(c("liberal", "moderate", "conservative"), function (i) {
|
| 483 |
+
# Calculate average support.
|
| 484 |
+
pid_mean <- with(tpnw,
|
| 485 |
+
mean(join_tpnw[ideo == i &
|
| 486 |
+
treatment == treat],
|
| 487 |
+
na.rm = TRUE))
|
| 488 |
+
|
| 489 |
+
# Calculate SE estimates with 10,000
|
| 490 |
+
# bootstrap replicates.
|
| 491 |
+
pid_boot <- replicate(10000, {
|
| 492 |
+
dat <- tpnw$join_tpnw[tpnw$ideo == i &
|
| 493 |
+
tpnw$treatment == treat]
|
| 494 |
+
samp <- dat[sample(length(dat),
|
| 495 |
+
replace = TRUE)]
|
| 496 |
+
mean(samp, na.rm = TRUE)
|
| 497 |
+
})
|
| 498 |
+
|
| 499 |
+
# Concatenate and return mean and SE
|
| 500 |
+
# estimates.
|
| 501 |
+
return(c(mean = pid_mean, se = sd(pid_boot)))
|
| 502 |
+
})
|
| 503 |
+
|
| 504 |
+
# Name results to distinguish estimates by political ideology,
|
| 505 |
+
# and return output.
|
| 506 |
+
names(out) <- c("liberal", "moderate", "conservative")
|
| 507 |
+
return(as.data.frame(out))
|
| 508 |
+
})
|
| 509 |
+
|
| 510 |
+
# Name results to distinguish between treatment groups.
|
| 511 |
+
names(ideo_results) <- c("Control", paste(c("Group", "Security", "Norms",
|
| 512 |
+
"Institutions"), "Cue"))
|
| 513 |
+
|
| 514 |
+
## Produce weighted main results.
|
| 515 |
+
# Compute weighted main results, looping over conditioning sets.
|
| 516 |
+
w_main_results <- lapply(covars, function (covar) {
|
| 517 |
+
# For each conditioning set ...
|
| 518 |
+
# Specify the relevant regression formula.
|
| 519 |
+
form <- as.formula(paste(join_tpnw, paste(c(treats, covar),
|
| 520 |
+
collapse = " + "), sep = " ~ "))
|
| 521 |
+
|
| 522 |
+
# Fit the OLS model per the specification.
|
| 523 |
+
fit <- lm(form, data = tpnw, weights = anesrake_weight)
|
| 524 |
+
|
| 525 |
+
# Compute HC2 robust standard errors.
|
| 526 |
+
ses <- sqrt(diag(vcovHC(fit, type = "HC2")))
|
| 527 |
+
|
| 528 |
+
# Bind coefficient and SE output.
|
| 529 |
+
reg_out <- cbind(fit$coef[2:5], ses[2:5])
|
| 530 |
+
|
| 531 |
+
# Name output matrix columns and rows.
|
| 532 |
+
colnames(reg_out) <- c("coef", "se")
|
| 533 |
+
rownames(reg_out) <- treats
|
| 534 |
+
|
| 535 |
+
# Return output
|
| 536 |
+
return(as.data.frame(reg_out))
|
| 537 |
+
})
|
| 538 |
+
|
| 539 |
+
# Name results to distinguish between Model 1 and Model 2 estimates.
|
| 540 |
+
names(w_main_results) <- c("model_1", "model_2")
|
| 541 |
+
|
| 542 |
+
### Produce plots and tables.
|
| 543 |
+
## Produce main results plot.
|
| 544 |
+
# Produce main results matrix for plotting.
|
| 545 |
+
main_mat <- do.call("rbind", lapply(1:2, function (model) {
|
| 546 |
+
cbind(main_results[[model]], model)
|
| 547 |
+
}))
|
| 548 |
+
|
| 549 |
+
# Store values for constructing 90- and 95-percent CIs.
|
| 550 |
+
z_90 <- qnorm(.95)
|
| 551 |
+
z_95 <- qnorm(.975)
|
| 552 |
+
|
| 553 |
+
# Open new pdf device.
|
| 554 |
+
setEPS()
|
| 555 |
+
postscript("output/fg1.eps", width = 8, height = 5.5)
|
| 556 |
+
|
| 557 |
+
# Define custom graphical parameters.
|
| 558 |
+
par(mar = c(8, 7, 2, 2))
|
| 559 |
+
|
| 560 |
+
# Open new, empty plot.
|
| 561 |
+
plot(0, type = "n", axes = FALSE, ann = FALSE,
|
| 562 |
+
xlim = c(-.3, .05), ylim = c(.8, 4))
|
| 563 |
+
|
| 564 |
+
# Produce guidelines to go behind point estimates and error bars.
|
| 565 |
+
abline(v = seq(-.3, .05, .05)[-7], col = "lightgrey", lty = 3)
|
| 566 |
+
|
| 567 |
+
# Add Model 1 point estimates.
|
| 568 |
+
par(new = TRUE)
|
| 569 |
+
plot(x = main_mat$coef[main_mat$model == 1], y = 1:4 + .05,
|
| 570 |
+
xlim = c(-.3, .05), ylim = c(.8, 4), pch = 16, col = "steelblue2",
|
| 571 |
+
xlab = "", ylab = "", axes = FALSE)
|
| 572 |
+
|
| 573 |
+
# Add Model 2 point estimates.
|
| 574 |
+
par(new = TRUE)
|
| 575 |
+
plot(x = main_mat$coef[main_mat$model == 2], y = 1:4 - .05,
|
| 576 |
+
xlim = c(-.3, .05), ylim = c(.8, 4), pch = 16, col = "#FF8F37", main = "",
|
| 577 |
+
xlab = "", ylab = "", axes = FALSE)
|
| 578 |
+
|
| 579 |
+
# Add horizontal axis indicating effect estimate size.
|
| 580 |
+
axis(side = 1, at = round(seq(-.3, 0, .05), 2), labels = FALSE)
|
| 581 |
+
mtext(side = 1, at = seq(-.3, .1, .1), text = c("-30", "-20", "-10", "0"),
|
| 582 |
+
cex = .9, line = .75)
|
| 583 |
+
axis(side = 1, at = round(seq(-.25, .05, .05), 2), tck = -.01, labels = FALSE)
|
| 584 |
+
|
| 585 |
+
# Add vertical axis specifying treatment names corresponding to point estimates.
|
| 586 |
+
axis(side = 2, at = 1:4, labels = FALSE)
|
| 587 |
+
mtext(side = 2, line = .75, at = 1:4,
|
| 588 |
+
text = paste(c("Group", "Security", "Norms", "Institutions"), "Cue"),
|
| 589 |
+
las = 1, padj = .35, cex = .9)
|
| 590 |
+
|
| 591 |
+
# Add axis labels.
|
| 592 |
+
mtext(side = 2, line = 2.3, at = 4.2, text = "Treatment",
|
| 593 |
+
font = 2, las = 1, xpd = TRUE)
|
| 594 |
+
mtext(side = 1, text = "Estimated Effect Size", line = 2.5, at = -.15, font = 2)
|
| 595 |
+
|
| 596 |
+
# Add a dashed line at zero.
|
| 597 |
+
abline(v = 0.00, lty = 2)
|
| 598 |
+
|
| 599 |
+
# Add two-sided, 90-percent CIs.
|
| 600 |
+
with(main_mat[main_mat$model == 1,],
|
| 601 |
+
segments(x0 = coef - z_90 * se, y0 = 1:4 + .05, x1 = coef + z_90 * se,
|
| 602 |
+
y1 = 1:4 + .05, col = "steelblue2", lwd = 3))
|
| 603 |
+
with(main_mat[main_mat$model == 2,],
|
| 604 |
+
segments(x0 = coef - z_90 * se, y0 = 1:4 - .05, x1 = coef + z_90 * se,
|
| 605 |
+
y1 = 1:4 - .05, col = "#FF8F37", lwd = 3))
|
| 606 |
+
|
| 607 |
+
# Add two-sided 95-percent CIs.
|
| 608 |
+
with(main_mat[main_mat$model == 1,],
|
| 609 |
+
segments(x0 = coef - z_95 *se, y0 = 1:4 + .05, x1 = coef + z_95 *se,
|
| 610 |
+
y1 = 1:4 + .05, col = "steelblue2", lwd = 1))
|
| 611 |
+
with(main_mat[main_mat$model == 2,],
|
| 612 |
+
segments(x0 = coef - z_95 *se, y0 = 1:4 - .05, x1 = coef + z_95 *se,
|
| 613 |
+
y1 = 1:4 - .05, col = "#FF8F37", lwd = 1))
|
| 614 |
+
|
| 615 |
+
# Add legend.
|
| 616 |
+
legend(legend = paste("Model", 1:2), x = -.15, y = -.275, horiz = TRUE,
|
| 617 |
+
pch = 16, col = c("steelblue2", "#FF8F37"), xjust = .5, xpd = TRUE,
|
| 618 |
+
text.width = .05, cex = .9)
|
| 619 |
+
|
| 620 |
+
# Draw a box around the plot.
|
| 621 |
+
box()
|
| 622 |
+
|
| 623 |
+
# Close the grpahical device.
|
| 624 |
+
dev.off()
|
| 625 |
+
|
| 626 |
+
## Create tabular output for main results.
|
| 627 |
+
# Define matrix object of main results.
|
| 628 |
+
tab_dat <- do.call("cbind", main_results)
|
| 629 |
+
|
| 630 |
+
# Compute control-group means, with SE estimates; define OLS formula.
|
| 631 |
+
ctrl_form <- as.formula(paste(join_tpnw, paste(treats,
|
| 632 |
+
collapse = " + "), sep = " ~ "))
|
| 633 |
+
|
| 634 |
+
# Fit the OLS model per the specification and recover the control mean.
|
| 635 |
+
ctrl_fit <- lm(ctrl_form, data = tpnw)
|
| 636 |
+
|
| 637 |
+
# Recover the control-group mean.
|
| 638 |
+
ctrl_mean <- ctrl_fit$coef["(Intercept)"]
|
| 639 |
+
|
| 640 |
+
# Compute control SE.
|
| 641 |
+
ctrl_se <- sqrt(diag(vcovHC(ctrl_fit, "HC2")))["(Intercept)"]
|
| 642 |
+
|
| 643 |
+
# Concatenate mean and SE output with blank values for Model 2.
|
| 644 |
+
ctrl_results <- c(format(round(c(ctrl_mean, ctrl_se), 3) * 100, digits = 2),
|
| 645 |
+
"|", "|")
|
| 646 |
+
|
| 647 |
+
# Reformat data to include a decimal point.
|
| 648 |
+
tab_dat <- apply(tab_dat, 2, function (y) format(round(y, 3) * 100, digits = 2))
|
| 649 |
+
|
| 650 |
+
# Bind control-group means with main results data.
|
| 651 |
+
tab <- rbind(ctrl_results, tab_dat)
|
| 652 |
+
|
| 653 |
+
# Rename row containing control-group means.
|
| 654 |
+
rownames(tab)[which(rownames(tab) == "1")] <- "control_mean"
|
| 655 |
+
|
| 656 |
+
# Relabel coefficient columns.
|
| 657 |
+
coef_cols <- grep("coef$", colnames(tab))
|
| 658 |
+
|
| 659 |
+
# Relabel SE columns.
|
| 660 |
+
se_cols <- grep("se$", colnames(tab))
|
| 661 |
+
|
| 662 |
+
# Reformat SE estimates to be within parentheses.
|
| 663 |
+
tab[,se_cols] <- apply(tab[, se_cols], 2, function (y) paste0("(", y, ")"))
|
| 664 |
+
|
| 665 |
+
# Concatenate data to comport with LaTeX tabular markup.
|
| 666 |
+
tab <- paste(paste(paste(capwords(gsub("_", " ", rownames(tab))),
|
| 667 |
+
apply(tab, 1, function (x) {
|
| 668 |
+
paste(x, collapse = " & ")
|
| 669 |
+
}), sep = " & "), collapse = " \\\\\n"), "\\\\\n")
|
| 670 |
+
|
| 671 |
+
# Produce tabular output.
|
| 672 |
+
sink("output/main_results_tab.tex")
|
| 673 |
+
cat("\\begin{table}\n",
|
| 674 |
+
"\\caption{Estimated Treatment Effects on Support for TPNW}\n",
|
| 675 |
+
"\\begin{adjustbox}{width = \\textwidth, center}\n",
|
| 676 |
+
"\\sisetup{\n",
|
| 677 |
+
"\tdetect-all,\n",
|
| 678 |
+
"\ttable-number-alignment = center,\n",
|
| 679 |
+
"\ttable-figures-integer = 1,\n",
|
| 680 |
+
"\ttable-figures-decimal = 3,\n",
|
| 681 |
+
"\ttable-space-text-post = *,\n",
|
| 682 |
+
"\tinput-symbols = {()}\n",
|
| 683 |
+
"}\n",
|
| 684 |
+
paste0("\\begin{tabular}{@{\\extracolsep{5pt}}L{3.5cm}*{4}",
|
| 685 |
+
"{S[table-number-alignment = right, table-column-width=1.25cm]}}\n"),
|
| 686 |
+
"\\toprule\n",
|
| 687 |
+
"& \\multicolumn{4}{c}{Model}\\\\\\cmidrule{2-5}\n",
|
| 688 |
+
"& \\multicolumn{2}{c}{{(1)}} & \\multicolumn{2}{c}{{(2)}} \\\\\\midrule\n",
|
| 689 |
+
tab,
|
| 690 |
+
"\\bottomrule\n",
|
| 691 |
+
"\\end{tabular}\n",
|
| 692 |
+
"\\end{adjustbox}\n",
|
| 693 |
+
"\\end{table}\n")
|
| 694 |
+
sink()
|
| 695 |
+
|
| 696 |
+
## Create tabular output for YouGov results.
|
| 697 |
+
# Restructure data as a matrix.
|
| 698 |
+
aware_tab <- rbind(do.call("rbind", aware_results))
|
| 699 |
+
|
| 700 |
+
# Reformat data to include three decimal points.
|
| 701 |
+
aware_tab <- apply(aware_tab, 2, function (y) format(round(y, 3) * 100,
|
| 702 |
+
digits = 3))
|
| 703 |
+
|
| 704 |
+
# Relabel mean rows.
|
| 705 |
+
mean_rows <- endsWith(rownames(aware_tab), "mean")
|
| 706 |
+
|
| 707 |
+
# Relabel SE rows.
|
| 708 |
+
se_rows <- endsWith(rownames(aware_tab), "se")
|
| 709 |
+
|
| 710 |
+
# Reformat SE estimates to be within parentheses.
|
| 711 |
+
aware_tab[se_rows,] <- paste0("(", aware_tab[se_rows,], ")")
|
| 712 |
+
|
| 713 |
+
# Remove row names for rows with SE estimates.
|
| 714 |
+
rownames(aware_tab)[se_rows] <- ""
|
| 715 |
+
|
| 716 |
+
# Remove "_mean" indication in mean_rows.
|
| 717 |
+
rownames(aware_tab)[mean_rows] <- gsub("_mean", "",
|
| 718 |
+
rownames(aware_tab)[mean_rows])
|
| 719 |
+
|
| 720 |
+
# Add an empty row, where excluded calculations of responses among skips are
|
| 721 |
+
# noted in the table, and rename the relevant row.
|
| 722 |
+
aware_tab <- rbind(aware_tab, c("|", "|"))
|
| 723 |
+
rownames(aware_tab)[nrow(aware_tab)] <- "Skipped"
|
| 724 |
+
|
| 725 |
+
# Add an empty column to the table, and insert the count column at the relevant
|
| 726 |
+
# indices.
|
| 727 |
+
aware_tab[which(rownames(aware_tab) %in% names(aware_table)),]
|
| 728 |
+
aware_tab <- cbind(aware_tab, "")
|
| 729 |
+
colnames(aware_tab)[ncol(aware_tab)] <- "N"
|
| 730 |
+
aware_tab[which(rownames(aware_tab) %in% names(aware_table)), "N"] <- aware_table
|
| 731 |
+
|
| 732 |
+
# Concatenate data to comport with LaTeX tabular markup.
|
| 733 |
+
aware_tab <- paste(paste(paste(capwords(gsub("_", " ", rownames(aware_tab))),
|
| 734 |
+
apply(aware_tab, 1, function (x) {
|
| 735 |
+
paste(x, collapse = " & ")
|
| 736 |
+
}),
|
| 737 |
+
sep = " & "), collapse = " \\\\\n"), "\\\\\n")
|
| 738 |
+
|
| 739 |
+
# Produce tabular output.
|
| 740 |
+
sink("output/yougov_tab.tex")
|
| 741 |
+
cat("\\begin{table}\n",
|
| 742 |
+
"\\caption{YouGov Survey Responses}\n",
|
| 743 |
+
"\\centering\\small\n",
|
| 744 |
+
"\\sisetup{\n",
|
| 745 |
+
"\tdetect-all,\n",
|
| 746 |
+
"\ttable-number-alignment = center,\n",
|
| 747 |
+
"\ttable-figures-integer = 1,\n",
|
| 748 |
+
"\ttable-figures-decimal = 3,\n",
|
| 749 |
+
"\tinput-symbols = {()}\n",
|
| 750 |
+
"}\n",
|
| 751 |
+
paste0("\\begin{tabular}{@{\\extracolsep{5pt}}L{3.5cm}*{5}",
|
| 752 |
+
"{S[table-number-alignment = right, table-column-width=1.25cm]}}\n"),
|
| 753 |
+
"\\toprule\n",
|
| 754 |
+
"& \\multicolumn{5}{c}{Arm}\\\\\\cmidrule{2-6}\n",
|
| 755 |
+
"& {Control} & {Group} & {Security} & {Norms} & {Institutions} \\\\\\midrule\n",
|
| 756 |
+
aware_tab,
|
| 757 |
+
"\\bottomrule\n",
|
| 758 |
+
"\\end{tabular}\n",
|
| 759 |
+
"\\end{table}\n")
|
| 760 |
+
sink()
|
| 761 |
+
|
| 762 |
+
## Create tabular output for attitudinal results.
|
| 763 |
+
# Define matrix object of main results.
|
| 764 |
+
tab_dat <- do.call("cbind", att_results)
|
| 765 |
+
|
| 766 |
+
# Reformat matrix to alternate mean and SE estimates.
|
| 767 |
+
tab <- sapply(seq(0, 8, 2), function (i) {
|
| 768 |
+
matrix(c(t(tab_dat[,1:2 + i])), 14, 1)
|
| 769 |
+
})
|
| 770 |
+
|
| 771 |
+
# Reformat data to include three decimal points.
|
| 772 |
+
tab <- apply(tab, 2, function (y) format(round(y, 3), digits = 3))
|
| 773 |
+
|
| 774 |
+
# Rename rows to indicate mean and SE estimates.
|
| 775 |
+
rownames(tab) <- paste(rep(rownames(tab_dat), each = 2),
|
| 776 |
+
c("mean", "se"), sep = "_")
|
| 777 |
+
|
| 778 |
+
# Relabel mean rows.
|
| 779 |
+
mean_rows <- grep("_mean", rownames(tab))
|
| 780 |
+
|
| 781 |
+
# Relabel SE rows
|
| 782 |
+
se_rows <- grep("_se", rownames(tab))
|
| 783 |
+
|
| 784 |
+
# Reformat SE estimates to be within parentheses.
|
| 785 |
+
tab[se_rows,] <- apply(tab[se_rows,], 1, function (y) {
|
| 786 |
+
paste0("(", gsub(" ", "", y), ")")
|
| 787 |
+
})
|
| 788 |
+
|
| 789 |
+
# Rename rows to improve tabular labels; remove "tpnw_atts, "mean," and "se" row
|
| 790 |
+
# name strings.
|
| 791 |
+
rownames(tab) <- gsub("tpnw_atts|mean$|se$", "", rownames(tab))
|
| 792 |
+
|
| 793 |
+
# Remove leading and tailing underscores.
|
| 794 |
+
rownames(tab) <- gsub("^_|_$", "", rownames(tab))
|
| 795 |
+
|
| 796 |
+
# Remove row names for rows with SE estimates.
|
| 797 |
+
rownames(tab)[se_rows] <- ""
|
| 798 |
+
|
| 799 |
+
# Concatenate data to comport with LaTeX tabular markup.
|
| 800 |
+
tab <- paste(paste(paste(capwords(gsub("_", " ", rownames(tab))),
|
| 801 |
+
apply(tab, 1, function (x) {
|
| 802 |
+
paste(x, collapse = " & ")
|
| 803 |
+
}),
|
| 804 |
+
sep = " & "), collapse = " \\\\\n"), "\\\\\n")
|
| 805 |
+
|
| 806 |
+
# Produce tabular output.
|
| 807 |
+
sink("output/atts_tab.tex")
|
| 808 |
+
cat("\\begin{table}\n",
|
| 809 |
+
"\\caption{Attitudes Toward Nuclear Weapons by Arm}\n",
|
| 810 |
+
"\\centering\\small\n",
|
| 811 |
+
"\\sisetup{\n",
|
| 812 |
+
"\tdetect-all,\n",
|
| 813 |
+
"\ttable-number-alignment = center,\n",
|
| 814 |
+
"\ttable-figures-integer = 1,\n",
|
| 815 |
+
"\ttable-figures-decimal = 3,\n",
|
| 816 |
+
"\ttable-space-text-post = *,\n",
|
| 817 |
+
"\tinput-symbols = {()}\n",
|
| 818 |
+
"}\n",
|
| 819 |
+
paste0("\\begin{tabular}{@{\\extracolsep{5pt}}L{3.5cm}*{5}",
|
| 820 |
+
"{S[table-number-alignment = center, table-column-width=1.25cm]}}\n"),
|
| 821 |
+
"\\toprule\n",
|
| 822 |
+
"& \\multicolumn{5}{c}{Arm}\\\\\\cmidrule{2-6}\n",
|
| 823 |
+
"& {Control} & {Group} & {Security} & {Norms} & {Institutions} \\\\\\midrule\n",
|
| 824 |
+
tab,
|
| 825 |
+
"\\bottomrule\n",
|
| 826 |
+
"\\end{tabular}\n",
|
| 827 |
+
"\\end{table}\n")
|
| 828 |
+
sink()
|
| 829 |
+
|
| 830 |
+
## Create tabular output for results by political party.
|
| 831 |
+
# Restructure data such that mean and SE estimates are alternating rows in a
|
| 832 |
+
# 1 x 6 matrix, in each of five list elements, corresponding to each treatment
|
| 833 |
+
# group; and bind the results for each treatment group.
|
| 834 |
+
pid_tab <- lapply(pid_results, function (x) {
|
| 835 |
+
matrix(unlist(x), nrow = 6, ncol = 1)
|
| 836 |
+
})
|
| 837 |
+
pid_tab <- do.call("cbind", pid_tab)
|
| 838 |
+
|
| 839 |
+
# Assign row names to distinguish results for each partisan group, and mean and
|
| 840 |
+
# SE estimates.
|
| 841 |
+
rownames(pid_tab) <- paste(rep(c("democrat", "independent", "republican"),
|
| 842 |
+
each = 2), c("mean", "se"))
|
| 843 |
+
|
| 844 |
+
# Relabel mean rows.
|
| 845 |
+
mean_rows <- endsWith(rownames(pid_tab), "mean")
|
| 846 |
+
|
| 847 |
+
# Relabel SE rows.
|
| 848 |
+
se_rows <- endsWith(rownames(pid_tab), "se")
|
| 849 |
+
|
| 850 |
+
# Label columns per treatment, for the computation of ATEs.
|
| 851 |
+
colnames(pid_tab) <- c("control", treats)
|
| 852 |
+
|
| 853 |
+
# Compute ATEs, with control as baseline, and update tabular data.
|
| 854 |
+
pid_tab[mean_rows, treats] <- pid_tab[mean_rows, treats] -
|
| 855 |
+
pid_tab[mean_rows, "control"]
|
| 856 |
+
|
| 857 |
+
# Reformat data to include three decimal points.
|
| 858 |
+
pid_tab <- apply(pid_tab, 2, function (y) format(round(y, 3) * 100, digits = 3))
|
| 859 |
+
|
| 860 |
+
# Remove extraneous spacing.
|
| 861 |
+
pid_tab <- gsub(" ", "", pid_tab)
|
| 862 |
+
|
| 863 |
+
# Reformat SE estimates to be within parentheses.
|
| 864 |
+
pid_tab[se_rows,] <- paste0("(", pid_tab[se_rows,], ")")
|
| 865 |
+
|
| 866 |
+
# Remove row names for rows with SE estimates.
|
| 867 |
+
rownames(pid_tab)[se_rows] <- ""
|
| 868 |
+
|
| 869 |
+
# Concatenate data to comport with LaTeX tabular markup.
|
| 870 |
+
pid_tab <- paste(paste(paste(capwords(gsub("_", " ", rownames(pid_tab))),
|
| 871 |
+
apply(pid_tab, 1, function (x) {
|
| 872 |
+
paste(x, collapse = " & ")
|
| 873 |
+
}),
|
| 874 |
+
sep = " & "), collapse = " \\\\\n"), "\\\\\n")
|
| 875 |
+
|
| 876 |
+
# Produce tabular output.
|
| 877 |
+
sink("output/pid_support.tex")
|
| 878 |
+
cat("\\begin{table}\n",
|
| 879 |
+
"\\caption{Support for Joining TPNW by Party ID}\n",
|
| 880 |
+
"\\centering\\small\n",
|
| 881 |
+
"\\sisetup{\n",
|
| 882 |
+
"\tdetect-all,\n",
|
| 883 |
+
"\ttable-number-alignment = center,\n",
|
| 884 |
+
"\ttable-figures-integer = 1,\n",
|
| 885 |
+
"\ttable-figures-decimal = 3,\n",
|
| 886 |
+
"\tinput-symbols = {()}\n",
|
| 887 |
+
"}\n",
|
| 888 |
+
paste0("\\begin{tabular}{@{\\extracolsep{5pt}}L{3.5cm}*{5}",
|
| 889 |
+
"{S[table-number-alignment = right, table-column-width=1.25cm]}}\n"),
|
| 890 |
+
"\\toprule\n",
|
| 891 |
+
"& \\multicolumn{5}{c}{Arm}\\\\\\cmidrule{2-6}\n",
|
| 892 |
+
"& {Control} & {Group} & {Security} & {Norms} & {Institutions} \\\\\\midrule\n",
|
| 893 |
+
pid_tab,
|
| 894 |
+
"\\bottomrule\n",
|
| 895 |
+
"\\end{tabular}\n",
|
| 896 |
+
"\\end{table}\n")
|
| 897 |
+
sink()
|
| 898 |
+
|
| 899 |
+
## Create tabular output for results by political ideology.
|
| 900 |
+
# Restructure data such that mean and SE estimates are alternating rows in a
|
| 901 |
+
# 1 x 6 matrix, in each of five list elements, corresponding to each treatment
|
| 902 |
+
# group; and bind the results for each treatment group.
|
| 903 |
+
ideo_tab <- lapply(ideo_results, function (x) {
|
| 904 |
+
matrix(unlist(x), nrow = 6, ncol = 1)
|
| 905 |
+
})
|
| 906 |
+
ideo_tab <- do.call("cbind", ideo_tab)
|
| 907 |
+
|
| 908 |
+
# Assign row names to distinguish results for each idelogical group, and mean
|
| 909 |
+
# and SE estimates.
|
| 910 |
+
rownames(ideo_tab) <- paste(rep(c("liberal", "moderate", "conservative"),
|
| 911 |
+
each = 2), c("mean", "se"))
|
| 912 |
+
|
| 913 |
+
# Reformat data to include three decimal points.
|
| 914 |
+
ideo_tab <- apply(ideo_tab, 2, function (y) format(round(y, 3) * 100,
|
| 915 |
+
digits = 3))
|
| 916 |
+
|
| 917 |
+
# Relabel mean rows.
|
| 918 |
+
mean_rows <- endsWith(rownames(ideo_tab), "mean")
|
| 919 |
+
|
| 920 |
+
# Relabel SE rows.
|
| 921 |
+
se_rows <- endsWith(rownames(ideo_tab), "se")
|
| 922 |
+
|
| 923 |
+
# Reformat SE estimates to be within parentheses.
|
| 924 |
+
ideo_tab[se_rows,] <- paste0("(", ideo_tab[se_rows,], ")")
|
| 925 |
+
|
| 926 |
+
# Remove row names for rows with SE estimates.
|
| 927 |
+
rownames(ideo_tab)[se_rows] <- ""
|
| 928 |
+
|
| 929 |
+
# Concatenate data to comport with LaTeX tabular markup.
|
| 930 |
+
ideo_tab <- paste(paste(paste(capwords(gsub("_", " ", rownames(ideo_tab))),
|
| 931 |
+
apply(ideo_tab, 1, function (x) {
|
| 932 |
+
paste(x, collapse = " & ")
|
| 933 |
+
}),
|
| 934 |
+
sep = " & "), collapse = " \\\\\n"), "\\\\\n")
|
| 935 |
+
|
| 936 |
+
# Produce tabular output.
|
| 937 |
+
sink("output/ideo_support_tab.tex")
|
| 938 |
+
cat("\\begin{table}\n",
|
| 939 |
+
"\\caption{Support for Joining TPNW by Ideology}\n",
|
| 940 |
+
"\\centering\\small\n",
|
| 941 |
+
"\\sisetup{\n",
|
| 942 |
+
"\tdetect-all,\n",
|
| 943 |
+
"\ttable-number-alignment = center,\n",
|
| 944 |
+
"\ttable-figures-integer = 1,\n",
|
| 945 |
+
"\ttable-figures-decimal = 3,\n",
|
| 946 |
+
"\tinput-symbols = {()}\n",
|
| 947 |
+
"}\n",
|
| 948 |
+
paste0("\\begin{tabular}{@{\\extracolsep{5pt}}L{3.5cm}*{5}",
|
| 949 |
+
"{S[table-number-alignment = right, table-column-width=1.25cm]}}\n"),
|
| 950 |
+
"\\toprule\n",
|
| 951 |
+
"& \\multicolumn{5}{c}{Arm}\\\\\\cmidrule{2-6}\n",
|
| 952 |
+
"& {Control} & {Group} & {Security} & {Norms} & {Institutions} \\\\\\midrule\n",
|
| 953 |
+
ideo_tab,
|
| 954 |
+
"\\bottomrule\n",
|
| 955 |
+
"\\end{tabular}\n",
|
| 956 |
+
"\\end{table}\n")
|
| 957 |
+
sink()
|
| 958 |
+
|
| 959 |
+
## Create tabular output for weighted main results.
|
| 960 |
+
# Define matrix object of weighted main results.
|
| 961 |
+
w_tab_dat <- do.call("cbind", w_main_results)
|
| 962 |
+
|
| 963 |
+
# Compute weighted control-group means, with SE estimates; define OLS formula.
|
| 964 |
+
w_ctrl_form <- as.formula(paste(join_tpnw, paste(treats,
|
| 965 |
+
collapse = " + "), sep = " ~ "))
|
| 966 |
+
|
| 967 |
+
# Fit the OLS model per the specification and recover the control mean.
|
| 968 |
+
w_ctrl_fit <- lm(w_ctrl_form, data = tpnw,
|
| 969 |
+
weights = anesrake_weight)
|
| 970 |
+
|
| 971 |
+
# Recover the control-group mean.
|
| 972 |
+
w_ctrl_mean <- w_ctrl_fit$coef["(Intercept)"]
|
| 973 |
+
|
| 974 |
+
# Compute control SE.
|
| 975 |
+
w_ctrl_se <- sqrt(diag(vcovHC(w_ctrl_fit, "HC2")))["(Intercept)"]
|
| 976 |
+
|
| 977 |
+
|
| 978 |
+
# Concatenate mean and SE output with blank values for Model 2.
|
| 979 |
+
w_ctrl_results <- c(format(round(c(w_ctrl_mean, w_ctrl_se), 3) * 100,
|
| 980 |
+
digits = 2), "|", "|")
|
| 981 |
+
|
| 982 |
+
# Reformat data to include a decimal point.
|
| 983 |
+
w_tab_dat <- apply(w_tab_dat, 2, function (y) format(round(y, 3) * 100,
|
| 984 |
+
digits = 2))
|
| 985 |
+
|
| 986 |
+
# Bind control-group means with main results data.
|
| 987 |
+
w_tab <- rbind(w_ctrl_results, w_tab_dat)
|
| 988 |
+
|
| 989 |
+
# Rename row containing control-group means.
|
| 990 |
+
rownames(w_tab)[which(rownames(w_tab) == "1")] <- "control_mean"
|
| 991 |
+
|
| 992 |
+
# Relabel coefficient columns.
|
| 993 |
+
coef_cols <- grep("coef$", colnames(w_tab))
|
| 994 |
+
|
| 995 |
+
# Relabel SE columns.
|
| 996 |
+
se_cols <- grep("se$", colnames(w_tab))
|
| 997 |
+
|
| 998 |
+
# Reformat SE estimates to be within parentheses.
|
| 999 |
+
w_tab[,se_cols] <- apply(w_tab[, se_cols], 2, function (y) paste0("(", y, ")"))
|
| 1000 |
+
|
| 1001 |
+
# Concatenate data to comport with LaTeX tabular markup.
|
| 1002 |
+
w_tab <- paste(paste(paste(capwords(gsub("_", " ", rownames(w_tab))),
|
| 1003 |
+
apply(w_tab, 1, function (x) {
|
| 1004 |
+
paste(x, collapse = " & ")
|
| 1005 |
+
}), sep = " & "), collapse = " \\\\\n"), "\\\\\n")
|
| 1006 |
+
|
| 1007 |
+
# Produce tabular output.
|
| 1008 |
+
sink("output/weighted_main_results_tab.tex")
|
| 1009 |
+
cat("\\begin{table}\n",
|
| 1010 |
+
"\\caption{Estimated Treatment Effects on Support for TPNW (Weighted)}\n",
|
| 1011 |
+
"\\begin{adjustbox}{width = \\textwidth, center}\n",
|
| 1012 |
+
"\\sisetup{\n",
|
| 1013 |
+
"\tdetect-all,\n",
|
| 1014 |
+
"\ttable-number-alignment = center,\n",
|
| 1015 |
+
"\ttable-figures-integer = 1,\n",
|
| 1016 |
+
"\ttable-figures-decimal = 3,\n",
|
| 1017 |
+
"\ttable-space-text-post = *,\n",
|
| 1018 |
+
"\tinput-symbols = {()}\n",
|
| 1019 |
+
"}\n",
|
| 1020 |
+
paste0("\\begin{tabular}{@{\\extracolsep{5pt}}L{3.5cm}*{4}",
|
| 1021 |
+
"{S[table-number-alignment = right, table-column-width=1.25cm]}}\n"),
|
| 1022 |
+
"\\toprule\n",
|
| 1023 |
+
"& \\multicolumn{4}{c}{Model}\\\\\\cmidrule{2-5}\n",
|
| 1024 |
+
"& \\multicolumn{2}{c}{{(1)}} & \\multicolumn{2}{c}{{(2)}} \\\\\\midrule\n",
|
| 1025 |
+
w_tab,
|
| 1026 |
+
"\\bottomrule\n",
|
| 1027 |
+
"\\end{tabular}\n",
|
| 1028 |
+
"\\end{adjustbox}\n",
|
| 1029 |
+
"\\end{table}\n")
|
| 1030 |
+
sink()
|
| 1031 |
+
|
| 1032 |
+
### Save image containing all objects.
|
| 1033 |
+
save.image(file = "output/hbg_replication_out.RData")
|
1/replication_package/scripts/hbg_cleaning.R
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Initialize workspace.
|
| 2 |
+
rm(list = ls(all = TRUE))
|
| 3 |
+
setwd("~/Downloads/hbg_replication")
|
| 4 |
+
|
| 5 |
+
# Load required packages
|
| 6 |
+
library(plyr)
|
| 7 |
+
library(car)
|
| 8 |
+
library(anesrake)
|
| 9 |
+
|
| 10 |
+
# Load relevant functions.
|
| 11 |
+
source("scripts/helper_functions.R")
|
| 12 |
+
|
| 13 |
+
## Load data.
|
| 14 |
+
# Load TPNW experimental data.
|
| 15 |
+
tpnw <- read.csv("data/tpnw_raw.csv", stringsAsFactors = FALSE, row.names = 1)
|
| 16 |
+
|
| 17 |
+
# Load original income question data.
|
| 18 |
+
orig_inc <- read.csv("data/tpnw_orig_income.csv", stringsAsFactors = FALSE,
|
| 19 |
+
row.names = 1)
|
| 20 |
+
|
| 21 |
+
# Load YouGov data (including covariates and awareness question).
|
| 22 |
+
aware <- read.csv("data/tpnw_aware_raw.csv", stringsAsFactors = FALSE,
|
| 23 |
+
row.names = 1)
|
| 24 |
+
|
| 25 |
+
### Clean TPNW data.
|
| 26 |
+
## Clean data.
|
| 27 |
+
# Remove first two (extraneous) rows.
|
| 28 |
+
tpnw <- tpnw[-c(1, 2),]
|
| 29 |
+
orig_inc <- orig_inc[-c(1, 2),]
|
| 30 |
+
|
| 31 |
+
# Remove respondents who did not consent.
|
| 32 |
+
tpnw <- tpnw[tpnw$consent == "1",]
|
| 33 |
+
orig_inc <- orig_inc[orig_inc$consent == "1",]
|
| 34 |
+
|
| 35 |
+
# Coalesce income variables.
|
| 36 |
+
orig_inc <- within(orig_inc, {
|
| 37 |
+
income <- as.numeric(income)
|
| 38 |
+
income <- ifelse(income < 1000, NA, income)
|
| 39 |
+
income <- ifelse(income < 15000, 1, income)
|
| 40 |
+
income <- ifelse(income >= 15000 & income < 25000, 2, income)
|
| 41 |
+
income <- ifelse(income >= 25000 & income < 50000, 3, income)
|
| 42 |
+
income <- ifelse(income >= 50000 & income < 75000, 4, income)
|
| 43 |
+
income <- ifelse(income >= 75000 & income < 100000, 5, income)
|
| 44 |
+
income <- ifelse(income >= 100000 & income < 150000, 6, income)
|
| 45 |
+
income <- ifelse(income >= 150000 & income < 200000, 7, income)
|
| 46 |
+
income <- ifelse(income >= 200000 & income < 250000, 8, income)
|
| 47 |
+
income <- ifelse(income >= 250000 & income < 500000, 9, income)
|
| 48 |
+
income <- ifelse(income >= 500000 & income < 1000000, 10, income)
|
| 49 |
+
income <- ifelse(income >= 1000000, 11, income)
|
| 50 |
+
})
|
| 51 |
+
orig_inc <- data.frame(pid = orig_inc$pid, income_old = orig_inc$income)
|
| 52 |
+
tpnw <- plyr::join(tpnw, orig_inc, by = "pid", type = "left")
|
| 53 |
+
tpnw <- within(tpnw, {
|
| 54 |
+
income <- coalesce(as.numeric(income), as.numeric(income_old))
|
| 55 |
+
})
|
| 56 |
+
|
| 57 |
+
# Note meta variables.
|
| 58 |
+
meta <- c("consent", "confirmation_code", "new_income_q")
|
| 59 |
+
|
| 60 |
+
# Note Qualtrics variables.
|
| 61 |
+
qualtrics_vars <- c("StartDate", "EndDate", "Status", "Progress",
|
| 62 |
+
"Duration..in.seconds.", "Finished", "RecordedDate",
|
| 63 |
+
"DistributionChannel", "UserLanguage")
|
| 64 |
+
|
| 65 |
+
# Note Dynata variables.
|
| 66 |
+
dynata_vars <- c("pid", "psid")
|
| 67 |
+
|
| 68 |
+
# Note non-numeric variables.
|
| 69 |
+
char_vars <- c(qualtrics_vars, dynata_vars,
|
| 70 |
+
c("ResponseId"), names(tpnw)[grep("text", tolower(names(tpnw)))])
|
| 71 |
+
char_cols <- which(names(tpnw) %in% char_vars)
|
| 72 |
+
|
| 73 |
+
# Numericize other variables
|
| 74 |
+
tpnw <- data.frame(apply(tpnw[, -char_cols], 2, as.numeric), tpnw[char_cols])
|
| 75 |
+
|
| 76 |
+
tpnw_atts <- which(names(tpnw) %in% c("danger", "peace", "safe", "use_unaccept",
|
| 77 |
+
"always_cheat", "cannot_elim", "slow_reduc"))
|
| 78 |
+
names(tpnw)[tpnw_atts] <- paste("tpnw_atts", names(tpnw)[tpnw_atts], sep = "_")
|
| 79 |
+
|
| 80 |
+
# Coalesce relevant variables.
|
| 81 |
+
tpnw <- within(tpnw, {
|
| 82 |
+
# Clean gender variable.
|
| 83 |
+
female <- ifelse(gender == 95, NA, gender)
|
| 84 |
+
|
| 85 |
+
# Transform birthyr variable to age.
|
| 86 |
+
age <- 2019 - birthyr
|
| 87 |
+
|
| 88 |
+
# Transform income variable.
|
| 89 |
+
income <- car::recode(income, "95 = NA")
|
| 90 |
+
|
| 91 |
+
# Combine pid and pid_forc variables.
|
| 92 |
+
pid3 <- ifelse(pid3 == 0, pid_forc, pid3)
|
| 93 |
+
|
| 94 |
+
# Recode ideology variable.
|
| 95 |
+
ideo <- car::recode(ideo, "3 = NA")
|
| 96 |
+
|
| 97 |
+
# Recode education variable.
|
| 98 |
+
educ <- car::recode(educ, "95 = NA")
|
| 99 |
+
|
| 100 |
+
# Recode state variable.
|
| 101 |
+
state <- recode(state, "1 = 'Alabama';
|
| 102 |
+
2 = 'Alaska';
|
| 103 |
+
4 = 'Arizona';
|
| 104 |
+
5 = 'Arkansas';
|
| 105 |
+
6 = 'California';
|
| 106 |
+
8 = 'Colorado';
|
| 107 |
+
9 = 'Connecticut';
|
| 108 |
+
10 = 'Delaware';
|
| 109 |
+
11 = 'Washington DC';
|
| 110 |
+
12 = 'Florida';
|
| 111 |
+
13 = 'Georgia';
|
| 112 |
+
15 = 'Hawaii';
|
| 113 |
+
16 = 'Idaho';
|
| 114 |
+
17 = 'Illinois';
|
| 115 |
+
18 = 'Indiana';
|
| 116 |
+
19 = 'Iowa';
|
| 117 |
+
20 = 'Kansas';
|
| 118 |
+
21 = 'Kentucky';
|
| 119 |
+
22 = 'Louisiana';
|
| 120 |
+
23 = 'Maine';
|
| 121 |
+
24 = 'Maryland';
|
| 122 |
+
25 = 'Massachusetts';
|
| 123 |
+
26 = 'Michigan';
|
| 124 |
+
27 = 'Minnesota';
|
| 125 |
+
28 = 'Mississippi';
|
| 126 |
+
29 = 'Missouri';
|
| 127 |
+
30 = 'Montana';
|
| 128 |
+
31 = 'Nebraska';
|
| 129 |
+
32 = 'Nevada';
|
| 130 |
+
33 = 'New Hampshire';
|
| 131 |
+
34 = 'New Jersey';
|
| 132 |
+
35 = 'New Mexico';
|
| 133 |
+
36 = 'New York';
|
| 134 |
+
37 = 'North Carolina';
|
| 135 |
+
38 = 'North Dakota';
|
| 136 |
+
39 = 'Ohio';
|
| 137 |
+
40 = 'Oklahoma';
|
| 138 |
+
41 = 'Oregon';
|
| 139 |
+
42 = 'Pennsylvania';
|
| 140 |
+
44 = 'Rhode Island';
|
| 141 |
+
45 = 'South Carolina';
|
| 142 |
+
46 = 'South Dakota';
|
| 143 |
+
47 = 'Tennessee';
|
| 144 |
+
48 = 'Texas';
|
| 145 |
+
49 = 'Utah';
|
| 146 |
+
50 = 'Vermont';
|
| 147 |
+
51 = 'Virginia';
|
| 148 |
+
53 = 'Washington';
|
| 149 |
+
54 = 'West Virginia';
|
| 150 |
+
55 = 'Wisconsin';
|
| 151 |
+
56 = 'Wyoming'")
|
| 152 |
+
|
| 153 |
+
# Create regional indicators.
|
| 154 |
+
northeast <- state %in% c("Connecticut", "Maine", "Massachusetts",
|
| 155 |
+
"New Hampshire", "Rhode Island", "Vermont",
|
| 156 |
+
"New Jersey", "New York", "Pennsylvania")
|
| 157 |
+
midwest <- state %in% c("Illinois", "Indiana", "Michigan", "Ohio",
|
| 158 |
+
"Wisconsin", "Iowa", "Kansas", "Minnesota",
|
| 159 |
+
"Missouri", "Nebraska", "North Dakota",
|
| 160 |
+
"South Dakota")
|
| 161 |
+
south <- state %in% c("Delaware", "Florida", "Georgia", "Maryland",
|
| 162 |
+
"North Carolina", "South Carolina", "Virginia",
|
| 163 |
+
"Washington DC", "West Virginia", "Alabama",
|
| 164 |
+
"Kentucky", "Mississippi", "Tennessee", "Arkansas",
|
| 165 |
+
"Louisiana", "Oklahoma", "Texas")
|
| 166 |
+
west <- state %in% c("Arizona", "Colorado", "Idaho", "Montana", "Nevada",
|
| 167 |
+
"New Mexico", "Utah", "Wyoming", "Alaska",
|
| 168 |
+
"California", "Hawaii", "Oregon", "Washington")
|
| 169 |
+
|
| 170 |
+
# Recode join_tpnw outcome.
|
| 171 |
+
join_tpnw <- car::recode(join_tpnw, "2 = 0")
|
| 172 |
+
|
| 173 |
+
# Create indicator variables for each treatment arm.
|
| 174 |
+
control <- treatment == 0
|
| 175 |
+
group_cue <- treatment == 1
|
| 176 |
+
security_cue <- treatment == 2
|
| 177 |
+
norms_cue <- treatment == 3
|
| 178 |
+
institutions_cue <- treatment == 4
|
| 179 |
+
|
| 180 |
+
# Recode attitudinal outcomes.
|
| 181 |
+
tpnw_atts_danger <- recode(tpnw_atts_danger, "-2 = 2; -1 = 1; 1 = -1; 2 = -2")
|
| 182 |
+
tpnw_atts_use_unaccept <- recode(tpnw_atts_use_unaccept, "-2 = 2; -1 = 1;
|
| 183 |
+
1 = -1; 2 = -2")
|
| 184 |
+
tpnw_atts_always_cheat <- recode(tpnw_atts_always_cheat, "-2 = 2; -1 = 1;
|
| 185 |
+
1 = -1; 2 = -2")
|
| 186 |
+
tpnw_atts_cannot_elim <- recode(tpnw_atts_cannot_elim, "-2 = 2; -1 = 1;
|
| 187 |
+
1 = -1; 2 = -2")
|
| 188 |
+
})
|
| 189 |
+
|
| 190 |
+
# Use mean imputation for missingness.
|
| 191 |
+
# Redefine char_cols object.
|
| 192 |
+
char_cols <- which(names(tpnw) %in% c(char_vars, meta, "state", "pid_forc",
|
| 193 |
+
"income_old", "gender"))
|
| 194 |
+
|
| 195 |
+
# Define out_vars object.
|
| 196 |
+
out_vars <- which(names(tpnw) %in% c("join_tpnw", "n_nukes", "n_tests") |
|
| 197 |
+
startsWith(names(tpnw), "tpnw_atts") |
|
| 198 |
+
startsWith(names(tpnw), "physical_eff") |
|
| 199 |
+
startsWith(names(tpnw), "testing_matrix"))
|
| 200 |
+
|
| 201 |
+
# Mean impute.
|
| 202 |
+
tpnw[,-c(char_cols, out_vars)] <-
|
| 203 |
+
data.frame(apply(tpnw[, -c(char_cols, out_vars)], 2, function (x) {
|
| 204 |
+
replace(x, is.na(x), mean(x, na.rm = TRUE))
|
| 205 |
+
}))
|
| 206 |
+
|
| 207 |
+
### Clean YouGov data.
|
| 208 |
+
## Indicate all non-numeric variables.
|
| 209 |
+
# Indicate YouGov metadata variables (e.g., start/end time, respondent ID) that
|
| 210 |
+
# may contain characters.
|
| 211 |
+
yougov_vars <- c("starttime", "endtime")
|
| 212 |
+
|
| 213 |
+
# Numericize all numeric variables
|
| 214 |
+
aware <- data.frame(apply(aware[, -which(names(aware) %in% yougov_vars)], 2,
|
| 215 |
+
as.numeric), aware[which(names(aware) %in% yougov_vars)])
|
| 216 |
+
|
| 217 |
+
# Coalesce relevant variables.
|
| 218 |
+
aware <- within(aware, {
|
| 219 |
+
# Clean gender variable to an indicator of female gender (renamed below).
|
| 220 |
+
gender <- recode(gender, "8 = NA") - 1
|
| 221 |
+
|
| 222 |
+
# Transform birthyr variable to age (renamed below).
|
| 223 |
+
birthyr <- 2020 - birthyr
|
| 224 |
+
|
| 225 |
+
# Recode pid3 variable.
|
| 226 |
+
pid3 <- recode(pid3, "1 = -1; 2 = 1; 3 = 0; c(5, 8, 9) = NA")
|
| 227 |
+
|
| 228 |
+
# Recode pid7
|
| 229 |
+
pid7 <- recode(pid7, "1 = -3; 2 = -2; 3 = -1; 4 = 0; 5 = 1; 6 = 2; 7 = 3;
|
| 230 |
+
c(8, 98) = NA")
|
| 231 |
+
|
| 232 |
+
# Code pid variable from pid7.
|
| 233 |
+
party <- recode(pid7, "c(-3, -2, -1) = -1; c(1, 2, 3) = 1")
|
| 234 |
+
|
| 235 |
+
# Recode ideology variable.
|
| 236 |
+
ideo5 <- recode(ideo5, "c(6, 8, 9) = NA") - 3
|
| 237 |
+
|
| 238 |
+
# Recode education variable.
|
| 239 |
+
educ <- recode(educ, "c(8, 9) = NA")
|
| 240 |
+
|
| 241 |
+
# Recode state variable.
|
| 242 |
+
state <- recode(inputstate, "1 = 'Alabama';
|
| 243 |
+
2 = 'Alaska';
|
| 244 |
+
4 = 'Arizona';
|
| 245 |
+
5 = 'Arkansas';
|
| 246 |
+
6 = 'California';
|
| 247 |
+
8 = 'Colorado';
|
| 248 |
+
9 = 'Connecticut';
|
| 249 |
+
10 = 'Delaware';
|
| 250 |
+
11 = 'Washington DC';
|
| 251 |
+
12 = 'Florida';
|
| 252 |
+
13 = 'Georgia';
|
| 253 |
+
15 = 'Hawaii';
|
| 254 |
+
16 = 'Idaho';
|
| 255 |
+
17 = 'Illinois';
|
| 256 |
+
18 = 'Indiana';
|
| 257 |
+
19 = 'Iowa';
|
| 258 |
+
20 = 'Kansas';
|
| 259 |
+
21 = 'Kentucky';
|
| 260 |
+
22 = 'Louisiana';
|
| 261 |
+
23 = 'Maine';
|
| 262 |
+
24 = 'Maryland';
|
| 263 |
+
25 = 'Massachusetts';
|
| 264 |
+
26 = 'Michigan';
|
| 265 |
+
27 = 'Minnesota';
|
| 266 |
+
28 = 'Mississippi';
|
| 267 |
+
29 = 'Missouri';
|
| 268 |
+
30 = 'Montana';
|
| 269 |
+
31 = 'Nebraska';
|
| 270 |
+
32 = 'Nevada';
|
| 271 |
+
33 = 'New Hampshire';
|
| 272 |
+
34 = 'New Jersey';
|
| 273 |
+
35 = 'New Mexico';
|
| 274 |
+
36 = 'New York';
|
| 275 |
+
37 = 'North Carolina';
|
| 276 |
+
38 = 'North Dakota';
|
| 277 |
+
39 = 'Ohio';
|
| 278 |
+
40 = 'Oklahoma';
|
| 279 |
+
41 = 'Oregon';
|
| 280 |
+
42 = 'Pennsylvania';
|
| 281 |
+
44 = 'Rhode Island';
|
| 282 |
+
45 = 'South Carolina';
|
| 283 |
+
46 = 'South Dakota';
|
| 284 |
+
47 = 'Tennessee';
|
| 285 |
+
48 = 'Texas';
|
| 286 |
+
49 = 'Utah';
|
| 287 |
+
50 = 'Vermont';
|
| 288 |
+
51 = 'Virginia';
|
| 289 |
+
53 = 'Washington';
|
| 290 |
+
54 = 'West Virginia';
|
| 291 |
+
55 = 'Wisconsin';
|
| 292 |
+
56 = 'Wyoming'")
|
| 293 |
+
|
| 294 |
+
# Define US Census geographic regions.
|
| 295 |
+
northeast <- inputstate %in% c(9, 23, 25, 33, 44, 50, 34, 36, 42)
|
| 296 |
+
midwest <- inputstate %in% c(18, 17, 26, 39, 55, 19, 20, 27, 29, 31, 38, 46)
|
| 297 |
+
south <- inputstate %in% c(10, 11, 12, 13, 24, 37, 45, 51,
|
| 298 |
+
54, 1, 21, 28, 47, 5, 22, 40, 48)
|
| 299 |
+
west <- inputstate %in% c(4, 8, 16, 35, 30, 49, 32, 56, 2, 6, 15, 41, 53)
|
| 300 |
+
|
| 301 |
+
# Recode employment.
|
| 302 |
+
employ <- recode(employ, "c(9, 98, 99) = NA")
|
| 303 |
+
|
| 304 |
+
# Recode outcome.
|
| 305 |
+
awareness <- recode(awareness, "8 = NA")
|
| 306 |
+
|
| 307 |
+
# Normalize weights.
|
| 308 |
+
weight <- weight / sum(weight)
|
| 309 |
+
})
|
| 310 |
+
|
| 311 |
+
# Rename demographic questions.
|
| 312 |
+
aware <- rename(aware, c("gender" = "female", "birthyr" = "age",
|
| 313 |
+
"faminc_new" = "income", "ideo5" = "ideo"))
|
| 314 |
+
|
| 315 |
+
## Impute missing values.
|
| 316 |
+
# Specify non-covariate numerical variables (other is exempted since over 10% of
|
| 317 |
+
# responses are missing; state is exempted since the variable is categorical).
|
| 318 |
+
non_covars <- names(aware)[names(aware) %in% c("caseid", "starttime", "endtime",
|
| 319 |
+
"awareness", "state", "weight")]
|
| 320 |
+
|
| 321 |
+
# Use mean imputation for missingness in covariates.
|
| 322 |
+
aware[, -which(names(aware) %in% non_covars)] <-
|
| 323 |
+
data.frame(apply(aware[, -which(names(aware) %in%
|
| 324 |
+
non_covars)], 2, function (x) {
|
| 325 |
+
replace(x, is.na(x), mean(x, na.rm = TRUE))
|
| 326 |
+
}))
|
| 327 |
+
|
| 328 |
+
### Produce weights for TPNW experimental data using anesrake.
|
| 329 |
+
## Create unique identifier variable for assigning weights.
|
| 330 |
+
tpnw$caseid <- 1:nrow(tpnw)
|
| 331 |
+
|
| 332 |
+
## Recode relevant covariates for reweighting: coarsen age; recode female; and
|
| 333 |
+
## recode geographic covariates.
|
| 334 |
+
# Coarsen age into a categorical variable for age groups.
|
| 335 |
+
tpnw$age_wtng <- cut(tpnw$age, c(0, 25, 35, 45, 55, 65, 99))
|
| 336 |
+
levels(tpnw$age_wtng) <- c("age1824", "age2534", "age3544",
|
| 337 |
+
"age4554", "age5564", "age6599")
|
| 338 |
+
|
| 339 |
+
# Recode female as a factor to account for NA values.
|
| 340 |
+
tpnw$female_wtng <- as.factor(tpnw$female)
|
| 341 |
+
levels(tpnw$female_wtng) <- c("male", "na", "female")
|
| 342 |
+
|
| 343 |
+
# Recode northeast as a factor.
|
| 344 |
+
tpnw$northeast_wtng <- as.factor(tpnw$northeast)
|
| 345 |
+
levels(tpnw$northeast_wtng) <- c("other", "northeast")
|
| 346 |
+
|
| 347 |
+
# Recode midwest as a factor.
|
| 348 |
+
tpnw$midwest_wtng <- as.factor(tpnw$midwest)
|
| 349 |
+
levels(tpnw$midwest_wtng) <- c("other", "midwest")
|
| 350 |
+
|
| 351 |
+
# Recode south as a factor.
|
| 352 |
+
tpnw$south_wtng <- as.factor(tpnw$south)
|
| 353 |
+
levels(tpnw$south_wtng) <- c("other", "south")
|
| 354 |
+
|
| 355 |
+
# Recode west as a factor.
|
| 356 |
+
tpnw$west_wtng <- as.factor(tpnw$west)
|
| 357 |
+
levels(tpnw$west_wtng) <- c("other", "west")
|
| 358 |
+
|
| 359 |
+
## Specify population targets for balancing (from US Census 2018 data).
|
| 360 |
+
# Specify gender proportion targets and assign names to comport with factors.
|
| 361 |
+
femaletarg <- c(.508, 0, .492)
|
| 362 |
+
names(femaletarg) <- c("female", "na", "male")
|
| 363 |
+
|
| 364 |
+
# Specify age-group proportion targets and assign names to comport with factors.
|
| 365 |
+
agetarg <- c(29363, 44854, 40659, 41537, 41700, 51080)/249193
|
| 366 |
+
names(agetarg) <- c("age1824", "age2534", "age3544",
|
| 367 |
+
"age4554", "age5564", "age6599")
|
| 368 |
+
|
| 369 |
+
# Specify northeast proportion targets and assign names to comport with factors.
|
| 370 |
+
northeasttarg <- c(1 - .173, .173)
|
| 371 |
+
names(northeasttarg) <- c("other", "northeast")
|
| 372 |
+
|
| 373 |
+
# Specify midwest proportion targets and assign names to comport with factors.
|
| 374 |
+
midwesttarg <- c(1 - .209, .209)
|
| 375 |
+
names(midwesttarg) <- c("other", "midwest")
|
| 376 |
+
|
| 377 |
+
# Specify south proportion targets and assign names to comport with factors.
|
| 378 |
+
southtarg <- c(1 - .380, .380)
|
| 379 |
+
names(southtarg) <- c("other", "south")
|
| 380 |
+
|
| 381 |
+
# Specify west proportion targets and assign names to comport with factors.
|
| 382 |
+
westtarg <- c(1 - .238, .238)
|
| 383 |
+
names(westtarg) <- c("other", "west")
|
| 384 |
+
|
| 385 |
+
# Create a list of all targets, with names to comport with relevant variables.
|
| 386 |
+
targets <- list(femaletarg, agetarg, northeasttarg,
|
| 387 |
+
midwesttarg, southtarg, westtarg)
|
| 388 |
+
names(targets) <- c("female_wtng", "age_wtng", "northeast_wtng",
|
| 389 |
+
"midwest_wtng", "south_wtng", "west_wtng")
|
| 390 |
+
|
| 391 |
+
# Produce anesrake weights.
|
| 392 |
+
anesrake_out <- anesrake(targets, tpnw, caseid = tpnw$caseid,
|
| 393 |
+
verbose = TRUE)
|
| 394 |
+
|
| 395 |
+
# Append anesrake weights to TPNW experimental data.
|
| 396 |
+
tpnw$anesrake_weight <- anesrake_out$weightvec
|
| 397 |
+
|
| 398 |
+
# Remove variables used for weighting.
|
| 399 |
+
tpnw <- tpnw[-grep("wtng$", names(tpnw))]
|
| 400 |
+
|
| 401 |
+
## Write data.
|
| 402 |
+
# Write full experimental dataset.
|
| 403 |
+
write.csv(tpnw, "data/tpnw_data.csv")
|
| 404 |
+
|
| 405 |
+
# write full YouGov dataset.
|
| 406 |
+
write.csv(aware, "data/tpnw_aware.csv")
|
1/replication_package/scripts/hbg_group_cue.R
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Initialize workspace.
|
| 2 |
+
# Remove objects.
|
| 3 |
+
rm(list = ls(all = TRUE))
|
| 4 |
+
|
| 5 |
+
## Generate data.
|
| 6 |
+
# Create count object storing count data.
|
| 7 |
+
count <- as.matrix(c(1547, 54, 2346))
|
| 8 |
+
|
| 9 |
+
# Convert count object to an object storing percentages.
|
| 10 |
+
perc <- sapply(count, function (x) x/sum(count))
|
| 11 |
+
|
| 12 |
+
# Create a cumulative percentage object.
|
| 13 |
+
cum_perc <- cumsum(perc)
|
| 14 |
+
|
| 15 |
+
# Create separate objects for the plotting of each proportion.
|
| 16 |
+
power_x <- c(0, rep(.74, 2), 0)
|
| 17 |
+
both_x <- c(.74, rep(.96, 2), .74)
|
| 18 |
+
weap_x <- c(.96, rep(1, 2), .96)
|
| 19 |
+
|
| 20 |
+
# Create an object representing the y-axis plotting points for each polygon.
|
| 21 |
+
plot_y <- c(2.25, 2.25, 3, 3)
|
| 22 |
+
|
| 23 |
+
# Open new .pdf file.
|
| 24 |
+
setEPS()
|
| 25 |
+
postscript("fgc1.eps", width = 10, height = 3)
|
| 26 |
+
|
| 27 |
+
# Modify graphical parameters (margins).
|
| 28 |
+
par(mar = c(0, 6, 6, 1))
|
| 29 |
+
|
| 30 |
+
# Create an empty plot.
|
| 31 |
+
plot(1, type = "n", xlab = "", ylab = "", xlim = c(0, 1), ylim = c(1.5, 3), axes = FALSE)
|
| 32 |
+
|
| 33 |
+
# Create polygons representing each proportion.
|
| 34 |
+
polygon(power_x, plot_y, col = "#FF8F37", border = "white")
|
| 35 |
+
polygon(both_x, plot_y, col = "steelblue3", border = "white")
|
| 36 |
+
polygon(weap_x, plot_y, col = "gray", border = "white")
|
| 37 |
+
|
| 38 |
+
# Create an axis and tick and axis labels.
|
| 39 |
+
axis(side = 3, at = seq(0, 1, .1), labels = FALSE)
|
| 40 |
+
text(x = seq(0, 1, .2), y = par("usr")[4] + .2, labels = c("0%", "20%", "40%", "60%", "80%", "100%"), xpd = TRUE)
|
| 41 |
+
mtext(text = "Proportion of Responses", side = 3, line = 2.5, cex = 1.25, font = 2)
|
| 42 |
+
|
| 43 |
+
# Add text denoting the percentage number associated of each proportion.
|
| 44 |
+
text(x = .74/2, y = 2.2, pos = 1, cex = 2, labels = "74%", col = "#FF8F37", font = 2)
|
| 45 |
+
text(x = .85, y = 2.2, pos = 1, cex = 2, labels = "22%", col = "steelblue3", font = 2)
|
| 46 |
+
text(x = .98, y = 2.2, labels = "4%", pos = 1, cex = 2, col = "grey", font = 2, xpd = TRUE)
|
| 47 |
+
|
| 48 |
+
# Add a legend.
|
| 49 |
+
leg = legend(x = -.16,, y = 2.625, legend = c("Oppose", "Support", "Prefer not\nto answer"), xpd = TRUE,
|
| 50 |
+
pch = 16, col = c("#FF8F37", "steelblue3", "grey"), box.lty = 0, cex = .9, y.intersp = 1.5, yjust = .5)
|
| 51 |
+
|
| 52 |
+
# Close the device.
|
| 53 |
+
dev.off()
|
1/replication_package/scripts/helper_functions.R
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Define coalesce function for recoding of post-election thermometers.
|
| 2 |
+
coalesce <- function (...) {
|
| 3 |
+
Reduce(function(x, y) {
|
| 4 |
+
i <- which(is.na(x))
|
| 5 |
+
x[i] <- y[i]
|
| 6 |
+
x},
|
| 7 |
+
list(...))
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
# Define capwords() function from the toupper() documentation.
|
| 11 |
+
capwords <- function(s, strict = FALSE) {
|
| 12 |
+
cap <- function(s) paste(toupper(substring(s, 1, 1)),
|
| 13 |
+
{s <- substring(s, 2); if(strict) tolower(s) else s},
|
| 14 |
+
sep = "", collapse = " " )
|
| 15 |
+
sapply(strsplit(s, split = " "), cap, USE.NAMES = !is.null(names(s)))
|
| 16 |
+
}
|
1/replication_package/scripts/run_hbg_replication.R
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## Initialize workspace.
|
| 2 |
+
# Clear workspace.
|
| 3 |
+
rm(list = ls(all = TRUE))
|
| 4 |
+
|
| 5 |
+
# Set working directory to abp_replication directory.
|
| 6 |
+
setwd("~/Downloads/hbg_replication")
|
| 7 |
+
|
| 8 |
+
## Prepare output directory and main output files.
|
| 9 |
+
# If an output directory does not exist, create the directory.
|
| 10 |
+
if (!file.exists("output")) {
|
| 11 |
+
dir.create("output")
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
# Create a log file for console output.
|
| 15 |
+
hbg_log <- file("output/hbg_log.txt", open = "wt")
|
| 16 |
+
|
| 17 |
+
# Echo and sink console log to psv_log file.
|
| 18 |
+
sink(hbg_log, append = TRUE)
|
| 19 |
+
sink(hbg_log, append = TRUE, type = "message")
|
| 20 |
+
|
| 21 |
+
## Replicate files and produce main output.
|
| 22 |
+
# Run abp_replication_code.R script, storing run-time statistics.
|
| 23 |
+
run_time <- system.time({source("scripts/hbg_cleaning.R", echo = TRUE,
|
| 24 |
+
max.deparse.length = 10000)
|
| 25 |
+
source("scripts/hbg_analysis.R", echo = TRUE,
|
| 26 |
+
max.deparse.length = 10000)})
|
| 27 |
+
|
| 28 |
+
# Close main output sink.
|
| 29 |
+
sink()
|
| 30 |
+
sink(type = "message")
|
| 31 |
+
|
| 32 |
+
## Sink run-time statistics to a run_time output file.
|
| 33 |
+
run_time_file <- file("output/run_time", open = "wt")
|
| 34 |
+
sink(run_time_file, append = TRUE)
|
| 35 |
+
print(run_time)
|
| 36 |
+
sink()
|
1/should_reproduce.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e948c9ddded565a15bdaa55c5f0001dcc6e8f1c0857305a6eaf31e19ff7b2dc0
|
| 3 |
+
size 16
|
10/paper.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0acc812e16e593efb2b9fbaf9ca35773a87a55f1753f85360f84c17e003da5d5
|
| 3 |
+
size 220140
|
10/replication_package/Codebook for Dyadic Party Dataset.docx
ADDED
|
Binary file (17.5 kB). View file
|
|
|
10/replication_package/Codebook for Gender Disaggregated Dyadic Party Dataset.docx
ADDED
|
Binary file (18 kB). View file
|
|
|
10/replication_package/Codebook for Multilevel Dataset.docx
ADDED
|
Binary file (18.3 kB). View file
|
|
|
10/replication_package/dyadic_data_1-4-22.Rdata
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ce16b80cec72dc2c069ac245c09faa56aa40a80aba7bc21038539f6b16076b05
|
| 3 |
+
size 253615
|
10/replication_package/gender_disagregated_8-8-21.rds
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:050817c347915cd18baf4412e7cda9445a15ced3a4d7362c28ee3405a4fcc12f
|
| 3 |
+
size 272286
|
10/replication_package/multilevel_1-5-22.Rdata
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bd9a14418d24853992cdc860953b56a09afad73d32a8e8a0f78f02522a0d853a
|
| 3 |
+
size 10236336
|
10/replication_package/readme.rtf
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{\rtf1\ansi\ansicpg1252\cocoartf2513
|
| 2 |
+
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 ArialMT;\f1\fswiss\fcharset0 Helvetica;}
|
| 3 |
+
{\colortbl;\red255\green255\blue255;\red26\green26\blue26;\red255\green255\blue255;\red26\green26\blue26;
|
| 4 |
+
}
|
| 5 |
+
{\*\expandedcolortbl;;\cssrgb\c13348\c13348\c13331;\cssrgb\c100000\c100000\c100000\c0;\cssrgb\c13348\c13348\c13331;
|
| 6 |
+
}
|
| 7 |
+
\paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
|
| 8 |
+
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
|
| 9 |
+
|
| 10 |
+
\f0\fs24 \cf0 Replication Data ReadMe for \cf2 \cb3 \expnd0\expndtw0\kerning0
|
| 11 |
+
Can\'92t We All Just Get Along? How Women MPs Can Ameliorate Affective Polarization in Western Publics\
|
| 12 |
+
\
|
| 13 |
+
Code files: \
|
| 14 |
+
\
|
| 15 |
+
1. replication_code.r - Contains code to replicate all figures and tables in both article and supplementary information memo\
|
| 16 |
+
\
|
| 17 |
+
Datasets:\
|
| 18 |
+
1. dyadic_data_1-4-22.Rdata - Dataset of directed party dyads, associated with codebook \'93Codebook for Dyadic Party Dataset\'94. Dataset required to replicate table 1 and Figure 1 in article, as well as tables S2, S3A, S3B, S4, S5, S6, S7, S8, S9, S10, and Figure S1 and S2 in supplementary information memo.\
|
| 19 |
+
\
|
| 20 |
+
2. gender_disagregated_8-8-21.rds - Dataset of directed party dyads, disaggregated by gender of partisans, associated with codebook \'93Codebook for Gender Disaggregated Dyadic Party Dataset\'94. Dataset required to replicate Table 1 in main article, as well as Table S2 in the supplementary \cf4 information memo\cf2 .\
|
| 21 |
+
\
|
| 22 |
+
3. multilevel_1-5-22.Rdata - Dataset of individual evaluations of out-parties, with contextual variables, associated with Codebook \'93Codebook for Multilevel Dataset\'94. Required to replicate Tables S11 and S12 in the supplementary information memo.\
|
| 23 |
+
\
|
| 24 |
+
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
|
| 25 |
+
|
| 26 |
+
\f1 \cf0 \cb1 \kerning1\expnd0\expndtw0 *** NOTE: TO RUN THESE FILES AS THEY ARE SET UP, CREATE A DIRECTORY INCLUDING ALL THREE DATASETS***\
|
| 27 |
+
\
|
| 28 |
+
}
|
10/replication_package/replication_code.R
ADDED
|
@@ -0,0 +1,716 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#install.packages("tidyverse")
|
| 2 |
+
#install.packages("stargazer")
|
| 3 |
+
library(tidyverse) ##data cleaning
|
| 4 |
+
library(stargazer) ##tex output
|
| 5 |
+
library(haven)
|
| 6 |
+
library(estimatr)
|
| 7 |
+
library(dplyr)
|
| 8 |
+
library(fixest)
|
| 9 |
+
library(modelsummary)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
############################################
|
| 13 |
+
############## CREATING FIGURE 1 ###########
|
| 14 |
+
############################################
|
| 15 |
+
|
| 16 |
+
#Load in data
|
| 17 |
+
load("dyadic_data_1-4-22.Rdata")
|
| 18 |
+
dta <- updated_data
|
| 19 |
+
|
| 20 |
+
#### Remove unneeded variables
|
| 21 |
+
vars <- c("to_mp_number", "to_rile", "to_economy", "to_society", "year", "country",
|
| 22 |
+
"to_pfeml", "to_femaleleader")
|
| 23 |
+
dta <- dta[vars]
|
| 24 |
+
dta <- na.omit(dta)
|
| 25 |
+
|
| 26 |
+
### Identiy unique parties being evaluated
|
| 27 |
+
dta_unique <- unique(dta)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
fig1 <- ggplot(dta_unique, aes(x = to_pfeml)) +
|
| 31 |
+
geom_histogram(color="black", fill="grey40", binwidth =0.1, center=0.25) +
|
| 32 |
+
scale_x_continuous(breaks = seq(0,1,0.1)) +
|
| 33 |
+
theme_minimal() +
|
| 34 |
+
theme(plot.title = element_text(size=12)) +
|
| 35 |
+
ylab("Frequency")+
|
| 36 |
+
xlab("Proportion of Women MPs");fig1
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
############################################
|
| 40 |
+
###### CREATING TABLE 1 COLUMNS 1 & 2 ######
|
| 41 |
+
############################################
|
| 42 |
+
|
| 43 |
+
#Out party % women, non-clustered SEs
|
| 44 |
+
load("dyadic_data_1-4-22.Rdata")
|
| 45 |
+
|
| 46 |
+
dta <-updated_data
|
| 47 |
+
|
| 48 |
+
#creating the country-year fixed effects
|
| 49 |
+
dta$cntryyr <-paste(dta$country, dta$year, sep = "")
|
| 50 |
+
|
| 51 |
+
## Removing smaller parties
|
| 52 |
+
dta <- subset(dta, dta$to_prior_seats >=4)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
vars <- c("rile_distance_s", "prior_coalition", "prior_opposition", "econ_distance_s", "society_distance_s",
|
| 56 |
+
"year", "country", "party_dislike", "party_like", "cntryyr", "to_pfeml", "to_prior_seats", "to_mp_number")
|
| 57 |
+
dta <- dta[vars]
|
| 58 |
+
dta <- na.omit(dta)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
table1.1 <-lm(party_like ~ to_pfeml + as.factor(cntryyr), data = dta)
|
| 62 |
+
table1.2 <-lm(party_like ~ to_pfeml + rile_distance_s + prior_coalition + prior_opposition + as.factor(cntryyr), data = dta)
|
| 63 |
+
|
| 64 |
+
### With clustered SEs
|
| 65 |
+
stargazer(table1.1, table1.2,
|
| 66 |
+
add.lines = list(c("Country-Year Fixed Effects?", "Yes"), c("Country-Level Clustered SEs?", "Yes")),
|
| 67 |
+
se = starprep(table1.1, table1.2,
|
| 68 |
+
clusters = dta$country),
|
| 69 |
+
keep = c("to_pfeml", "rile_distance_s", "prior_coalition", "prior_opposition",
|
| 70 |
+
"econ_distance_s", "society_distance_s"))
|
| 71 |
+
|
| 72 |
+
############################################
|
| 73 |
+
###### CREATING TABLE 1 COLUMNS 3 & 4 ######
|
| 74 |
+
############################################
|
| 75 |
+
|
| 76 |
+
## Note in gendered data, the party_like and party_dislike variable indicate mean levels of
|
| 77 |
+
## like/dislike for party by ALL partisans
|
| 78 |
+
## the "dislike" variable indicates level of dislike towards out-party by partisans of specified gender
|
| 79 |
+
dta <- readRDS("gender_disagregated_8-8-21.rds")
|
| 80 |
+
|
| 81 |
+
#creating the country-year fixed effects
|
| 82 |
+
dta$countryyear <-paste(dta$country, dta$year, sep = "")
|
| 83 |
+
|
| 84 |
+
## Removing smaller parties
|
| 85 |
+
dta <- subset(dta, dta$to_prior_seats >=4)
|
| 86 |
+
|
| 87 |
+
### Create Like variable for gendered data from dislike
|
| 88 |
+
dta$like <- 10- dta$dislike
|
| 89 |
+
|
| 90 |
+
## Remove unneeded variables and NAs
|
| 91 |
+
vars <- c("rile_distance_s", "prior_coalition", "prior_opposition", "econ_distance_s", "society_distance_s",
|
| 92 |
+
"year", "country", "to_pfeml",
|
| 93 |
+
"countryyear", "gender", "like", "dislike", "to_prior_seats")
|
| 94 |
+
dta <- dta[vars]
|
| 95 |
+
dta <- na.omit(dta)
|
| 96 |
+
|
| 97 |
+
## Only men subset
|
| 98 |
+
dta_male <- subset(dta, gender==1)
|
| 99 |
+
dta_female <- subset(dta, gender==2)
|
| 100 |
+
|
| 101 |
+
table1.3 <-lm(like ~ to_pfeml + rile_distance_s + prior_coalition + prior_opposition + as.factor(countryyear), data = dta_female)
|
| 102 |
+
table1.4 <-lm(like ~ to_pfeml + rile_distance_s + prior_coalition + prior_opposition + as.factor(countryyear), data = dta_male)
|
| 103 |
+
|
| 104 |
+
### With clustered SEs - women
|
| 105 |
+
stargazer(table1.3,
|
| 106 |
+
add.lines = list(c("Country-Year Fixed Effects?", "Yes"), c("Out-Party Fixed Effects?", "Yes"), c("Country-Level Clustered SEs?", "Yes")),
|
| 107 |
+
se = starprep(table1.3,
|
| 108 |
+
clusters = dta_female$country),
|
| 109 |
+
keep = c("to_pfeml", "rile_distance_s", "prior_coalition", "prior_opposition", "to_pfeml2"))
|
| 110 |
+
|
| 111 |
+
### With clustered SEs - men
|
| 112 |
+
stargazer(table1.4,
|
| 113 |
+
add.lines = list(c("Country-Year Fixed Effects?", "Yes"), c("Out-Party Fixed Effects?", "Yes"), c("Country-Level Clustered SEs?", "Yes")),
|
| 114 |
+
se = starprep(table1.4,
|
| 115 |
+
clusters = dta_male$country),
|
| 116 |
+
keep = c("to_pfeml", "rile_distance_s", "prior_coalition", "prior_opposition", "to_pfeml2"))
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
############################################
|
| 120 |
+
###### CREATING TABLE S2 COLUMNS 1 & 2 ######
|
| 121 |
+
############################################
|
| 122 |
+
|
| 123 |
+
#Out party % women, non-clustered SEs
|
| 124 |
+
load("dyadic_data_1-4-22.Rdata")
|
| 125 |
+
|
| 126 |
+
dta <-updated_data
|
| 127 |
+
|
| 128 |
+
#creating the country-year fixed effects
|
| 129 |
+
dta$cntryyr <-paste(dta$country, dta$year, sep = "")
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
vars <- c("rile_distance_s", "prior_coalition", "prior_opposition", "econ_distance_s", "society_distance_s",
|
| 134 |
+
"year", "country", "party_dislike", "party_like", "cntryyr", "to_pfeml", "to_prior_seats", "to_mp_number")
|
| 135 |
+
dta <- dta[vars]
|
| 136 |
+
dta <- na.omit(dta)
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
tableS2.1 <-lm(party_like ~ to_pfeml + as.factor(cntryyr), data = dta)
|
| 140 |
+
tableS2.2 <-lm(party_like ~ to_pfeml + rile_distance_s + prior_coalition + prior_opposition + as.factor(cntryyr), data = dta)
|
| 141 |
+
|
| 142 |
+
summary(tableS2.1)
|
| 143 |
+
summary(tableS2.2)
|
| 144 |
+
|
| 145 |
+
### With clustered SEs
|
| 146 |
+
stargazer(tableS2.1, tableS2.2,
|
| 147 |
+
add.lines = list(c("Country-Year Fixed Effects?", "Yes"), c("Country-Level Clustered SEs?", "Yes")),
|
| 148 |
+
se = starprep(tableS2.1, tableS2.2,
|
| 149 |
+
clusters = dta$country),
|
| 150 |
+
keep = c("to_pfeml", "rile_distance_s", "prior_coalition", "prior_opposition",
|
| 151 |
+
"econ_distance_s", "society_distance_s"))
|
| 152 |
+
|
| 153 |
+
############################################
|
| 154 |
+
###### CREATING TABLE S2 COLUMNS 3 & 4 ######
|
| 155 |
+
############################################
|
| 156 |
+
|
| 157 |
+
dta <- readRDS("gender_disagregated_8-8-21.rds")
|
| 158 |
+
|
| 159 |
+
#creating the country-year fixed effects
|
| 160 |
+
dta$countryyear <-paste(dta$country, dta$year, sep = "")
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
### Create Like variable for gendered data from dislike
|
| 164 |
+
dta$like <- 10- dta$dislike
|
| 165 |
+
|
| 166 |
+
## Remove unneeded variables and NAs
|
| 167 |
+
vars <- c("rile_distance_s", "prior_coalition", "prior_opposition", "econ_distance_s", "society_distance_s",
|
| 168 |
+
"year", "country", "to_pfeml",
|
| 169 |
+
"countryyear", "gender", "like", "dislike", "to_prior_seats")
|
| 170 |
+
dta <- dta[vars]
|
| 171 |
+
dta <- na.omit(dta)
|
| 172 |
+
|
| 173 |
+
## Only men subset
|
| 174 |
+
dta_male <- subset(dta, gender==1)
|
| 175 |
+
dta_female <- subset(dta, gender==2)
|
| 176 |
+
|
| 177 |
+
tableS2.3 <-lm(like ~ to_pfeml + rile_distance_s + prior_coalition + prior_opposition + as.factor(countryyear), data = dta_female)
|
| 178 |
+
tableS2.4 <-lm(like ~ to_pfeml + rile_distance_s + prior_coalition + prior_opposition + as.factor(countryyear), data = dta_male)
|
| 179 |
+
|
| 180 |
+
summary(tableS2.3)
|
| 181 |
+
summary(tableS2.4)
|
| 182 |
+
|
| 183 |
+
### With clustered SEs - women
|
| 184 |
+
stargazer(tableS2.3,
|
| 185 |
+
add.lines = list(c("Country-Year Fixed Effects?", "Yes"), c("Out-Party Fixed Effects?", "Yes"), c("Country-Level Clustered SEs?", "Yes")),
|
| 186 |
+
se = starprep(tableS2.3,
|
| 187 |
+
clusters = dta_female$country),
|
| 188 |
+
keep = c("to_pfeml", "rile_distance_s", "prior_coalition", "prior_opposition", "to_pfeml2"))
|
| 189 |
+
|
| 190 |
+
### With clustered SEs - men
|
| 191 |
+
stargazer(tableS2.4,
|
| 192 |
+
add.lines = list(c("Country-Year Fixed Effects?", "Yes"), c("Out-Party Fixed Effects?", "Yes"), c("Country-Level Clustered SEs?", "Yes")),
|
| 193 |
+
se = starprep(tableS2.4,
|
| 194 |
+
clusters = dta_male$country),
|
| 195 |
+
keep = c("to_pfeml", "rile_distance_s", "prior_coalition", "prior_opposition", "to_pfeml2"))
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
############################################
|
| 199 |
+
############ CREATING TABLE S3 #############
|
| 200 |
+
############################################
|
| 201 |
+
|
| 202 |
+
## Read in data
|
| 203 |
+
load("dyadic_data_1-4-22.Rdata")
|
| 204 |
+
|
| 205 |
+
dta <-updated_data
|
| 206 |
+
colnames(dta)
|
| 207 |
+
|
| 208 |
+
#creating the country-year fixed effects
|
| 209 |
+
dta$cntryyr <-paste(dta$country, dta$year, sep = "")
|
| 210 |
+
vars <- c("rile_distance_s", "prior_coalition", "prior_opposition", "econ_distance_s", "society_distance_s",
|
| 211 |
+
"year", "country", "party_dislike","party_like", "cntryyr", "to_pfeml", "from_rile", "to_rile",
|
| 212 |
+
"from_left_bloc", "from_right_bloc", "to_left_bloc", "to_right_bloc", "from_parfam", "to_parfam",
|
| 213 |
+
"to_prior_seats")
|
| 214 |
+
dta <- dta[vars]
|
| 215 |
+
dta <- na.omit(dta)
|
| 216 |
+
|
| 217 |
+
dta_nrr <- subset(dta, dta$to_parfam!=70)
|
| 218 |
+
dta_nrr <- subset(dta_nrr, dta_nrr$from_parfam!=70)
|
| 219 |
+
|
| 220 |
+
## Remove small parties, with fewer than 4 seats
|
| 221 |
+
dta_small_nrr <- subset(dta_nrr, dta_nrr$to_prior_seats >=4)
|
| 222 |
+
|
| 223 |
+
table.S3 <-lm(party_like ~ to_pfeml + rile_distance_s + prior_coalition + prior_opposition + as.factor(country), data = dta_small_nrr)
|
| 224 |
+
summary(table.S3)
|
| 225 |
+
|
| 226 |
+
stargazer(table.S3,
|
| 227 |
+
add.lines = list(c("Country-Year Fixed Effects?", "Yes"), c("Country-Level Clustered SEs?", "Yes")),
|
| 228 |
+
se = starprep(table.S3,
|
| 229 |
+
clusters = dta_small_nrr$country),
|
| 230 |
+
keep = c("to_pfeml", "rile_distance_s", "prior_coalition", "prior_opposition",
|
| 231 |
+
"econ_distance_s", "society_distance_s"))
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
############################################
|
| 235 |
+
############ CREATING TABLE S3B ############
|
| 236 |
+
############################################
|
| 237 |
+
|
| 238 |
+
## Load
|
| 239 |
+
load("dyadic_data_1-4-22.Rdata")
|
| 240 |
+
|
| 241 |
+
dta <-updated_data
|
| 242 |
+
|
| 243 |
+
#creating the country-year fixed effects
|
| 244 |
+
vars <- c("rile_distance_s", "prior_coalition", "prior_opposition", "econ_distance_s", "society_distance_s",
|
| 245 |
+
"year", "country", "party_dislike", "party_like", "to_parfam", "to_left_bloc", "to_right_bloc", "cntryyr", "to_pfeml",
|
| 246 |
+
"to_prior_seats")
|
| 247 |
+
dta <- dta[vars]
|
| 248 |
+
dta <- na.omit(dta)
|
| 249 |
+
|
| 250 |
+
## Remove small parties, with fewer than 4 seats
|
| 251 |
+
dta_small <- subset(dta, dta$to_prior_seats >=4)
|
| 252 |
+
|
| 253 |
+
table.3B.1 <-lm(party_like ~ to_pfeml + as.factor(cntryyr), data = dta_small)
|
| 254 |
+
table.3B.2 <-lm(party_like ~ to_pfeml + rile_distance_s + to_left_bloc + prior_coalition + prior_opposition + as.factor(cntryyr), data = dta_small)
|
| 255 |
+
|
| 256 |
+
summary(table.3B.2)
|
| 257 |
+
|
| 258 |
+
### With clustered SEs
|
| 259 |
+
stargazer(table.3B.1, table.3B.2,
|
| 260 |
+
add.lines = list(c("Country-Year Fixed Effects?", "Yes"), c("Country-Level Clustered SEs?", "Yes")),
|
| 261 |
+
se = starprep(table.3B.1, table.3B.2,
|
| 262 |
+
clusters = dta_small$country),
|
| 263 |
+
keep = c("to_pfeml", "rile_distance_s", "to_left_bloc", "prior_coalition", "prior_opposition",
|
| 264 |
+
"econ_distance_s", "society_distance_s"))
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
############################################
|
| 268 |
+
############ CREATING TABLE S4 ############
|
| 269 |
+
############################################
|
| 270 |
+
|
| 271 |
+
## Read in data
|
| 272 |
+
load("dyadic_data_1-4-22.Rdata")
|
| 273 |
+
|
| 274 |
+
dta <-updated_data
|
| 275 |
+
|
| 276 |
+
#creating the country-year fixed effects
|
| 277 |
+
dta$countryyear <-paste(dta$country, dta$year, sep = "")
|
| 278 |
+
vars <- c("rile_distance_s", "prior_coalition", "prior_opposition", "econ_distance_s", "society_distance_s",
|
| 279 |
+
"year", "country", "party_dislike","party_like", "countryyear", "to_pfeml", "from_rile", "to_rile",
|
| 280 |
+
"logDM", "to_left_bloc", "to_prior_seats")
|
| 281 |
+
dta <- dta[vars]
|
| 282 |
+
dta <- na.omit(dta)
|
| 283 |
+
|
| 284 |
+
### Split by year, 1996-2006 and 2007-2017
|
| 285 |
+
dta_early <- subset(dta, dta$year<=2006)
|
| 286 |
+
dta_late <- subset(dta, dta$year>=2007)
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
table.early <-lm(party_like ~ to_pfeml + rile_distance_s + prior_coalition + prior_opposition + as.factor(countryyear), data = dta_early)
|
| 290 |
+
table.late <-lm(party_like ~ to_pfeml + rile_distance_s + prior_coalition + prior_opposition + as.factor(countryyear), data = dta_late)
|
| 291 |
+
|
| 292 |
+
### Without small parties
|
| 293 |
+
dta_early_small <- subset(dta_early, dta_early$to_prior_seats >=4)
|
| 294 |
+
dta_late_small <- subset(dta_late, dta_late$to_prior_seats >=4)
|
| 295 |
+
|
| 296 |
+
table.4.1 <-lm(party_like ~ to_pfeml + rile_distance_s + prior_coalition + prior_opposition + as.factor(countryyear), data = dta_early_small)
|
| 297 |
+
table.4.2 <-lm(party_like ~ to_pfeml + rile_distance_s + prior_coalition + prior_opposition + as.factor(countryyear), data = dta_late_small)
|
| 298 |
+
|
| 299 |
+
summary(table.4.1)
|
| 300 |
+
summary(table.4.2)
|
| 301 |
+
|
| 302 |
+
### With clustered SEs
|
| 303 |
+
stargazer(table.4.1,
|
| 304 |
+
add.lines = list(c("Country-Year Fixed Effects?", "Yes"), c("Out-Party Fixed Effects?", "Yes"), c("Country-Level Clustered SEs?", "Yes")),
|
| 305 |
+
se = starprep(table.4.1,
|
| 306 |
+
clusters = dta_early_small$country),
|
| 307 |
+
keep = c("to_pfeml", "rile_distance_s", "prior_coalition", "prior_opposition"
|
| 308 |
+
))
|
| 309 |
+
|
| 310 |
+
### With clustered SEs
|
| 311 |
+
stargazer(table.4.2,
|
| 312 |
+
add.lines = list(c("Country-Year Fixed Effects?", "Yes"), c("Out-Party Fixed Effects?", "Yes"), c("Country-Level Clustered SEs?", "Yes")),
|
| 313 |
+
se = starprep(table.4.2,
|
| 314 |
+
clusters = dta_late_small$country),
|
| 315 |
+
keep = c("to_pfeml", "rile_distance_s", "prior_coalition", "prior_opposition"
|
| 316 |
+
))
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
############################################
|
| 321 |
+
############ CREATING TABLE S5 #############
|
| 322 |
+
############################################
|
| 323 |
+
|
| 324 |
+
load("dyadic_data_1-4-22.Rdata")
|
| 325 |
+
|
| 326 |
+
dta <-updated_data
|
| 327 |
+
|
| 328 |
+
#creating the country-year fixed effects
|
| 329 |
+
dta$countryyear <-paste(dta$country, dta$year, sep = "")
|
| 330 |
+
vars <- c("rile_distance_s", "prior_coalition", "prior_opposition", "econ_distance_s", "society_distance_s",
|
| 331 |
+
"year", "country", "party_dislike", "party_like", "countryyear",
|
| 332 |
+
"to_pfeml", "from_pfeml", "diff_pfeml", "to_prior_seats")
|
| 333 |
+
dta <- dta[vars]
|
| 334 |
+
dta <- na.omit(dta)
|
| 335 |
+
|
| 336 |
+
## Remove small parties, with fewer than 4 seats
|
| 337 |
+
dta_small <- subset(dta, dta$to_prior_seats >=4)
|
| 338 |
+
|
| 339 |
+
table.S5.1 <-lm(party_like ~ to_pfeml + from_pfeml + diff_pfeml + as.factor(countryyear), data = dta_small)
|
| 340 |
+
table.S5.2 <-lm(party_like ~ to_pfeml + from_pfeml + diff_pfeml + rile_distance_s + prior_coalition + prior_opposition + as.factor(countryyear), data = dta_small)
|
| 341 |
+
|
| 342 |
+
summary(table.S5.1)
|
| 343 |
+
summary(table.S5.2)
|
| 344 |
+
|
| 345 |
+
### With clustered SEs
|
| 346 |
+
stargazer(table.S5.1, table.S5.2,
|
| 347 |
+
add.lines = list(c("Country-Year Fixed Effects?", "Yes"), c("Country-Level Clustered SEs?", "Yes")),
|
| 348 |
+
se = starprep(table.S5.1, table.S5.2,
|
| 349 |
+
clusters = dta_small$country),
|
| 350 |
+
keep = c("to_pfeml", "from_pfeml", "diff_pfeml", "rile_distance_s", "prior_coalition", "prior_opposition",
|
| 351 |
+
"econ_distance_s", "society_distance_s"))
|
| 352 |
+
|
| 353 |
+
############################################
|
| 354 |
+
############ CREATING FIG. S1 #############
|
| 355 |
+
############################################
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
### Create Plot Data
|
| 359 |
+
|
| 360 |
+
## All values of Out-Party % women
|
| 361 |
+
plot_1 <- as.data.frame((unique(dta$to_pfeml)))
|
| 362 |
+
colnames(plot_1) <- c("to_pfeml")
|
| 363 |
+
|
| 364 |
+
## All 1 Sd above mean of In-party % women
|
| 365 |
+
plot_1$from_pfeml <- mean(dta$from_pfeml, na.rm=T) + sd(dta$from_pfeml, na.rm=T)
|
| 366 |
+
|
| 367 |
+
## Create difference between in-and out-party women
|
| 368 |
+
plot_1$diff_pfeml <- abs(plot_1$to_pfeml - plot_1$from_pfeml)
|
| 369 |
+
|
| 370 |
+
## Select other values (mean RILE distance, opposition together, France 2012 country year)
|
| 371 |
+
plot_1$rile_distance_s <- mean(dta$rile_distance_s, na.rm=T)
|
| 372 |
+
plot_1$prior_coalition <- 0
|
| 373 |
+
plot_1$prior_opposition <- 1
|
| 374 |
+
plot_1$countryyear <- "France2012"
|
| 375 |
+
plot_1$to_mp_number <- "31320"
|
| 376 |
+
plot_1$group <- "above_mean"
|
| 377 |
+
|
| 378 |
+
## All values of Out-Party % women
|
| 379 |
+
plot_2 <- as.data.frame((unique(dta$to_pfeml)))
|
| 380 |
+
colnames(plot_2) <- c("to_pfeml")
|
| 381 |
+
|
| 382 |
+
## All 1 Sd below mean of In-party % women
|
| 383 |
+
plot_2$from_pfeml <- mean(dta$from_pfeml, na.rm=T) - sd(dta$from_pfeml, na.rm=T)
|
| 384 |
+
|
| 385 |
+
## Create difference between in-and out-party women
|
| 386 |
+
plot_2$diff_pfeml <- abs(plot_2$to_pfeml - plot_2$from_pfeml)
|
| 387 |
+
|
| 388 |
+
## Select other values (opposition together, France 2012 country year)
|
| 389 |
+
plot_2$rile_distance_s <- mean(dta$rile_distance_s, na.rm=T)
|
| 390 |
+
plot_2$prior_coalition <- 0
|
| 391 |
+
plot_2$prior_opposition <- 1
|
| 392 |
+
plot_2$countryyear <- "France2012"
|
| 393 |
+
plot_2$to_mp_number <- "31320"
|
| 394 |
+
plot_2$group <- "below_mean"
|
| 395 |
+
|
| 396 |
+
plot_dta <- rbind(plot_1, plot_2)
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
###### Plot based on table.S5.2
|
| 400 |
+
figureS1.data <- as.data.frame(predict(table.S5.2, newdata = plot_dta, interval = "confidence"))
|
| 401 |
+
|
| 402 |
+
plot_dta$fit <- figureS1.data$fit
|
| 403 |
+
plot_dta$lwr <- figureS1.data$lwr
|
| 404 |
+
plot_dta$upr <- figureS1.data$upr
|
| 405 |
+
|
| 406 |
+
figS1 <- ggplot(plot_dta, aes(x=to_pfeml, y=fit, lty=group))
|
| 407 |
+
figS1 <- figS1 + geom_line() +
|
| 408 |
+
geom_ribbon(aes(x = to_pfeml, y = fit, ymin = lwr,
|
| 409 |
+
ymax = upr),
|
| 410 |
+
lwd = 1/2, alpha=0.1) +
|
| 411 |
+
theme_minimal() +
|
| 412 |
+
theme(plot.title = element_text(size=12)) +
|
| 413 |
+
ylab("Predicted Out-Party Thermometer Rating")+
|
| 414 |
+
xlab("Proportion of Out-Party Women MPs") +
|
| 415 |
+
theme(legend.position = "none") +
|
| 416 |
+
geom_text(x=0.70, y=5.3, label="in-party % of women is \n1 SD above the mean") +
|
| 417 |
+
geom_text(x=0.70, y=4.0, label="in-party % of women is \n1 SD below the mean", color="grey37") +
|
| 418 |
+
ylim(c(2.5,6.5));figS1
|
| 419 |
+
|
| 420 |
+
pdf("figS1.pdf")
|
| 421 |
+
figS1
|
| 422 |
+
dev.off()
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
############################################
|
| 426 |
+
############ CREATING TABLE S6 #############
|
| 427 |
+
############################################
|
| 428 |
+
|
| 429 |
+
## Read in data
|
| 430 |
+
load("dyadic_data_1-4-22.Rdata")
|
| 431 |
+
|
| 432 |
+
dta <-updated_data
|
| 433 |
+
|
| 434 |
+
#creating the country-year fixed effects
|
| 435 |
+
dta$countryyear <-paste(dta$country, dta$year, sep = "")
|
| 436 |
+
vars <- c("rile_distance_s", "prior_coalition", "prior_opposition", "econ_distance_s", "society_distance_s",
|
| 437 |
+
"year", "country", "party_dislike","party_like", "countryyear", "to_pfeml", "from_rile", "to_rile",
|
| 438 |
+
"logDM", "to_left_bloc", "to_prior_seats")
|
| 439 |
+
dta <- dta[vars]
|
| 440 |
+
dta <- na.omit(dta)
|
| 441 |
+
|
| 442 |
+
dta_small <- subset(dta, dta$to_prior_seats >=4)
|
| 443 |
+
|
| 444 |
+
table.S6.1 <-lm(party_like ~ to_pfeml + rile_distance_s + logDM + prior_coalition + prior_opposition + as.factor(year), data = dta_small)
|
| 445 |
+
table.S6.2 <-lm(party_like ~ to_pfeml*logDM + rile_distance_s + prior_coalition + prior_opposition + as.factor(year), data = dta_small)
|
| 446 |
+
table.S6.3 <-lm(party_like ~ to_pfeml*logDM + rile_distance_s*logDM + prior_coalition*logDM + prior_opposition*logDM + as.factor(year), data = dta_small)
|
| 447 |
+
|
| 448 |
+
summary(table.S6.1)
|
| 449 |
+
summary(table.S6.2)
|
| 450 |
+
summary(table.S6.3)
|
| 451 |
+
|
| 452 |
+
stargazer(table.S6.1, table.S6.2, table.S6.3,
|
| 453 |
+
add.lines = list(c("Country-Year Fixed Effects?", "Yes"), c("Country-Level Clustered SEs?", "Yes")),
|
| 454 |
+
se = starprep(table.S6.1, table.S6.2, table.S6.3,
|
| 455 |
+
clusters = dta_small$country),
|
| 456 |
+
keep = c("to_pfeml", "rile_distance_s", "logDM", "prior_coalition", "prior_opposition",
|
| 457 |
+
"econ_distance_s", "society_distance_s"))
|
| 458 |
+
|
| 459 |
+
|
| 460 |
+
############################################
|
| 461 |
+
############ CREATING TABLE S7 #############
|
| 462 |
+
############################################
|
| 463 |
+
|
| 464 |
+
#Out party % women, non-clustered SEs
|
| 465 |
+
load("dyadic_data_1-4-22.Rdata")
|
| 466 |
+
|
| 467 |
+
dta <-updated_data
|
| 468 |
+
|
| 469 |
+
#creating the country-year fixed effects
|
| 470 |
+
dta$cntryyr <-paste(dta$country, dta$year, sep = "")
|
| 471 |
+
vars <- c("rile_distance_s", "prior_coalition", "prior_opposition", "econ_distance_s", "society_distance_s",
|
| 472 |
+
"year", "country", "party_dislike", "party_like", "cntryyr", "to_pfeml", "to_prior_seats")
|
| 473 |
+
dta <- dta[vars]
|
| 474 |
+
dta <- na.omit(dta)
|
| 475 |
+
|
| 476 |
+
## Creating squared term for out-party % women
|
| 477 |
+
dta$to_pfeml2 <- dta$to_pfeml^2
|
| 478 |
+
|
| 479 |
+
## Remove small parties, with fewer than 4 seats
|
| 480 |
+
dta <- subset(dta, dta$to_prior_seats >=4)
|
| 481 |
+
|
| 482 |
+
table.S7.1 <-lm(party_like ~ to_pfeml + to_pfeml2 + as.factor(cntryyr), data = dta)
|
| 483 |
+
table.S7.2 <-lm(party_like ~ to_pfeml + to_pfeml2 + rile_distance_s + prior_coalition + prior_opposition + as.factor(cntryyr), data = dta)
|
| 484 |
+
|
| 485 |
+
summary(table.S7.1)
|
| 486 |
+
summary(table.S7.2)
|
| 487 |
+
|
| 488 |
+
### With clustered SEs
|
| 489 |
+
stargazer(table.S7.1, table.S7.2,
|
| 490 |
+
add.lines = list(c("Country-Year Fixed Effects?", "Yes"), c("Country-Level Clustered SEs?", "Yes")),
|
| 491 |
+
se = starprep(table.S7.1, table.S7.2,
|
| 492 |
+
clusters = dta$country),
|
| 493 |
+
keep = c("to_pfeml", "to_pfeml2", "rile_distance_s", "prior_coalition", "prior_opposition",
|
| 494 |
+
"econ_distance_s", "society_distance_s"))
|
| 495 |
+
|
| 496 |
+
############################################
|
| 497 |
+
############ CREATING FIG. S2 #############
|
| 498 |
+
############################################
|
| 499 |
+
|
| 500 |
+
### Create Plot Data
|
| 501 |
+
|
| 502 |
+
## All values of Out-Party % women
|
| 503 |
+
plot_S2 <- as.data.frame((unique(dta$to_pfeml)))
|
| 504 |
+
colnames(plot_S2) <- c("to_pfeml")
|
| 505 |
+
|
| 506 |
+
## Create difference between in-and out-party women
|
| 507 |
+
plot_S2$to_pfeml2 <- plot_S2$to_pfeml^2
|
| 508 |
+
|
| 509 |
+
## Select other values (mean RILE distance, opposition together, France 2012 country year)
|
| 510 |
+
plot_S2$rile_distance_s <- mean(dta$rile_distance_s, na.rm=T)
|
| 511 |
+
plot_S2$prior_coalition <- 0
|
| 512 |
+
plot_S2$prior_opposition <- 1
|
| 513 |
+
plot_S2$cntryyr <- "France2012"
|
| 514 |
+
plot_S2$to_mp_number <- "31320"
|
| 515 |
+
|
| 516 |
+
figureS2.data <- as.data.frame(predict(table.S7.2, newdata = plot_S2, interval = "confidence"))
|
| 517 |
+
|
| 518 |
+
plot_S2$fit <- figureS2.data$fit
|
| 519 |
+
plot_S2$lwr <- figureS2.data$lwr
|
| 520 |
+
plot_S2$upr <- figureS2.data$upr
|
| 521 |
+
|
| 522 |
+
figS2 <- ggplot(plot_S2, aes(x=to_pfeml, y=fit))
|
| 523 |
+
figS2 <- figS2 + geom_line() +
|
| 524 |
+
geom_ribbon(aes(x = to_pfeml, y = fit, ymin = lwr,
|
| 525 |
+
ymax = upr),
|
| 526 |
+
lwd = 1/2, alpha=0.1) +
|
| 527 |
+
theme_minimal() +
|
| 528 |
+
theme(plot.title = element_text(size=12)) +
|
| 529 |
+
ylab("Predicted Out-Party Thermometer Rating")+
|
| 530 |
+
xlab("Proportion of Out-Party Women MPs") +
|
| 531 |
+
ylim(c(2,5));figS2
|
| 532 |
+
|
| 533 |
+
pdf("figS2.pdf")
|
| 534 |
+
figS2
|
| 535 |
+
dev.off()
|
| 536 |
+
|
| 537 |
+
############################################
|
| 538 |
+
############ CREATING TABLE S8 #############
|
| 539 |
+
############################################
|
| 540 |
+
|
| 541 |
+
#Women-led parties
|
| 542 |
+
load("dyadic_data_1-4-22.Rdata")
|
| 543 |
+
|
| 544 |
+
dta <-updated_data
|
| 545 |
+
|
| 546 |
+
dta_womenlead <- subset(dta, dta$to_femaleleader==1)
|
| 547 |
+
|
| 548 |
+
#creating the country-year fixed effects
|
| 549 |
+
dta_womenlead$countryyear <-paste(dta_womenlead$country, dta_womenlead$year, sep = "")
|
| 550 |
+
vars <- c("rile_distance_s", "prior_coalition", "prior_opposition", "econ_distance_s", "society_distance_s",
|
| 551 |
+
"year", "country", "party_dislike","party_like", "countryyear", "to_pfeml", "to_prior_seats")
|
| 552 |
+
dta_womenlead <- dta_womenlead[vars]
|
| 553 |
+
dta_womenlead <- na.omit(dta_womenlead)
|
| 554 |
+
|
| 555 |
+
## Exclude small parties
|
| 556 |
+
dta_womenlead <- subset(dta_womenlead, dta_womenlead$to_prior_seats >=4)
|
| 557 |
+
|
| 558 |
+
table.S8A1 <-lm(party_like ~ to_pfeml + as.factor(countryyear), data = dta_womenlead)
|
| 559 |
+
table.S8A2 <-lm(party_like ~ to_pfeml + rile_distance_s + prior_coalition + prior_opposition + as.factor(countryyear), data = dta_womenlead)
|
| 560 |
+
|
| 561 |
+
summary(table.S8A1)
|
| 562 |
+
summary(table.S8A2)
|
| 563 |
+
|
| 564 |
+
### With clustered SEs
|
| 565 |
+
stargazer(table.S8A1, table.S8A2,
|
| 566 |
+
add.lines = list(c("Country-Year Fixed Effects?", "Yes"), c("Country-Level Clustered SEs?", "Yes")),
|
| 567 |
+
se = starprep(table.S8A1, table.S8A2,
|
| 568 |
+
clusters = dta_womenlead$country),
|
| 569 |
+
keep = c("to_pfeml", "rile_distance_s", "prior_coalition", "prior_opposition",
|
| 570 |
+
"econ_distance_s", "society_distance_s"))
|
| 571 |
+
|
| 572 |
+
#Male-led parties
|
| 573 |
+
load("dyadic_data_1-4-22.Rdata")
|
| 574 |
+
dta <-updated_data
|
| 575 |
+
|
| 576 |
+
dta_malelead <- subset(dta, dta$to_femaleleader==0)
|
| 577 |
+
|
| 578 |
+
#creating the country-year fixed effects
|
| 579 |
+
dta_malelead$countryyear <-paste(dta_malelead$country, dta_malelead$year, sep = "")
|
| 580 |
+
vars <- c("rile_distance_s", "prior_coalition", "prior_opposition", "econ_distance_s", "society_distance_s",
|
| 581 |
+
"year", "country", "party_dislike","party_like", "countryyear", "to_pfeml", "to_prior_seats")
|
| 582 |
+
dta_malelead <- dta_malelead[vars]
|
| 583 |
+
dta_malelead <- na.omit(dta_malelead)
|
| 584 |
+
|
| 585 |
+
## Exclude small parties
|
| 586 |
+
dta_malelead <- subset(dta_malelead, dta_malelead$to_prior_seats >=4)
|
| 587 |
+
|
| 588 |
+
table.S8B1 <-lm(party_like ~ to_pfeml + as.factor(countryyear), data = dta_malelead)
|
| 589 |
+
table.S8B2 <-lm(party_like ~ to_pfeml + rile_distance_s + prior_coalition + prior_opposition + as.factor(countryyear), data = dta_malelead)
|
| 590 |
+
|
| 591 |
+
summary(table.S8B1)
|
| 592 |
+
summary(table.S8B2)
|
| 593 |
+
|
| 594 |
+
### With clustered SEs
|
| 595 |
+
stargazer(table.S8B1, table.S8B2,
|
| 596 |
+
add.lines = list(c("Country-Year Fixed Effects?", "Yes"), c("Country-Level Clustered SEs?", "Yes")),
|
| 597 |
+
se = starprep(table.S8B1, table.S8B2,
|
| 598 |
+
clusters = dta_malelead$country),
|
| 599 |
+
keep = c("to_pfeml", "rile_distance_s", "prior_coalition", "prior_opposition",
|
| 600 |
+
"econ_distance_s", "society_distance_s"))
|
| 601 |
+
|
| 602 |
+
############################################
|
| 603 |
+
############ CREATING TABLE S9 #############
|
| 604 |
+
############################################
|
| 605 |
+
|
| 606 |
+
## Read in data
|
| 607 |
+
load("dyadic_data_1-4-22.Rdata")
|
| 608 |
+
|
| 609 |
+
dta <- updated_data
|
| 610 |
+
|
| 611 |
+
#creating the country-year fixed effects
|
| 612 |
+
dta$countryyear <-paste(dta$country, dta$year, sep = "")
|
| 613 |
+
|
| 614 |
+
#creating the party fixed effects / cluster
|
| 615 |
+
dta$partydyad <-paste(dta$from_mp_number, dta$to_mp_number, sep = "")
|
| 616 |
+
|
| 617 |
+
vars <- c("rile_distance_s", "prior_coalition", "prior_opposition", "econ_distance_s", "society_distance_s",
|
| 618 |
+
"year", "country", "party_dislike","party_like", "countryyear", "to_pfeml",
|
| 619 |
+
"from_rile", "to_rile", "to_mp_number", "partydyad", "to_prior_seats")
|
| 620 |
+
dta <- dta[vars]
|
| 621 |
+
dta <- na.omit(dta)
|
| 622 |
+
|
| 623 |
+
## Exclude small parties
|
| 624 |
+
dta <- subset(dta, dta$to_prior_seats >=4)
|
| 625 |
+
|
| 626 |
+
table.S9 <-lm(party_like ~ to_pfeml + rile_distance_s + prior_coalition + prior_opposition + as.factor(countryyear), data = dta)
|
| 627 |
+
summary(table.S9)
|
| 628 |
+
|
| 629 |
+
### With clustered SEs
|
| 630 |
+
stargazer(table.S9,
|
| 631 |
+
add.lines = list(c("Country-Year Fixed Effects?", "Yes"), c("Out-Party Fixed Effects?", "Yes"), c("Country-Level Clustered SEs?", "Yes")),
|
| 632 |
+
se = starprep(table.S9,
|
| 633 |
+
clusters = dta$partydyad),
|
| 634 |
+
keep = c("to_pfeml", "rile_distance_s", "prior_coalition", "prior_opposition",
|
| 635 |
+
"econ_distance_s", "society_distance_s"))
|
| 636 |
+
|
| 637 |
+
|
| 638 |
+
############################################
|
| 639 |
+
############ CREATING TABLE 10 #############
|
| 640 |
+
############################################
|
| 641 |
+
|
| 642 |
+
load("dyadic_data_1-4-22.Rdata")
|
| 643 |
+
|
| 644 |
+
dta <-updated_data
|
| 645 |
+
|
| 646 |
+
vars <- c("rile_distance_s", "prior_coalition", "prior_opposition", "econ_distance_s", "society_distance_s",
|
| 647 |
+
"year", "country", "party_dislike", "to_pfeml", "party_like", "to_prior_seats")
|
| 648 |
+
dta <- dta[vars]
|
| 649 |
+
dta <- na.omit(dta)
|
| 650 |
+
|
| 651 |
+
## Remove small parties, with fewer than 4 seats
|
| 652 |
+
dta_small <- subset(dta, dta$to_prior_seats >=4)
|
| 653 |
+
|
| 654 |
+
table.S10.1 <-lm(party_like ~ to_pfeml + as.factor(country), data = dta_small)
|
| 655 |
+
table.S10.2 <-lm(party_like ~ to_pfeml + rile_distance_s + prior_coalition + prior_opposition + as.factor(country), data = dta_small)
|
| 656 |
+
|
| 657 |
+
summary(table.S10.2)
|
| 658 |
+
|
| 659 |
+
### With clustered SEs
|
| 660 |
+
stargazer(table.S10.1, table.S10.2,
|
| 661 |
+
add.lines = list(c("Country-Year Fixed Effects?", "Yes"), c("Country-Level Clustered SEs?", "Yes")),
|
| 662 |
+
se = starprep(table.S10.1, table.S10.2,
|
| 663 |
+
clusters = dta_small$country),
|
| 664 |
+
keep = c("to_pfeml", "rile_distance_s", "prior_coalition", "prior_opposition",
|
| 665 |
+
"econ_distance_s", "society_distance_s"))
|
| 666 |
+
|
| 667 |
+
##################################################
|
| 668 |
+
############ CREATING TABLES 11 & 12 #############
|
| 669 |
+
##################################################
|
| 670 |
+
|
| 671 |
+
load("Data/multilevel_1-5-22.Rdata")
|
| 672 |
+
|
| 673 |
+
indiv_data <-multilevel_data
|
| 674 |
+
|
| 675 |
+
|
| 676 |
+
vars <- c("rile_distance_s", "prior_coalition", "prior_opposition", "econ_distance_s", "society_distance_s",
|
| 677 |
+
"year", "country", "cntryyr", "to_pfeml", "from_pfeml", "thermometer_score", "ID", "party_to", "party_from",
|
| 678 |
+
"from_partyname", "to_partyname", "to_left_bloc", "from_left_bloc",
|
| 679 |
+
"to_right_bloc", "from_right_bloc", "gender", "to_parfam", "from_parfam", "to_prior_seats",
|
| 680 |
+
"from_mp_number", "to_mp_number")
|
| 681 |
+
|
| 682 |
+
|
| 683 |
+
indiv_data <- indiv_data[vars]
|
| 684 |
+
|
| 685 |
+
## Create gender variable
|
| 686 |
+
indiv_data <-mutate(indiv_data, gender = ifelse(gender == "1", "male",
|
| 687 |
+
ifelse(gender == "2", "female", NA)))
|
| 688 |
+
|
| 689 |
+
indiv_data$gender <-as.factor(indiv_data$gender)
|
| 690 |
+
|
| 691 |
+
##filter out parties with no data, mainly parties who were not in parliament plus a few cases from early 1990s
|
| 692 |
+
indiv_data <-filter(indiv_data, is.na(to_pfeml) == F)
|
| 693 |
+
|
| 694 |
+
### Create dyads for FEs/Clustered SEs
|
| 695 |
+
indiv_data$dyad <-paste(indiv_data$from_mp_number, indiv_data$to_mp_number, sep ="_to_")
|
| 696 |
+
|
| 697 |
+
### Create Table 11, column 1, with Standard errors clustered at country-year, party-dyad, and individual levels
|
| 698 |
+
table11A.1.1 <-feols(thermometer_score ~ to_pfeml | ID, data = indiv_data, cluster = ~cntryyr)
|
| 699 |
+
table11A.1.2 <-feols(thermometer_score ~ to_pfeml | ID, data = indiv_data, cluster = ~dyad)
|
| 700 |
+
table11A.1.3 <-feols(thermometer_score ~ to_pfeml | ID, data = indiv_data, cluster = ~ID)
|
| 701 |
+
|
| 702 |
+
### Create Table 11, column 2, with Standard errors clustered at country-year, party-dyad, and individual levels
|
| 703 |
+
table11A.2.1 <-feols(thermometer_score ~ to_pfeml + + rile_distance_s + prior_coalition + prior_opposition | ID, data = indiv_data, cluster = ~cntryyr)
|
| 704 |
+
table11A.2.2 <-feols(thermometer_score ~ to_pfeml + + rile_distance_s + prior_coalition + prior_opposition | ID, data = indiv_data, cluster = ~dyad)
|
| 705 |
+
table11A.2.3 <-feols(thermometer_score ~ to_pfeml + + rile_distance_s + prior_coalition + prior_opposition | ID, data = indiv_data, cluster = ~ID)
|
| 706 |
+
|
| 707 |
+
### Create Table 11B, column 1, with Standard errors clustered at country-year, party-dyad, and individual levels
|
| 708 |
+
table11B.1.1 <-feols(thermometer_score ~ to_pfeml | cntryyr, data = indiv_data, cluster = ~cntryyr)
|
| 709 |
+
table11B.1.2 <-feols(thermometer_score ~ to_pfeml | cntryyr, data = indiv_data, cluster = ~dyad)
|
| 710 |
+
table11B.1.3 <-feols(thermometer_score ~ to_pfeml | cntryyr, data = indiv_data, cluster = ~ID)
|
| 711 |
+
|
| 712 |
+
### Create Table 11B, column 2, with Standard errors clustered at country-year, party-dyad, and individual levels
|
| 713 |
+
table11B.2.1 <-feols(thermometer_score ~ to_pfeml + + rile_distance_s + prior_coalition + prior_opposition | cntryyr, data = indiv_data, cluster = ~cntryyr)
|
| 714 |
+
table11B.2.2 <-feols(thermometer_score ~ to_pfeml + + rile_distance_s + prior_coalition + prior_opposition | cntryyr, data = indiv_data, cluster = ~dyad)
|
| 715 |
+
table11B.2.3 <-feols(thermometer_score ~ to_pfeml + + rile_distance_s + prior_coalition + prior_opposition | cntryyr, data = indiv_data, cluster = ~ID)
|
| 716 |
+
|
10/should_reproduce.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e948c9ddded565a15bdaa55c5f0001dcc6e8f1c0857305a6eaf31e19ff7b2dc0
|
| 3 |
+
size 16
|
100/paper.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:89b75da0b3c2d121536a946d5462290f4c76c28dea1136e6881ec509912ad2e3
|
| 3 |
+
size 1115636
|
100/replication_package/journal.pone.0278164.s002.xlsx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:409dd972bffd5d800c816778c325ed8bc8e59ea48043e6faa00cc93a0b8ae0c6
|
| 3 |
+
size 4362713
|
100/should_reproduce.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8217d76d89509cec1c270c661a37fd2f3fd2e6ea45f303f42d77823b0f966ba2
|
| 3 |
+
size 59
|
101/paper.pdf
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0288699f0b4a67532df6cb1a3dd6391f46688831a3b092bea21f0fb35e1889d8
|
| 3 |
+
size 3262536
|
101/replication_package/.gitignore
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.Rproj.user
|
| 2 |
+
.Rhistory
|
| 3 |
+
.RData
|
| 4 |
+
.Ruserdata
|
| 5 |
+
.DS_Store
|
| 6 |
+
*.Rproj
|
| 7 |
+
|
| 8 |
+
*.RData
|
| 9 |
+
Table_of_Languages.tab
|
| 10 |
+
ethnologue_pop_full.tsv
|
| 11 |
+
pop.tsv
|
| 12 |
+
pop_full.tsv
|
| 13 |
+
GB_wide_strict.tsv
|
| 14 |
+
*.png
|
| 15 |
+
.xlsx
|
| 16 |
+
*.jpg
|
| 17 |
+
*.svg
|
| 18 |
+
*.tiff
|
| 19 |
+
*.emf
|
| 20 |
+
*.eps
|
| 21 |
+
*.ps
|
| 22 |
+
*.wmf
|
| 23 |
+
*.pptx
|
| 24 |
+
*.docx
|
| 25 |
+
*.pdf
|
| 26 |
+
*.jpeg
|
| 27 |
+
*.qs
|
| 28 |
+
|
| 29 |
+
#folders
|
| 30 |
+
*grambank-analysed*
|
101/replication_package/.gitmodules
ADDED
|
File without changes
|
101/replication_package/LICENSE.md
ADDED
|
@@ -0,0 +1,395 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Attribution 4.0 International
|
| 2 |
+
|
| 3 |
+
=======================================================================
|
| 4 |
+
|
| 5 |
+
Creative Commons Corporation ("Creative Commons") is not a law firm and
|
| 6 |
+
does not provide legal services or legal advice. Distribution of
|
| 7 |
+
Creative Commons public licenses does not create a lawyer-client or
|
| 8 |
+
other relationship. Creative Commons makes its licenses and related
|
| 9 |
+
information available on an "as-is" basis. Creative Commons gives no
|
| 10 |
+
warranties regarding its licenses, any material licensed under their
|
| 11 |
+
terms and conditions, or any related information. Creative Commons
|
| 12 |
+
disclaims all liability for damages resulting from their use to the
|
| 13 |
+
fullest extent possible.
|
| 14 |
+
|
| 15 |
+
Using Creative Commons Public Licenses
|
| 16 |
+
|
| 17 |
+
Creative Commons public licenses provide a standard set of terms and
|
| 18 |
+
conditions that creators and other rights holders may use to share
|
| 19 |
+
original works of authorship and other material subject to copyright
|
| 20 |
+
and certain other rights specified in the public license below. The
|
| 21 |
+
following considerations are for informational purposes only, are not
|
| 22 |
+
exhaustive, and do not form part of our licenses.
|
| 23 |
+
|
| 24 |
+
Considerations for licensors: Our public licenses are
|
| 25 |
+
intended for use by those authorized to give the public
|
| 26 |
+
permission to use material in ways otherwise restricted by
|
| 27 |
+
copyright and certain other rights. Our licenses are
|
| 28 |
+
irrevocable. Licensors should read and understand the terms
|
| 29 |
+
and conditions of the license they choose before applying it.
|
| 30 |
+
Licensors should also secure all rights necessary before
|
| 31 |
+
applying our licenses so that the public can reuse the
|
| 32 |
+
material as expected. Licensors should clearly mark any
|
| 33 |
+
material not subject to the license. This includes other CC-
|
| 34 |
+
licensed material, or material used under an exception or
|
| 35 |
+
limitation to copyright. More considerations for licensors:
|
| 36 |
+
wiki.creativecommons.org/Considerations_for_licensors
|
| 37 |
+
|
| 38 |
+
Considerations for the public: By using one of our public
|
| 39 |
+
licenses, a licensor grants the public permission to use the
|
| 40 |
+
licensed material under specified terms and conditions. If
|
| 41 |
+
the licensor's permission is not necessary for any reason--for
|
| 42 |
+
example, because of any applicable exception or limitation to
|
| 43 |
+
copyright--then that use is not regulated by the license. Our
|
| 44 |
+
licenses grant only permissions under copyright and certain
|
| 45 |
+
other rights that a licensor has authority to grant. Use of
|
| 46 |
+
the licensed material may still be restricted for other
|
| 47 |
+
reasons, including because others have copyright or other
|
| 48 |
+
rights in the material. A licensor may make special requests,
|
| 49 |
+
such as asking that all changes be marked or described.
|
| 50 |
+
Although not required by our licenses, you are encouraged to
|
| 51 |
+
respect those requests where reasonable. More_considerations
|
| 52 |
+
for the public:
|
| 53 |
+
wiki.creativecommons.org/Considerations_for_licensees
|
| 54 |
+
|
| 55 |
+
=======================================================================
|
| 56 |
+
|
| 57 |
+
Creative Commons Attribution 4.0 International Public License
|
| 58 |
+
|
| 59 |
+
By exercising the Licensed Rights (defined below), You accept and agree
|
| 60 |
+
to be bound by the terms and conditions of this Creative Commons
|
| 61 |
+
Attribution 4.0 International Public License ("Public License"). To the
|
| 62 |
+
extent this Public License may be interpreted as a contract, You are
|
| 63 |
+
granted the Licensed Rights in consideration of Your acceptance of
|
| 64 |
+
these terms and conditions, and the Licensor grants You such rights in
|
| 65 |
+
consideration of benefits the Licensor receives from making the
|
| 66 |
+
Licensed Material available under these terms and conditions.
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
Section 1 -- Definitions.
|
| 70 |
+
|
| 71 |
+
a. Adapted Material means material subject to Copyright and Similar
|
| 72 |
+
Rights that is derived from or based upon the Licensed Material
|
| 73 |
+
and in which the Licensed Material is translated, altered,
|
| 74 |
+
arranged, transformed, or otherwise modified in a manner requiring
|
| 75 |
+
permission under the Copyright and Similar Rights held by the
|
| 76 |
+
Licensor. For purposes of this Public License, where the Licensed
|
| 77 |
+
Material is a musical work, performance, or sound recording,
|
| 78 |
+
Adapted Material is always produced where the Licensed Material is
|
| 79 |
+
synched in timed relation with a moving image.
|
| 80 |
+
|
| 81 |
+
b. Adapter's License means the license You apply to Your Copyright
|
| 82 |
+
and Similar Rights in Your contributions to Adapted Material in
|
| 83 |
+
accordance with the terms and conditions of this Public License.
|
| 84 |
+
|
| 85 |
+
c. Copyright and Similar Rights means copyright and/or similar rights
|
| 86 |
+
closely related to copyright including, without limitation,
|
| 87 |
+
performance, broadcast, sound recording, and Sui Generis Database
|
| 88 |
+
Rights, without regard to how the rights are labeled or
|
| 89 |
+
categorized. For purposes of this Public License, the rights
|
| 90 |
+
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
| 91 |
+
Rights.
|
| 92 |
+
|
| 93 |
+
d. Effective Technological Measures means those measures that, in the
|
| 94 |
+
absence of proper authority, may not be circumvented under laws
|
| 95 |
+
fulfilling obligations under Article 11 of the WIPO Copyright
|
| 96 |
+
Treaty adopted on December 20, 1996, and/or similar international
|
| 97 |
+
agreements.
|
| 98 |
+
|
| 99 |
+
e. Exceptions and Limitations means fair use, fair dealing, and/or
|
| 100 |
+
any other exception or limitation to Copyright and Similar Rights
|
| 101 |
+
that applies to Your use of the Licensed Material.
|
| 102 |
+
|
| 103 |
+
f. Licensed Material means the artistic or literary work, database,
|
| 104 |
+
or other material to which the Licensor applied this Public
|
| 105 |
+
License.
|
| 106 |
+
|
| 107 |
+
g. Licensed Rights means the rights granted to You subject to the
|
| 108 |
+
terms and conditions of this Public License, which are limited to
|
| 109 |
+
all Copyright and Similar Rights that apply to Your use of the
|
| 110 |
+
Licensed Material and that the Licensor has authority to license.
|
| 111 |
+
|
| 112 |
+
h. Licensor means the individual(s) or entity(ies) granting rights
|
| 113 |
+
under this Public License.
|
| 114 |
+
|
| 115 |
+
i. Share means to provide material to the public by any means or
|
| 116 |
+
process that requires permission under the Licensed Rights, such
|
| 117 |
+
as reproduction, public display, public performance, distribution,
|
| 118 |
+
dissemination, communication, or importation, and to make material
|
| 119 |
+
available to the public including in ways that members of the
|
| 120 |
+
public may access the material from a place and at a time
|
| 121 |
+
individually chosen by them.
|
| 122 |
+
|
| 123 |
+
j. Sui Generis Database Rights means rights other than copyright
|
| 124 |
+
resulting from Directive 96/9/EC of the European Parliament and of
|
| 125 |
+
the Council of 11 March 1996 on the legal protection of databases,
|
| 126 |
+
as amended and/or succeeded, as well as other essentially
|
| 127 |
+
equivalent rights anywhere in the world.
|
| 128 |
+
|
| 129 |
+
k. You means the individual or entity exercising the Licensed Rights
|
| 130 |
+
under this Public License. Your has a corresponding meaning.
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
Section 2 -- Scope.
|
| 134 |
+
|
| 135 |
+
a. License grant.
|
| 136 |
+
|
| 137 |
+
1. Subject to the terms and conditions of this Public License,
|
| 138 |
+
the Licensor hereby grants You a worldwide, royalty-free,
|
| 139 |
+
non-sublicensable, non-exclusive, irrevocable license to
|
| 140 |
+
exercise the Licensed Rights in the Licensed Material to:
|
| 141 |
+
|
| 142 |
+
a. reproduce and Share the Licensed Material, in whole or
|
| 143 |
+
in part; and
|
| 144 |
+
|
| 145 |
+
b. produce, reproduce, and Share Adapted Material.
|
| 146 |
+
|
| 147 |
+
2. Exceptions and Limitations. For the avoidance of doubt, where
|
| 148 |
+
Exceptions and Limitations apply to Your use, this Public
|
| 149 |
+
License does not apply, and You do not need to comply with
|
| 150 |
+
its terms and conditions.
|
| 151 |
+
|
| 152 |
+
3. Term. The term of this Public License is specified in Section
|
| 153 |
+
6(a).
|
| 154 |
+
|
| 155 |
+
4. Media and formats; technical modifications allowed. The
|
| 156 |
+
Licensor authorizes You to exercise the Licensed Rights in
|
| 157 |
+
all media and formats whether now known or hereafter created,
|
| 158 |
+
and to make technical modifications necessary to do so. The
|
| 159 |
+
Licensor waives and/or agrees not to assert any right or
|
| 160 |
+
authority to forbid You from making technical modifications
|
| 161 |
+
necessary to exercise the Licensed Rights, including
|
| 162 |
+
technical modifications necessary to circumvent Effective
|
| 163 |
+
Technological Measures. For purposes of this Public License,
|
| 164 |
+
simply making modifications authorized by this Section 2(a)
|
| 165 |
+
(4) never produces Adapted Material.
|
| 166 |
+
|
| 167 |
+
5. Downstream recipients.
|
| 168 |
+
|
| 169 |
+
a. Offer from the Licensor -- Licensed Material. Every
|
| 170 |
+
recipient of the Licensed Material automatically
|
| 171 |
+
receives an offer from the Licensor to exercise the
|
| 172 |
+
Licensed Rights under the terms and conditions of this
|
| 173 |
+
Public License.
|
| 174 |
+
|
| 175 |
+
b. No downstream restrictions. You may not offer or impose
|
| 176 |
+
any additional or different terms or conditions on, or
|
| 177 |
+
apply any Effective Technological Measures to, the
|
| 178 |
+
Licensed Material if doing so restricts exercise of the
|
| 179 |
+
Licensed Rights by any recipient of the Licensed
|
| 180 |
+
Material.
|
| 181 |
+
|
| 182 |
+
6. No endorsement. Nothing in this Public License constitutes or
|
| 183 |
+
may be construed as permission to assert or imply that You
|
| 184 |
+
are, or that Your use of the Licensed Material is, connected
|
| 185 |
+
with, or sponsored, endorsed, or granted official status by,
|
| 186 |
+
the Licensor or others designated to receive attribution as
|
| 187 |
+
provided in Section 3(a)(1)(A)(i).
|
| 188 |
+
|
| 189 |
+
b. Other rights.
|
| 190 |
+
|
| 191 |
+
1. Moral rights, such as the right of integrity, are not
|
| 192 |
+
licensed under this Public License, nor are publicity,
|
| 193 |
+
privacy, and/or other similar personality rights; however, to
|
| 194 |
+
the extent possible, the Licensor waives and/or agrees not to
|
| 195 |
+
assert any such rights held by the Licensor to the limited
|
| 196 |
+
extent necessary to allow You to exercise the Licensed
|
| 197 |
+
Rights, but not otherwise.
|
| 198 |
+
|
| 199 |
+
2. Patent and trademark rights are not licensed under this
|
| 200 |
+
Public License.
|
| 201 |
+
|
| 202 |
+
3. To the extent possible, the Licensor waives any right to
|
| 203 |
+
collect royalties from You for the exercise of the Licensed
|
| 204 |
+
Rights, whether directly or through a collecting society
|
| 205 |
+
under any voluntary or waivable statutory or compulsory
|
| 206 |
+
licensing scheme. In all other cases the Licensor expressly
|
| 207 |
+
reserves any right to collect such royalties.
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
Section 3 -- License Conditions.
|
| 211 |
+
|
| 212 |
+
Your exercise of the Licensed Rights is expressly made subject to the
|
| 213 |
+
following conditions.
|
| 214 |
+
|
| 215 |
+
a. Attribution.
|
| 216 |
+
|
| 217 |
+
1. If You Share the Licensed Material (including in modified
|
| 218 |
+
form), You must:
|
| 219 |
+
|
| 220 |
+
a. retain the following if it is supplied by the Licensor
|
| 221 |
+
with the Licensed Material:
|
| 222 |
+
|
| 223 |
+
i. identification of the creator(s) of the Licensed
|
| 224 |
+
Material and any others designated to receive
|
| 225 |
+
attribution, in any reasonable manner requested by
|
| 226 |
+
the Licensor (including by pseudonym if
|
| 227 |
+
designated);
|
| 228 |
+
|
| 229 |
+
ii. a copyright notice;
|
| 230 |
+
|
| 231 |
+
iii. a notice that refers to this Public License;
|
| 232 |
+
|
| 233 |
+
iv. a notice that refers to the disclaimer of
|
| 234 |
+
warranties;
|
| 235 |
+
|
| 236 |
+
v. a URI or hyperlink to the Licensed Material to the
|
| 237 |
+
extent reasonably practicable;
|
| 238 |
+
|
| 239 |
+
b. indicate if You modified the Licensed Material and
|
| 240 |
+
retain an indication of any previous modifications; and
|
| 241 |
+
|
| 242 |
+
c. indicate the Licensed Material is licensed under this
|
| 243 |
+
Public License, and include the text of, or the URI or
|
| 244 |
+
hyperlink to, this Public License.
|
| 245 |
+
|
| 246 |
+
2. You may satisfy the conditions in Section 3(a)(1) in any
|
| 247 |
+
reasonable manner based on the medium, means, and context in
|
| 248 |
+
which You Share the Licensed Material. For example, it may be
|
| 249 |
+
reasonable to satisfy the conditions by providing a URI or
|
| 250 |
+
hyperlink to a resource that includes the required
|
| 251 |
+
information.
|
| 252 |
+
|
| 253 |
+
3. If requested by the Licensor, You must remove any of the
|
| 254 |
+
information required by Section 3(a)(1)(A) to the extent
|
| 255 |
+
reasonably practicable.
|
| 256 |
+
|
| 257 |
+
4. If You Share Adapted Material You produce, the Adapter's
|
| 258 |
+
License You apply must not prevent recipients of the Adapted
|
| 259 |
+
Material from complying with this Public License.
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
Section 4 -- Sui Generis Database Rights.
|
| 263 |
+
|
| 264 |
+
Where the Licensed Rights include Sui Generis Database Rights that
|
| 265 |
+
apply to Your use of the Licensed Material:
|
| 266 |
+
|
| 267 |
+
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
| 268 |
+
to extract, reuse, reproduce, and Share all or a substantial
|
| 269 |
+
portion of the contents of the database;
|
| 270 |
+
|
| 271 |
+
b. if You include all or a substantial portion of the database
|
| 272 |
+
contents in a database in which You have Sui Generis Database
|
| 273 |
+
Rights, then the database in which You have Sui Generis Database
|
| 274 |
+
Rights (but not its individual contents) is Adapted Material; and
|
| 275 |
+
|
| 276 |
+
c. You must comply with the conditions in Section 3(a) if You Share
|
| 277 |
+
all or a substantial portion of the contents of the database.
|
| 278 |
+
|
| 279 |
+
For the avoidance of doubt, this Section 4 supplements and does not
|
| 280 |
+
replace Your obligations under this Public License where the Licensed
|
| 281 |
+
Rights include other Copyright and Similar Rights.
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
| 285 |
+
|
| 286 |
+
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
| 287 |
+
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
| 288 |
+
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
| 289 |
+
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
| 290 |
+
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
| 291 |
+
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
| 292 |
+
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
| 293 |
+
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
| 294 |
+
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
| 295 |
+
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
| 296 |
+
|
| 297 |
+
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
| 298 |
+
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
| 299 |
+
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
| 300 |
+
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
| 301 |
+
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
| 302 |
+
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
| 303 |
+
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
| 304 |
+
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
| 305 |
+
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
| 306 |
+
|
| 307 |
+
c. The disclaimer of warranties and limitation of liability provided
|
| 308 |
+
above shall be interpreted in a manner that, to the extent
|
| 309 |
+
possible, most closely approximates an absolute disclaimer and
|
| 310 |
+
waiver of all liability.
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
Section 6 -- Term and Termination.
|
| 314 |
+
|
| 315 |
+
a. This Public License applies for the term of the Copyright and
|
| 316 |
+
Similar Rights licensed here. However, if You fail to comply with
|
| 317 |
+
this Public License, then Your rights under this Public License
|
| 318 |
+
terminate automatically.
|
| 319 |
+
|
| 320 |
+
b. Where Your right to use the Licensed Material has terminated under
|
| 321 |
+
Section 6(a), it reinstates:
|
| 322 |
+
|
| 323 |
+
1. automatically as of the date the violation is cured, provided
|
| 324 |
+
it is cured within 30 days of Your discovery of the
|
| 325 |
+
violation; or
|
| 326 |
+
|
| 327 |
+
2. upon express reinstatement by the Licensor.
|
| 328 |
+
|
| 329 |
+
For the avoidance of doubt, this Section 6(b) does not affect any
|
| 330 |
+
right the Licensor may have to seek remedies for Your violations
|
| 331 |
+
of this Public License.
|
| 332 |
+
|
| 333 |
+
c. For the avoidance of doubt, the Licensor may also offer the
|
| 334 |
+
Licensed Material under separate terms or conditions or stop
|
| 335 |
+
distributing the Licensed Material at any time; however, doing so
|
| 336 |
+
will not terminate this Public License.
|
| 337 |
+
|
| 338 |
+
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
| 339 |
+
License.
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
Section 7 -- Other Terms and Conditions.
|
| 343 |
+
|
| 344 |
+
a. The Licensor shall not be bound by any additional or different
|
| 345 |
+
terms or conditions communicated by You unless expressly agreed.
|
| 346 |
+
|
| 347 |
+
b. Any arrangements, understandings, or agreements regarding the
|
| 348 |
+
Licensed Material not stated herein are separate from and
|
| 349 |
+
independent of the terms and conditions of this Public License.
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
Section 8 -- Interpretation.
|
| 353 |
+
|
| 354 |
+
a. For the avoidance of doubt, this Public License does not, and
|
| 355 |
+
shall not be interpreted to, reduce, limit, restrict, or impose
|
| 356 |
+
conditions on any use of the Licensed Material that could lawfully
|
| 357 |
+
be made without permission under this Public License.
|
| 358 |
+
|
| 359 |
+
b. To the extent possible, if any provision of this Public License is
|
| 360 |
+
deemed unenforceable, it shall be automatically reformed to the
|
| 361 |
+
minimum extent necessary to make it enforceable. If the provision
|
| 362 |
+
cannot be reformed, it shall be severed from this Public License
|
| 363 |
+
without affecting the enforceability of the remaining terms and
|
| 364 |
+
conditions.
|
| 365 |
+
|
| 366 |
+
c. No term or condition of this Public License will be waived and no
|
| 367 |
+
failure to comply consented to unless expressly agreed to by the
|
| 368 |
+
Licensor.
|
| 369 |
+
|
| 370 |
+
d. Nothing in this Public License constitutes or may be interpreted
|
| 371 |
+
as a limitation upon, or waiver of, any privileges and immunities
|
| 372 |
+
that apply to the Licensor or You, including from the legal
|
| 373 |
+
processes of any jurisdiction or authority.
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
=======================================================================
|
| 377 |
+
|
| 378 |
+
Creative Commons is not a party to its public
|
| 379 |
+
licenses. Notwithstanding, Creative Commons may elect to apply one of
|
| 380 |
+
its public licenses to material it publishes and in those instances
|
| 381 |
+
will be considered the “Licensor.” The text of the Creative Commons
|
| 382 |
+
public licenses is dedicated to the public domain under the CC0 Public
|
| 383 |
+
Domain Dedication. Except for the limited purpose of indicating that
|
| 384 |
+
material is shared under a Creative Commons public license or as
|
| 385 |
+
otherwise permitted by the Creative Commons policies published at
|
| 386 |
+
creativecommons.org/policies, Creative Commons does not authorize the
|
| 387 |
+
use of the trademark "Creative Commons" or any other trademark or logo
|
| 388 |
+
of Creative Commons without its prior written consent including,
|
| 389 |
+
without limitation, in connection with any unauthorized modifications
|
| 390 |
+
to any of its public licenses or any other arrangements,
|
| 391 |
+
understandings, or agreements concerning use of licensed material. For
|
| 392 |
+
the avoidance of doubt, this paragraph does not form part of the
|
| 393 |
+
public licenses.
|
| 394 |
+
|
| 395 |
+
Creative Commons may be contacted at creativecommons.org.
|
101/replication_package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Code accompanying the paper *Societies of strangers do not speak grammatically simpler languages* by Olena Shcherbakova, Susanne Maria Michaelis, Hannah J. Haynie, Sam Passmore, Volker Gast, Russell D. Gray, Simon J. Greenhill, Damián E. Blasi, and Hedvig Skirgård
|
| 2 |
+
|
| 3 |
+
# Overview of structure
|
| 4 |
+
This project contains all data and all scripts for data-wrangling, analysis and plotting.
|
| 5 |
+
|
| 6 |
+
## Data sources
|
| 7 |
+
|
| 8 |
+
The data that serves as the input for the analysis comes from Grambank,
|
| 9 |
+
(v1.0, Skirgård et al (in prep)), AUTOTYP (v1.01, Bickel et al (2022)), Glottolog (v4.5), EDGE-tree (v1.0.0, Bouckaert et al (2023)), Ethnologue (Eberhard et al 2020)), and WALS (Dryer & Haspelmath 2013).
|
| 10 |
+
|
| 11 |
+
With the exception of the Ethnologue data, all the data is available
|
| 12 |
+
openly via the science archive Zenodo and/or public GitHub repositories. A
|
| 13 |
+
modified version of the Ethnologue data is available in this repository, it contains
|
| 14 |
+
transformed population numbers that cannot be transformed back into the
|
| 15 |
+
raw numbers. The MCCT EDGE-tree is found in a file inside grambank-analysed.
|
| 16 |
+
|
| 17 |
+
Zenodo locations:
|
| 18 |
+
|
| 19 |
+
* Grambank (v.1.0) <https://doi.org/10.5281/zenodo.7740140>
|
| 20 |
+
* Grambank-analysed (v1.0) <https://doi.org/10.5281/zenodo.7740822>
|
| 21 |
+
* Glottolog-cldf (v4.5) <https://doi.org/10.5281/zenodo.5772649>
|
| 22 |
+
* AUTOTYP (v1.0.1) <https://doi.org/10.5281/zenodo.6255206>
|
| 23 |
+
|
| 24 |
+
GitHub locations:
|
| 25 |
+
|
| 26 |
+
* EDGE-tree (v1.0.0) <https://github.com/rbouckaert/global-language-tree-pipeline/tree/v1.0.0>
|
| 27 |
+
* Grambank (v1.0) <https://github.com/grambank/grambank/tree/v1.0>
|
| 28 |
+
* Grambank-analysed (v1.0) <https://github.com/grambank/grambank-analysed/tree/v1.0>
|
| 29 |
+
* Glottolog-cldf (v4.5) <https://github.com/glottolog/glottolog-cldf/tree/v4.5>
|
| 30 |
+
* AUTOTYP (v1.01) <https://github.com/autotyp/autotyp-data/tree/v1.0.1>
|
| 31 |
+
|
| 32 |
+
In this project, we fetch the data from the Zenodo locations by downloading a zip file and expanding it. We have also made tables and files available derived from these sources in this repos so that users may run the analysis without engaging with fetching from Zenodo. The scripts that generate these files are also found in this repository and can be run by users if they would like.
|
| 33 |
+
|
| 34 |
+
## Running data-wrangling, analysis and plotting scripts
|
| 35 |
+
All scripts are written in R. The necessary scripts can be called
|
| 36 |
+
one-by-one in order or executed by running the script `all_scripts.R`.
|
| 37 |
+
|
| 38 |
+
Running `all_scripts.R` involves the following:
|
| 39 |
+
|
| 40 |
+
- downloading, installing and loading necessary packages and create
|
| 41 |
+
folders for output (see `requirements.R` & `install_and_load_INLA.R`
|
| 42 |
+
for specific packages)
|
| 43 |
+
- generating a table of languoids from Glottolog v.4.5
|
| 44 |
+
- calculating metric scores from Grambank v.1.0: fusion metric and
|
| 45 |
+
informativity metric; both metrics designed by Hedvig Skirgård and
|
| 46 |
+
Hannah J. Haynie.
|
| 47 |
+
- generating population table (all sociodemographic variables in one
|
| 48 |
+
dataframe): data from Ethnologue e24 (Eberhard et al. 2020) and
|
| 49 |
+
Supplementary Materials in `data\lang_endangerment_predictors.xlsx`
|
| 50 |
+
from Bromham et al. (2022). Based on data availability, within
|
| 51 |
+
`set_up_inla.R`, it is necessary to specify whether `sample` is
|
| 52 |
+
`"full"` (full access to both Ethnologue variables in transformed
|
| 53 |
+
and non-transformed form and running all models; possible only for
|
| 54 |
+
users with their own access to Ethnologue) and `"reduced"` (access
|
| 55 |
+
to both Ethnologue variables - the number of L1 speakers and the
|
| 56 |
+
proportion of L2 speakers - in transformed form (logged and
|
| 57 |
+
standardized number of L1 speakers and the proportion of L2 speakers
|
| 58 |
+
than than raw numbers) and running all models except for one
|
| 59 |
+
including the interaction between the number of L1 speakers and L2
|
| 60 |
+
proportion; the dataset is already provided within the repository).
|
| 61 |
+
- wrangling global phylogeny - EDGE-tree (v1.0.0, Bouckaert et al 2023)
|
| 62 |
+
- generating AUTOTYP-areas table (v.1.0.1, Bickel et al. 2020)
|
| 63 |
+
- prepare everything for and run INLA analysis, including sensitivity
|
| 64 |
+
analyses
|
| 65 |
+
- measuring phylogenetic signal in fusion and informativity
|
| 66 |
+
- generating tables from INLA analyses, including sensitivity analyses
|
| 67 |
+
- make plots
|
| 68 |
+
- running additional analyses on WALS-based morphological complexity scores used in Lupyan & Dale's (2010) study (`data/complexity_data_WALS.csv`) (obtained from Gary Lupyan, personal communication 02.06.2023)
|
| 69 |
+
|
| 70 |
+
Please note: the necessary files, such as metrics scores obtained from the
|
| 71 |
+
Grambank dataset and parameters of metrics (these determine the
|
| 72 |
+
inclusion of Grambank into the metrics), are already made available. The
|
| 73 |
+
script that generates these `generating_GB_input_file.R` relies on the
|
| 74 |
+
folder `grambank_analysed` which incorporates data from
|
| 75 |
+
Grambank v.1.0, AUTOTYP (v1.0.1) and Glottolog v.4.5. To run this script, one needs to
|
| 76 |
+
first clone the repository and then run the R-script `get_external_data.R`.
|
| 77 |
+
|
| 78 |
+
# References
|
| 79 |
+
|
| 80 |
+
R. Bouckaert, D. Redding, O. Sheehan, T. Kyritsis, R. Gray, K. E. Jones, Q. Atkinson, Global language diversification is linked to socio-ecology and threat status (2022), , doi:10.31235/osf.io/f8tr6.
|
| 81 |
+
|
| 82 |
+
Bickel, Balthasar, Johanna Nichols, Taras Zakharko, Alena
|
| 83 |
+
Witzlack-Makarevich, Kristine Hildebrandt, Michael Rießler, Lennart
|
| 84 |
+
Bierkandt, Fernando Zúñiga & John B Lowe. 2022. The AUTOTYP database
|
| 85 |
+
(v1.1.0). <https://doi.org/10.5281/zenodo.6793367>.
|
| 86 |
+
|
| 87 |
+
Bromham, Lindell, Russell Dinnage, Hedvig Skirgård, Andrew Ritchie,
|
| 88 |
+
Marcel Cardillo, Felicity Meakins, Simon Greenhill & Xia Hua. 2022.
|
| 89 |
+
Global predictors of language endangerment and the future of linguistic
|
| 90 |
+
diversity. Nature ecology & evolution 6(2). 163--173.
|
| 91 |
+
|
| 92 |
+
Dryer, Matthew & Martin Haspelmath (eds.). 2013. The World Atlas of Language Structures Online. Leipzig: Max Planck Institute for Evolutionary Anthropology. http://wals.info.
|
| 93 |
+
|
| 94 |
+
Eberhard, David M., Gary F. Simons & Charles D. Fennig (eds.). 2020.
|
| 95 |
+
Ethnologue: Languages of the World. Dallas, Texas: SIL International.
|
| 96 |
+
www.ethnologue.com.
|
| 97 |
+
|
| 98 |
+
Hammarström, Harald & Forkel, Robert & Haspelmath, Martin & Bank, Sebastian. 2021. Glottolog 4.5. Leipzig: Max Planck Institute for Evolutionary Anthropology. (Available online at https://glottolog.org)
|
| 99 |
+
|
| 100 |
+
Skirgård, H., Haynie, H. J., Blasi, D. E., Hammarström, H., Collins, J., Latarche, J., Lesage, J., Weber, T., Witzlack-Makarevich, A., Passmore, S., Chira, A., Dinnage, R., Maurits, L., Dinnage, R., Dunn, M., Reesink, G., Singer, R., Bowern, C., Epps, P., Hill, J., Vesakoski, O., Robbeets, M., Abbas, K., Auer, D., Bakker, N., Barbos, G., Borges, R., Danielsen, S., Dorenbusch, L., Dorn, E., Elliott, J., Falcone, G., Fischer, J., Ghanggo Ate, Y., Gibson, H., Göbel, H., Goodall, J., Gruner, V., Harvey, A., Hayes, R., Heer, L., Herrera Miranda, R., Hübler, N., Huntington-Rainey, B., Ivani, J., Johns, M., Just, E., Kashima, E., Kipf, C., Klingenberg, J., König, N., Koti, K., Kowalik, R., Krasnoukhova, O., Lindvall, N., Lorenzen, M., Lutzenberger, H., Martins, T., Mata German, C., Meer, S., Montoya Samamé, J., Müller, M., Muradoglu, S., Neely, K., Nickel, J., Norvik, M., Oluoch, C. A., Peacock, J., Pearey , I., Peck, N., Petit, S., Pieper, S., Poblete, M., Prestipino, D., Raabe, L., Raja, A., Reimringer, J., Rey, S., Rizaew, J., Ruppert, E., Salmon, K., Sammet, J., Schembri, R., Schlabbach, L., Schmidt, F., Skilton, A., Smith, W. D., Sousa, H., Sverredal, K., Valle, D., Vera, J., Voß, J., Witte, T., Wu, H., Yam, S., Ye 葉婧婷, J., Yong, M., Yuditha, T., Zariquiey, R., Forkel, R., Evans, N., Levinson, S. C., Haspelmath, M., Greenhill, S. J., Atkinson, Q. D. and Gray, R. D. (in prep) "Grambank reveals the importance of genealogical constraints on linguistic diversity and highlights the impact of language loss". Science Advances
|
| 101 |
+
|
| 102 |
+
Hedvig Skirgård; Hannah J. Haynie; Harald Hammarström; Damián E. Blasi; Jeremy Collins; Jay Latarche; Jakob Lesage; Tobias Weber; Alena Witzlack-Makarevich; Michael Dunn; Ger Reesink; Ruth Singer; Claire Bowern; Patience Epps; Jane Hill; Outi Vesakoski; Noor Karolin Abbas; Sunny Ananth; Daniel Auer; Nancy A. Bakker; Giulia Barbos; Anina Bolls; Robert D. Borges; Mitchell Browen; Lennart Chevallier; Swintha Danielsen; Sinoël Dohlen; Luise Dorenbusch; Ella Dorn; Marie Duhamel; Farah El Haj Ali; John Elliott; Giada Falcone; Anna-Maria Fehn; Jana Fischer; Yustinus Ghanggo Ate; Hannah Gibson; Hans-Philipp Göbel; Jemima A. Goodall; Victoria Gruner; Andrew Harvey; Rebekah Hayes; Leonard Heer; Roberto E. Herrera Miranda; Nataliia Hübler; Biu H. Huntington-Rainey; Guglielmo Inglese; Jessica K. Ivani; Marilen Johns; Erika Just; Ivan Kapitonov; Eri Kashima; Carolina Kipf; Janina V. Klingenberg; Nikita König; Aikaterina Koti; Richard G. A. Kowalik; Olga Krasnoukhova; Kate Lynn Lindsey; Nora L. M. Lindvall; Mandy Lorenzen; Hannah Lutzenberger; Alexandra Marley; Tânia R. A. Martins; Celia Mata German; Suzanne van der Meer; Jaime Montoya; Michael Müller; Saliha Muradoglu; HunterGatherer; David Nash; Kelsey Neely; Johanna Nickel; Miina Norvik; Bruno Olsson; Cheryl Akinyi Oluoch; David Osgarby; Jesse Peacock; India O.C. Pearey; Naomi Peck; Jana Peter; Stephanie Petit; Sören Pieper; Mariana Poblete; Daniel Prestipino; Linda Raabe; Amna Raja; Janis Reimringer; Sydney C. Rey; Julia Rizaew; Eloisa Ruppert; Kim K. Salmon; Jill Sammet; Rhiannon Schembri; Lars Schlabbach; Frederick W. P. Schmidt; Dineke Schokkin; Jeff Siegel; Amalia Skilton; Hilário de Sousa; Kristin Sverredal; Daniel Valle; Javier Vera; Judith Voß; Daniel Wikalier Smith; Tim Witte; Henry Wu; Stephanie Yam; Jingting Ye 葉婧婷; Maisie Yong; Tessa Yuditha; Roberto Zariquiey; Robert Forkel; Nicholas Evans; Stephen C. Levinson; Martin Haspelmath; Simon J. Greenhill; Quentin D. Atkinson; Russell D. Gray (2023) Grambank v1.0 https://doi.org/10.5281/zenodo.7740140
|
| 103 |
+
|
| 104 |
+
The Grambank Consortium (eds.). 2022. Grambank 1.0. Leipzig: Max Planck
|
| 105 |
+
Institute for Evolutionary Anthropology. <http://grambank.clld.org>.
|
101/replication_package/WALS_reanalysis_controlled_setup.R
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
source("install_and_load_INLA.R")
|
| 2 |
+
|
| 3 |
+
#parameters
|
| 4 |
+
kappa = 1
|
| 5 |
+
phi_1 = c(1, 1.25) # "Local" version: (sigma, phi) First value is not used
|
| 6 |
+
|
| 7 |
+
WALS <- read_csv("data/complexity_data_WALS.csv") %>%
|
| 8 |
+
dplyr::select("Name" = lang, roundComp, logpop2, "ISO_639" = silCode) %>%
|
| 9 |
+
dplyr::mutate(ISO_639 = str_to_lower(ISO_639))
|
| 10 |
+
|
| 11 |
+
min_val <- min(WALS$roundComp)
|
| 12 |
+
max_val <- max(WALS$roundComp)
|
| 13 |
+
|
| 14 |
+
# Perform the rescaling
|
| 15 |
+
WALS$roundComp <- (WALS$roundComp - min_val) / (max_val - min_val)
|
| 16 |
+
|
| 17 |
+
pop_file_fn <-
|
| 18 |
+
"data_wrangling/ethnologue_pop_SM_morph_compl_reanalysis.tsv"
|
| 19 |
+
L1 <-
|
| 20 |
+
read_tsv(pop_file_fn, show_col_types = F) %>% dplyr::select(ISO_639, L1_log10_scaled)
|
| 21 |
+
|
| 22 |
+
glottolog_df <-
|
| 23 |
+
read_tsv("data_wrangling/glottolog_cldf_wide_df.tsv", col_types = cols()) %>%
|
| 24 |
+
dplyr::select(
|
| 25 |
+
Glottocode,
|
| 26 |
+
Language_ID,
|
| 27 |
+
"ISO_639" = ISO639P3code,
|
| 28 |
+
Language_level_ID,
|
| 29 |
+
level,
|
| 30 |
+
Family_ID,
|
| 31 |
+
Longitude,
|
| 32 |
+
Latitude
|
| 33 |
+
) %>%
|
| 34 |
+
mutate(Language_level_ID = if_else(is.na(Language_level_ID), Glottocode, Language_level_ID)) %>%
|
| 35 |
+
mutate(Family_ID = ifelse(is.na(Family_ID), Language_level_ID, Family_ID)) %>%
|
| 36 |
+
dplyr::select(
|
| 37 |
+
Glottocode,
|
| 38 |
+
Language_ID,
|
| 39 |
+
ISO_639,
|
| 40 |
+
Language_level_ID,
|
| 41 |
+
level,
|
| 42 |
+
Family_ID,
|
| 43 |
+
Longitude,
|
| 44 |
+
Latitude
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
WALS_df <- WALS %>%
|
| 48 |
+
inner_join(L1,
|
| 49 |
+
by = c("ISO_639")) %>%
|
| 50 |
+
inner_join(glottolog_df, by = "ISO_639") %>%
|
| 51 |
+
filter(!is.na(Latitude), !is.na(Longitude)) %>%
|
| 52 |
+
dplyr::select(Language_ID = Glottocode,
|
| 53 |
+
Name,
|
| 54 |
+
roundComp,
|
| 55 |
+
ISO_639,
|
| 56 |
+
L1_log10_scaled,
|
| 57 |
+
Longitude,
|
| 58 |
+
Latitude)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
tree <- read.tree(file.path("data_wrangling/wrangled.tree"))
|
| 63 |
+
|
| 64 |
+
#dropping tips not in Grambank
|
| 65 |
+
WALS_df <- WALS_df[WALS_df$Language_ID %in% tree$tip.label,]
|
| 66 |
+
tree <- keep.tip(tree, WALS_df$Language_ID)
|
| 67 |
+
|
| 68 |
+
x <-
|
| 69 |
+
assert_that(all(tree$tip.label %in% WALS_df$Language_ID), msg = "The data and phylogeny taxa do not match")
|
| 70 |
+
|
| 71 |
+
## Building standardized phylogenetic precision matrix
|
| 72 |
+
tree_scaled <- tree
|
| 73 |
+
|
| 74 |
+
tree_vcv = vcv.phylo(tree_scaled)
|
| 75 |
+
typical_phylogenetic_variance = exp(mean(log(diag(tree_vcv))))
|
| 76 |
+
|
| 77 |
+
#We opt for a sparse phylogenetic precision matrix (i.e. it is quantified using all nodes and tips), since sparse matrices make the analysis in INLA less time-intensive
|
| 78 |
+
tree_scaled$edge.length <-
|
| 79 |
+
tree_scaled$edge.length / typical_phylogenetic_variance
|
| 80 |
+
phylo_prec_mat <- MCMCglmm::inverseA(tree_scaled,
|
| 81 |
+
nodes = "ALL",
|
| 82 |
+
scale = FALSE)$Ainv
|
| 83 |
+
|
| 84 |
+
WALS_df = WALS_df[order(match(WALS_df$Language_ID, rownames(phylo_prec_mat))), ]
|
| 85 |
+
|
| 86 |
+
#"local" set of parameters
|
| 87 |
+
## Create spatial covariance matrix using the matern covariance function
|
| 88 |
+
spatial_covar_mat_1 = varcov.spatial(WALS_df[, c("Longitude", "Latitude")],
|
| 89 |
+
cov.pars = phi_1, kappa = kappa)$varcov
|
| 90 |
+
# Calculate and standardize by the typical variance
|
| 91 |
+
typical_variance_spatial_1 = exp(mean(log(diag(
|
| 92 |
+
spatial_covar_mat_1
|
| 93 |
+
))))
|
| 94 |
+
spatial_cov_std_1 = spatial_covar_mat_1 / typical_variance_spatial_1
|
| 95 |
+
spatial_prec_mat_1 = solve(spatial_cov_std_1)
|
| 96 |
+
dimnames(spatial_prec_mat_1) = list(WALS_df$Language_ID, WALS_df$Language_ID)
|
| 97 |
+
|
| 98 |
+
## Since we are using a sparse phylogenetic matrix, we are matching taxa to rows in the matrix
|
| 99 |
+
phy_id = match(tree$tip.label, rownames(phylo_prec_mat))
|
| 100 |
+
WALS_df$phy_id = phy_id
|
| 101 |
+
|
| 102 |
+
## Other effects are in the same order they appear in the dataset
|
| 103 |
+
WALS_df$sp_id = 1:nrow(spatial_prec_mat_1)
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
formula <- as.formula(
|
| 107 |
+
paste(
|
| 108 |
+
"roundComp ~",
|
| 109 |
+
"L1_log10_scaled +",
|
| 110 |
+
"f(phy_id, model = 'generic0', Cmatrix = phylo_prec_mat,
|
| 111 |
+
constr = TRUE, hyper = pcprior_hyper) +
|
| 112 |
+
f(sp_id, model = 'generic0', Cmatrix = spatial_prec_mat_1,
|
| 113 |
+
constr = TRUE, hyper = pcprior_hyper)"
|
| 114 |
+
)
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
result <- inla(
|
| 118 |
+
formula,
|
| 119 |
+
family = "gaussian",
|
| 120 |
+
data = WALS_df,
|
| 121 |
+
control.compute = list(waic = TRUE)
|
| 122 |
+
)
|
| 123 |
+
summary(result)
|
| 124 |
+
|
| 125 |
+
save(result, file = "output_models/model_WALS_controlled.RData")
|
| 126 |
+
|
| 127 |
+
social_effects_controlled <-
|
| 128 |
+
c("morphological complexity ~ L1 + phylogenetic effect + spatial effect",
|
| 129 |
+
round(
|
| 130 |
+
c(
|
| 131 |
+
result$summary.fixed[2,]$`0.025quant`,
|
| 132 |
+
result$summary.fixed[2,]$`0.5quant`,
|
| 133 |
+
result$summary.fixed[2,]$`0.975quant`,
|
| 134 |
+
nrow(WALS_df)
|
| 135 |
+
),
|
| 136 |
+
2
|
| 137 |
+
), "default (~10%)")
|
| 138 |
+
|
| 139 |
+
save(social_effects_controlled, file = "output_models/social_effects_controlled.RData")
|
| 140 |
+
|
101/replication_package/WALS_reanalysis_controlled_setup_high_coverage.R
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
source("install_and_load_INLA.R")
|
| 2 |
+
|
| 3 |
+
#parameters
|
| 4 |
+
kappa = 1
|
| 5 |
+
phi_1 = c(1, 1.25) # "Local" version: (sigma, phi) First value is not used
|
| 6 |
+
|
| 7 |
+
WALS <- read_csv("data/complexity_data_WALS.csv") %>%
|
| 8 |
+
dplyr::select("Name" = lang, roundComp, logpop2, "ISO_639" = silCode) %>%
|
| 9 |
+
dplyr::mutate(ISO_639 = str_to_lower(ISO_639)) %>%
|
| 10 |
+
inner_join(read_csv("output_tables/WALS_high_coverage.csv"),
|
| 11 |
+
by = c("ISO_639"))
|
| 12 |
+
|
| 13 |
+
min_val <- min(WALS$roundComp)
|
| 14 |
+
max_val <- max(WALS$roundComp)
|
| 15 |
+
|
| 16 |
+
# Perform the rescaling
|
| 17 |
+
WALS$roundComp <- (WALS$roundComp - min_val) / (max_val - min_val)
|
| 18 |
+
|
| 19 |
+
pop_file_fn <-
|
| 20 |
+
"data_wrangling/ethnologue_pop_SM_morph_compl_reanalysis.tsv"
|
| 21 |
+
L1 <-
|
| 22 |
+
read_tsv(pop_file_fn, show_col_types = F) %>% dplyr::select(ISO_639, L1_log10_scaled)
|
| 23 |
+
|
| 24 |
+
glottolog_df <-
|
| 25 |
+
read_tsv("data_wrangling/glottolog_cldf_wide_df.tsv", col_types = cols()) %>%
|
| 26 |
+
dplyr::select(
|
| 27 |
+
Glottocode,
|
| 28 |
+
Name,
|
| 29 |
+
Language_ID,
|
| 30 |
+
"ISO_639" = ISO639P3code,
|
| 31 |
+
Language_level_ID,
|
| 32 |
+
level,
|
| 33 |
+
Family_ID,
|
| 34 |
+
Longitude,
|
| 35 |
+
Latitude
|
| 36 |
+
) %>%
|
| 37 |
+
mutate(Language_level_ID = if_else(is.na(Language_level_ID), Glottocode, Language_level_ID)) %>%
|
| 38 |
+
mutate(Family_ID = ifelse(is.na(Family_ID), Language_level_ID, Family_ID)) %>%
|
| 39 |
+
dplyr::select(
|
| 40 |
+
Glottocode,
|
| 41 |
+
Name,
|
| 42 |
+
Language_ID,
|
| 43 |
+
ISO_639,
|
| 44 |
+
Language_level_ID,
|
| 45 |
+
level,
|
| 46 |
+
Family_ID,
|
| 47 |
+
Longitude,
|
| 48 |
+
Latitude
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
WALS_df <- WALS %>%
|
| 52 |
+
inner_join(L1,
|
| 53 |
+
by = c("ISO_639")) %>%
|
| 54 |
+
inner_join(glottolog_df, by = "ISO_639") %>%
|
| 55 |
+
filter(!is.na(Latitude),!is.na(Longitude)) %>%
|
| 56 |
+
dplyr::select(Language_ID = Glottocode,
|
| 57 |
+
Name,
|
| 58 |
+
roundComp,
|
| 59 |
+
ISO_639,
|
| 60 |
+
L1_log10_scaled,
|
| 61 |
+
Longitude,
|
| 62 |
+
Latitude)
|
| 63 |
+
|
| 64 |
+
# jitter points locations
|
| 65 |
+
WALS_df$Latitude <- jitter(WALS_df$Latitude, amount = 0.001)
|
| 66 |
+
WALS_df$Longitude <- jitter(WALS_df$Longitude, amount = 0.001)
|
| 67 |
+
|
| 68 |
+
tree <- read.tree(file.path("data_wrangling/wrangled.tree"))
|
| 69 |
+
|
| 70 |
+
#dropping tips not in Grambank
|
| 71 |
+
WALS_df <- WALS_df[WALS_df$Language_ID %in% tree$tip.label, ]
|
| 72 |
+
WALS_df <- WALS_df[!duplicated(WALS_df$Language_ID),]
|
| 73 |
+
tree <- keep.tip(tree, WALS_df$Language_ID)
|
| 74 |
+
|
| 75 |
+
x <-
|
| 76 |
+
assert_that(all(tree$tip.label %in% WALS_df$Language_ID), msg = "The data and phylogeny taxa do not match")
|
| 77 |
+
|
| 78 |
+
## Building standardized phylogenetic precision matrix
|
| 79 |
+
tree_scaled <- tree
|
| 80 |
+
|
| 81 |
+
tree_vcv = vcv.phylo(tree_scaled)
|
| 82 |
+
typical_phylogenetic_variance = exp(mean(log(diag(tree_vcv))))
|
| 83 |
+
|
| 84 |
+
#We opt for a sparse phylogenetic precision matrix (i.e. it is quantified using all nodes and tips), since sparse matrices make the analysis in INLA less time-intensive
|
| 85 |
+
tree_scaled$edge.length <-
|
| 86 |
+
tree_scaled$edge.length / typical_phylogenetic_variance
|
| 87 |
+
phylo_prec_mat <- MCMCglmm::inverseA(tree_scaled,
|
| 88 |
+
nodes = "ALL",
|
| 89 |
+
scale = FALSE)$Ainv
|
| 90 |
+
|
| 91 |
+
WALS_df = WALS_df[order(match(WALS_df$Language_ID, rownames(phylo_prec_mat))),]
|
| 92 |
+
|
| 93 |
+
#"local" set of parameters
|
| 94 |
+
## Create spatial covariance matrix using the matern covariance function
|
| 95 |
+
spatial_covar_mat_1 = varcov.spatial(WALS_df[, c("Longitude", "Latitude")],
|
| 96 |
+
cov.pars = phi_1, kappa = kappa)$varcov
|
| 97 |
+
# Calculate and standardize by the typical variance
|
| 98 |
+
typical_variance_spatial_1 = exp(mean(log(diag(
|
| 99 |
+
spatial_covar_mat_1
|
| 100 |
+
))))
|
| 101 |
+
spatial_cov_std_1 = spatial_covar_mat_1 / typical_variance_spatial_1
|
| 102 |
+
spatial_prec_mat_1 = solve(spatial_cov_std_1)
|
| 103 |
+
dimnames(spatial_prec_mat_1) = list(WALS_df$Language_ID, WALS_df$Language_ID)
|
| 104 |
+
|
| 105 |
+
## Since we are using a sparse phylogenetic matrix, we are matching taxa to rows in the matrix
|
| 106 |
+
phy_id <- match(tree$tip.label, rownames(phylo_prec_mat))
|
| 107 |
+
if (length(phy_id) != nrow(WALS_df)) {
|
| 108 |
+
stop("The number of phylogenetic IDs does not match the number of rows in WALS_df.")
|
| 109 |
+
}
|
| 110 |
+
|
| 111 |
+
WALS_df$phy_id <- phy_id
|
| 112 |
+
|
| 113 |
+
## Other effects are in the same order they appear in the dataset
|
| 114 |
+
WALS_df$sp_id = 1:nrow(spatial_prec_mat_1)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
formula <- as.formula(
|
| 118 |
+
paste(
|
| 119 |
+
"roundComp ~",
|
| 120 |
+
"L1_log10_scaled +",
|
| 121 |
+
"f(phy_id, model = 'generic0', Cmatrix = phylo_prec_mat,
|
| 122 |
+
constr = TRUE, hyper = pcprior_hyper) +
|
| 123 |
+
f(sp_id, model = 'generic0', Cmatrix = spatial_prec_mat_1,
|
| 124 |
+
constr = TRUE, hyper = pcprior_hyper)"
|
| 125 |
+
)
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
result <- inla(
|
| 129 |
+
formula,
|
| 130 |
+
family = "gaussian",
|
| 131 |
+
control.family = list(hyper = pcprior_hyper),
|
| 132 |
+
data = WALS_df,
|
| 133 |
+
control.compute = list(waic = TRUE)
|
| 134 |
+
)
|
| 135 |
+
summary(result)
|
| 136 |
+
|
| 137 |
+
save(result, file = "output_models/model_WALS_high_coverage.RData")
|
| 138 |
+
|
| 139 |
+
#mean estimate of L1_Users: with credible intervals not crossing zero ()
|
| 140 |
+
|
| 141 |
+
social_effects_controlled_coverage <-
|
| 142 |
+
c(
|
| 143 |
+
"morphological complexity ~ L1 + phylogenetic effect + spatial effect",
|
| 144 |
+
round(
|
| 145 |
+
c(
|
| 146 |
+
result$summary.fixed[2, ]$`0.025quant`,
|
| 147 |
+
result$summary.fixed[2, ]$`0.5quant`,
|
| 148 |
+
result$summary.fixed[2, ]$`0.975quant`,
|
| 149 |
+
nrow(WALS_df)
|
| 150 |
+
),
|
| 151 |
+
2
|
| 152 |
+
),
|
| 153 |
+
"35%"
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
save(social_effects_controlled_coverage, file = "output_models/social_effects_controlled.RData")
|
| 157 |
+
|
| 158 |
+
load("output_models/social_effects_uncontrolled.RData")
|
| 159 |
+
load("output_models/social_effects_controlled.RData")
|
| 160 |
+
load("output_models/social_effects_controlled_coverage.RData")
|
| 161 |
+
|
| 162 |
+
effects_morph_comp <-
|
| 163 |
+
as.data.frame(
|
| 164 |
+
rbind(
|
| 165 |
+
social_effects_uncontrolled,
|
| 166 |
+
social_effects_controlled,
|
| 167 |
+
social_effects_controlled_coverage
|
| 168 |
+
)
|
| 169 |
+
)
|
| 170 |
+
colnames(effects_morph_comp) <-
|
| 171 |
+
c("model",
|
| 172 |
+
"2.5%",
|
| 173 |
+
"50%",
|
| 174 |
+
"97.5%",
|
| 175 |
+
"sample size",
|
| 176 |
+
"feature coverage threshold")
|
| 177 |
+
|
| 178 |
+
rownames(effects_morph_comp) <- NULL
|
| 179 |
+
|
| 180 |
+
effects_morph_comp %>%
|
| 181 |
+
write_csv("output_tables/WALS_morph_compl_effects.csv")
|
101/replication_package/WALS_reanalysis_setup.R
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
source("install_and_load_INLA.R")
|
| 2 |
+
|
| 3 |
+
#parameters
|
| 4 |
+
kappa = 1
|
| 5 |
+
phi_1 = c(1, 1.25) # "Local" version: (sigma, phi) First value is not used
|
| 6 |
+
|
| 7 |
+
WALS <- read_csv("data/complexity_data_WALS.csv") %>%
|
| 8 |
+
dplyr::select("Name"=lang, roundComp, logpop2, "ISO_639"=silCode) %>%
|
| 9 |
+
dplyr::mutate(ISO_639 = str_to_lower(ISO_639))
|
| 10 |
+
|
| 11 |
+
min_val <- min(WALS$roundComp)
|
| 12 |
+
max_val <- max(WALS$roundComp)
|
| 13 |
+
|
| 14 |
+
# Perform the rescaling
|
| 15 |
+
WALS$roundComp <- (WALS$roundComp - min_val) / (max_val - min_val)
|
| 16 |
+
|
| 17 |
+
pop_file_fn <- "data_wrangling/ethnologue_pop_SM_morph_compl_reanalysis.tsv"
|
| 18 |
+
L1 <-
|
| 19 |
+
read_tsv(pop_file_fn, show_col_types = F) %>% dplyr::select(ISO_639, L1_log10_scaled)
|
| 20 |
+
|
| 21 |
+
WALS_df <- WALS %>%
|
| 22 |
+
inner_join(L1,
|
| 23 |
+
by = c("ISO_639"))
|
| 24 |
+
|
| 25 |
+
formula <- as.formula(paste("roundComp ~", "L1_log10_scaled"))
|
| 26 |
+
result <- inla(formula, family = "gaussian",
|
| 27 |
+
data = WALS_df, control.compute = list(waic = TRUE))
|
| 28 |
+
summary(result)
|
| 29 |
+
|
| 30 |
+
save(result, file = "output_models/models_WALS_uncontrolled.RData")
|
| 31 |
+
|
| 32 |
+
social_effects_uncontrolled <- c("morphological complexity ~ L1",
|
| 33 |
+
round(c(
|
| 34 |
+
result$summary.fixed[2,]$`0.025quant`,
|
| 35 |
+
result$summary.fixed[2,]$`0.5quant`,
|
| 36 |
+
result$summary.fixed[2,]$`0.975quant`, nrow(WALS_df)), 2), "default (~10%)")
|
| 37 |
+
|
| 38 |
+
save(social_effects_uncontrolled, file = "output_models/social_effects_uncontrolled.RData")
|
| 39 |
+
|
| 40 |
+
|
101/replication_package/WALS_sparseness.R
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
source("requirements.R")
|
| 2 |
+
|
| 3 |
+
library(INLA)
|
| 4 |
+
inla.setOption(inla.mode = "experimental")
|
| 5 |
+
|
| 6 |
+
wals <- read.delim(
|
| 7 |
+
"https://raw.githubusercontent.com/cldf-datasets/wals/master/cldf/languages.csv",
|
| 8 |
+
sep = ","
|
| 9 |
+
) %>%
|
| 10 |
+
dplyr::select(ID, ISO_639 = ISO_codes, Name, Glottocode) %>%
|
| 11 |
+
rename(Language_ID = ID) %>% #renaming the column to avoid problems
|
| 12 |
+
left_join(
|
| 13 |
+
read.delim(
|
| 14 |
+
"https://raw.githubusercontent.com/cldf-datasets/wals/master/cldf/values.csv",
|
| 15 |
+
sep = ","
|
| 16 |
+
) %>% dplyr::select(Language_ID, Parameter_ID, Value)
|
| 17 |
+
) %>%
|
| 18 |
+
dplyr::select(-Language_ID) %>%
|
| 19 |
+
rename(Language_ID = Glottocode)
|
| 20 |
+
|
| 21 |
+
wals_selected <- wals %>%
|
| 22 |
+
filter(
|
| 23 |
+
Parameter_ID == "20A" |
|
| 24 |
+
Parameter_ID == "26A" |
|
| 25 |
+
Parameter_ID == "49A" |
|
| 26 |
+
Parameter_ID == "28A" |
|
| 27 |
+
Parameter_ID == "98A" |
|
| 28 |
+
Parameter_ID == "22A" |
|
| 29 |
+
Parameter_ID == "100A" |
|
| 30 |
+
Parameter_ID == "102A" |
|
| 31 |
+
Parameter_ID == "48A" |
|
| 32 |
+
Parameter_ID == "29A" |
|
| 33 |
+
Parameter_ID == "74A" |
|
| 34 |
+
Parameter_ID == "75A" |
|
| 35 |
+
Parameter_ID == "76A" |
|
| 36 |
+
Parameter_ID == "77A" |
|
| 37 |
+
Parameter_ID == "112A" |
|
| 38 |
+
Parameter_ID == "34A" |
|
| 39 |
+
Parameter_ID == "36A" |
|
| 40 |
+
Parameter_ID == "92A" |
|
| 41 |
+
Parameter_ID == "66A" |
|
| 42 |
+
Parameter_ID == "67A" |
|
| 43 |
+
Parameter_ID == "65A" |
|
| 44 |
+
Parameter_ID == "70A" |
|
| 45 |
+
Parameter_ID == "57A" |
|
| 46 |
+
Parameter_ID == "59A" |
|
| 47 |
+
Parameter_ID == "73A" |
|
| 48 |
+
Parameter_ID == "38A" |
|
| 49 |
+
Parameter_ID == "39A" |
|
| 50 |
+
Parameter_ID == "41A" |
|
| 51 |
+
Parameter_ID == "101A"
|
| 52 |
+
) %>%
|
| 53 |
+
pivot_wider(
|
| 54 |
+
names_from = Parameter_ID,
|
| 55 |
+
values_from = Value
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
# Specify the range of columns
|
| 59 |
+
start_column <- "92A"
|
| 60 |
+
end_column <- "76A"
|
| 61 |
+
|
| 62 |
+
# Filter and gather the selected columns
|
| 63 |
+
wals_selected_na <- wals_selected %>%
|
| 64 |
+
rowwise() %>%
|
| 65 |
+
mutate(na_proportion = mean(is.na(c_across(starts_with(start_column):starts_with(end_column))))) %>%
|
| 66 |
+
filter(na_proportion <= 0.35)
|
| 67 |
+
|
| 68 |
+
wals_selected_na %>%
|
| 69 |
+
write_csv("output_tables/WALS_high_coverage.csv")
|
| 70 |
+
|
101/replication_package/all_scripts.R
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#Running all scripts
|
| 2 |
+
|
| 3 |
+
#download packages and create folders
|
| 4 |
+
#generate Glottolog table (based on Glottolog 4.4)
|
| 5 |
+
#calculate metric scores (based on Grambank 1.0)
|
| 6 |
+
#generate population table (all sociodemographic variables in one dataframe)
|
| 7 |
+
#wrangling EDGE tree
|
| 8 |
+
#generating AUTOTYP areas table
|
| 9 |
+
source("get_external_data.R")
|
| 10 |
+
source("generating_GB_input_file.R")
|
| 11 |
+
source("set_up_general.R")
|
| 12 |
+
|
| 13 |
+
#setup for INLA analysis
|
| 14 |
+
source("install_and_load_INLA.R")
|
| 15 |
+
#choosing whether to use the full dataset (possible only for reviewers and if one has own access to Ethnologue and saved the dataset in the data folder on their own) or to only to the subset of Ethnologue with transformed variables made available in this repostiory after running create_pop_table.R
|
| 16 |
+
|
| 17 |
+
#sample <- "full"
|
| 18 |
+
sample <- "reduced" #default
|
| 19 |
+
|
| 20 |
+
source("make_ethnologue_SM_and_merging_tables.R")
|
| 21 |
+
source("create_pop_table.R")
|
| 22 |
+
source("set_up_inla.R")
|
| 23 |
+
|
| 24 |
+
#run all INLA models + extract main results tables
|
| 25 |
+
#Note that previously "fusion" was called "boundness", and this is how it is referenced in all scripts
|
| 26 |
+
|
| 27 |
+
#predictors: random effects - phylogenetic and spatial (same scripts for "full" and "reduced" versions)
|
| 28 |
+
source("models_Boundness_phylogenetic_spatial.R")
|
| 29 |
+
source("models_Informativity_phylogenetic_spatial.R")
|
| 30 |
+
|
| 31 |
+
if(sample == "full"){
|
| 32 |
+
|
| 33 |
+
#predictors: phylogenetic and spatial random effects + sociodemograhic variables as fixed effects
|
| 34 |
+
source("models_Boundness_social.R")
|
| 35 |
+
source("models_Informativity_social.R")
|
| 36 |
+
|
| 37 |
+
#predictors: sociodemographic variables as fixed effects
|
| 38 |
+
source("models_Boundness_social_only.R")
|
| 39 |
+
source("models_Informativity_social_only.R")
|
| 40 |
+
|
| 41 |
+
#conduct sensitivity testing + extract the corresponding table
|
| 42 |
+
source("runs_sensitivity.R")
|
| 43 |
+
|
| 44 |
+
#extract tables from INLA analyses
|
| 45 |
+
source("table_INLA_summary_all_models_SI.R")
|
| 46 |
+
source("variance_top_ranking_models.R")
|
| 47 |
+
|
| 48 |
+
#plotting main results
|
| 49 |
+
source("plot_social_effects_combined.R")
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
if(sample == "reduced"){
|
| 53 |
+
|
| 54 |
+
#predictors: phylogenetic and spatial random effects + sociodemograhic variables as fixed effects
|
| 55 |
+
#(on reduced set of social variables: without log10 transformed L1 speakers)
|
| 56 |
+
source("models_Boundness_reduced_social.R")
|
| 57 |
+
source("models_Informativity_reduced_social.R")
|
| 58 |
+
|
| 59 |
+
#predictors: sociodemographic variables as fixed effects
|
| 60 |
+
source("models_Boundness_reduced_social_only.R")
|
| 61 |
+
source("models_Informativity_reduced_social_only.R")
|
| 62 |
+
|
| 63 |
+
#conduct sensitivity testing + extract the corresponding table
|
| 64 |
+
source("runs_sensitivity_on_reduced.R")
|
| 65 |
+
|
| 66 |
+
#extract tables from INLA analyses
|
| 67 |
+
source("table_INLA_summary_all_models_SI_reduced.R")
|
| 68 |
+
source("variance_top_ranking_models_reduced.R")
|
| 69 |
+
|
| 70 |
+
#plotting main results
|
| 71 |
+
source("plots_social_effects_combined_on_reduced.R")
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
#measure phylogenetic signal in two fusion and informativity
|
| 75 |
+
source("measuring_phylosignal.R")
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
#plotting
|
| 79 |
+
source("plot_maps_main.R") #maps of scores
|
| 80 |
+
source("plot_heatmap_B_I.R") #phylogenetic tree with a heatmap
|
| 81 |
+
source("plot_map_Africa.R")
|
| 82 |
+
source("plot_map_Eurasia.R")
|
| 83 |
+
source("plot_heatmap_informativity_Uralic.R") #Uralic tree (informativity) + combined plot with two maps from above
|
| 84 |
+
source("plot_spatial_parameters_linear_distances.R") #SI figure for visualizing how covariance under different kappa and phi parameters corresponds to spatial distances
|
| 85 |
+
|
| 86 |
+
#additional analyses on WALS data
|
| 87 |
+
source("make_ethnologue_SM_for_morphological_complexity_reanalysis.R")
|
| 88 |
+
source("WALS_sparseness.R")
|
| 89 |
+
source("WALS_reanalysis_setup.R")
|
| 90 |
+
source("WALS_reanalysis_controlled_setup.R")
|
| 91 |
+
source("WALS_reanalysis_controlled_setup_high_coverage.R") #analysis + summary table
|
101/replication_package/assigning_AUTOTYP_areas.R
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#This script assigns all languages in glottolog_df to their nearest AUTOTYP area
|
| 2 |
+
|
| 3 |
+
#Script was written by Hedvig Skirgård
|
| 4 |
+
|
| 5 |
+
source("requirements.R")
|
| 6 |
+
|
| 7 |
+
OUTPUTDIR_data_wrangling <- here("data_wrangling")
|
| 8 |
+
# create output dir if it does not exist.
|
| 9 |
+
if (!dir.exists(OUTPUTDIR_data_wrangling)) {
|
| 10 |
+
dir.create(OUTPUTDIR_data_wrangling)
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
if (!file.exists(here(OUTPUTDIR_data_wrangling, "glottolog_AUTOTYPE_areas.tsv"))) {
|
| 14 |
+
#GB langs for subsettting
|
| 15 |
+
GB_langs <-
|
| 16 |
+
read_tsv("data/GB_wide/GB_wide_strict.tsv", col_types = WIDE_COLSPEC) %>%
|
| 17 |
+
dplyr::select(Language_ID)
|
| 18 |
+
|
| 19 |
+
#combining the tables languages and values from glottolog_df-cldf into one wide dataframe.
|
| 20 |
+
#this can be replaced with any list of Language_IDs, long and lat
|
| 21 |
+
|
| 22 |
+
glottolog_fn <- "data_wrangling/glottolog_cldf_wide_df.tsv"
|
| 23 |
+
if (!file.exists(glottolog_fn)) {
|
| 24 |
+
source("generating_GB_input_file.R")
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
glottolog_df <- read.delim(glottolog_fn , sep = "\t") %>%
|
| 28 |
+
dplyr::select(Language_ID, Longitude, Latitude) %>%
|
| 29 |
+
inner_join(GB_langs, by = "Language_ID")
|
| 30 |
+
|
| 31 |
+
##Adding in areas of linguistic contact from AUTOTYP
|
| 32 |
+
|
| 33 |
+
AUTOTYP <-
|
| 34 |
+
read.delim(
|
| 35 |
+
"https://raw.githubusercontent.com/autotyp/autotyp-data/master/data/csv/Register.csv",
|
| 36 |
+
sep = ","
|
| 37 |
+
) %>%
|
| 38 |
+
dplyr::select(Language_ID = Glottocode, Area, Longitude, Latitude) %>%
|
| 39 |
+
group_by(Language_ID, Area) %>% #some lgs are assigned to more than one area, we level that out.
|
| 40 |
+
sample_n(1)
|
| 41 |
+
|
| 42 |
+
#This next bit where we find the autotyp areas of languages was written by Seán Roberts
|
| 43 |
+
# We know the autotyp-area of langauges in autotyp and their long lat. We don't know the autotyp area of languages in Glottolog. We also can't be sure that the long lat of languoids with the same glottoids in autotyp and glottolog_df have the exact identical long lat. First let's make two datasets, one for autotyp languages (hence lgs where we know the area) and those that we wish to know about, the Glottolog ones.
|
| 44 |
+
|
| 45 |
+
lgs_with_known_area <-
|
| 46 |
+
as.matrix(AUTOTYP[!is.na(AUTOTYP$Area), c("Longitude", "Latitude")])
|
| 47 |
+
rownames(lgs_with_known_area) <-
|
| 48 |
+
AUTOTYP[!is.na(AUTOTYP$Area), ]$Language_ID
|
| 49 |
+
|
| 50 |
+
known_areas <- AUTOTYP %>%
|
| 51 |
+
dplyr::filter(!is.na(Area)) %>%
|
| 52 |
+
dplyr::select(Language_ID, Area) %>%
|
| 53 |
+
distinct() %>%
|
| 54 |
+
dplyr::select(AUTOTYP_Language_ID = Language_ID, everything())
|
| 55 |
+
|
| 56 |
+
rm(AUTOTYP)
|
| 57 |
+
|
| 58 |
+
lgs_with_unknown_area <-
|
| 59 |
+
as.matrix(glottolog_df[, c("Longitude", "Latitude")])
|
| 60 |
+
rownames(lgs_with_unknown_area) <- glottolog_df$Language_ID
|
| 61 |
+
|
| 62 |
+
# For missing, find area of closest langauge
|
| 63 |
+
atDist <-
|
| 64 |
+
rdist.earth(lgs_with_known_area, lgs_with_unknown_area, miles = F)
|
| 65 |
+
|
| 66 |
+
rm(lgs_with_known_area, lgs_with_unknown_area)
|
| 67 |
+
|
| 68 |
+
df_matched_up <-
|
| 69 |
+
as.data.frame(unlist(apply(atDist, 2, function(x) {
|
| 70 |
+
names(which.min(x))
|
| 71 |
+
})), stringsAsFactors = F) %>%
|
| 72 |
+
rename(AUTOTYP_Language_ID = `unlist(apply(atDist, 2, function(x) { names(which.min(x)) }))`)
|
| 73 |
+
|
| 74 |
+
glottolog_df_with_AUTOTYP <- df_matched_up %>%
|
| 75 |
+
tibble::rownames_to_column("Language_ID") %>%
|
| 76 |
+
full_join(known_areas, by = "AUTOTYP_Language_ID") %>%
|
| 77 |
+
right_join(glottolog_df, by = "Language_ID") %>%
|
| 78 |
+
dplyr::select(-AUTOTYP_Language_ID) %>%
|
| 79 |
+
group_by(Language_ID) %>% #some lgs are assigned to more than one area, we level that out.
|
| 80 |
+
sample_n(1) %>%
|
| 81 |
+
rename(AUTOTYP_area = Area)
|
| 82 |
+
|
| 83 |
+
glottolog_df_with_AUTOTYP %>%
|
| 84 |
+
write_tsv(here(OUTPUTDIR_data_wrangling, "glottolog_AUTOTYPE_areas.tsv"))
|
| 85 |
+
}
|
101/replication_package/create_pop_table.R
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#create_pop_table
|
| 2 |
+
|
| 3 |
+
OUTPUTDIR_data_wrangling <- here("data_wrangling")
|
| 4 |
+
# create output dir if it does not exist.
|
| 5 |
+
if (!dir.exists(OUTPUTDIR_data_wrangling)) {
|
| 6 |
+
dir.create(OUTPUTDIR_data_wrangling)
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
#Glottolog df for ISO_639 merging
|
| 11 |
+
glottolog_df <-
|
| 12 |
+
read_tsv("data_wrangling/glottolog_cldf_wide_df.tsv", col_types = cols()) %>%
|
| 13 |
+
dplyr::select(
|
| 14 |
+
Glottocode,
|
| 15 |
+
Language_ID,
|
| 16 |
+
"ISO_639" = ISO639P3code,
|
| 17 |
+
Language_level_ID,
|
| 18 |
+
level,
|
| 19 |
+
Family_ID,
|
| 20 |
+
Longitude,
|
| 21 |
+
Latitude
|
| 22 |
+
) %>%
|
| 23 |
+
mutate(Language_level_ID = if_else(is.na(Language_level_ID), Glottocode, Language_level_ID)) %>%
|
| 24 |
+
mutate(Family_ID = ifelse(is.na(Family_ID), Language_level_ID, Family_ID)) %>%
|
| 25 |
+
dplyr::select(
|
| 26 |
+
Glottocode,
|
| 27 |
+
Language_ID,
|
| 28 |
+
ISO_639,
|
| 29 |
+
Language_level_ID,
|
| 30 |
+
level,
|
| 31 |
+
Family_ID,
|
| 32 |
+
Longitude,
|
| 33 |
+
Latitude
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
if (sample == "full") {
|
| 38 |
+
data_ethnologue <-
|
| 39 |
+
read_tsv("data_wrangling/ethnologue_pop_full.tsv")
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
if (sample == "reduced") {
|
| 43 |
+
#double check if the file below needs to be changed
|
| 44 |
+
data_ethnologue <-
|
| 45 |
+
read_tsv("data_wrangling/ethnologue_pop_SM.tsv", show_col_types = F) %>%
|
| 46 |
+
rename(L1_log10_st = L1_log10_scaled) %>%
|
| 47 |
+
dplyr::select(ISO_639, Language_ID, L1_log10_st, L2_prop)
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
social_vars <-
|
| 51 |
+
readxl::read_xlsx(
|
| 52 |
+
"data/lang_endangerment_predictors.xlsx",
|
| 53 |
+
sheet = "Supplementary data 1",
|
| 54 |
+
skip = 1,
|
| 55 |
+
col_types = "text",
|
| 56 |
+
na = "NA"
|
| 57 |
+
) %>%
|
| 58 |
+
left_join(glottolog_df, by = c("ISO" = "ISO_639")) %>%
|
| 59 |
+
rename("ISO_639" = "ISO") %>%
|
| 60 |
+
dplyr::select(
|
| 61 |
+
Language_ID = Glottocode,
|
| 62 |
+
ISO_639,
|
| 63 |
+
official_status,
|
| 64 |
+
language_of_education,
|
| 65 |
+
bordering_language_richness
|
| 66 |
+
) %>%
|
| 67 |
+
rename(Official = official_status) %>%
|
| 68 |
+
# naniar::replace_with_na(replace = list(L1_log10 = -Inf, L2_log10 = -Inf)) #removing for now
|
| 69 |
+
dplyr::mutate(neighboring_languages = bordering_language_richness, Education =
|
| 70 |
+
language_of_education) %>%
|
| 71 |
+
dplyr::mutate(neighboring_languages = as.numeric(neighboring_languages)) %>%
|
| 72 |
+
#dplyr::mutate(neighboring_languages_log10 = log10(neighboring_languages+1)) %>%
|
| 73 |
+
dplyr::mutate(neighboring_languages_st = scale(neighboring_languages)[, 1]) %>%
|
| 74 |
+
#dplyr::mutate(neighboring_languages_log10_st = scale(neighboring_languages_log10)[,1]) %>%
|
| 75 |
+
dplyr::select(Language_ID, Education, Official, neighboring_languages_st)
|
| 76 |
+
|
| 77 |
+
if (sample == "full") {
|
| 78 |
+
social_vars %>%
|
| 79 |
+
left_join(data_ethnologue, by = c("Language_ID")) %>%
|
| 80 |
+
dplyr::select(
|
| 81 |
+
Language_ID,
|
| 82 |
+
L1_log10_st,
|
| 83 |
+
L1_log10,
|
| 84 |
+
L2_prop,
|
| 85 |
+
Education,
|
| 86 |
+
Official,
|
| 87 |
+
neighboring_languages_st
|
| 88 |
+
) %>%
|
| 89 |
+
write_tsv(here(OUTPUTDIR_data_wrangling, "pop_full.tsv"))
|
| 90 |
+
} else{
|
| 91 |
+
social_vars %>%
|
| 92 |
+
left_join(data_ethnologue, by = c("Language_ID")) %>%
|
| 93 |
+
dplyr::select(Language_ID,
|
| 94 |
+
L1_log10_st,
|
| 95 |
+
L2_prop,
|
| 96 |
+
Education,
|
| 97 |
+
Official,
|
| 98 |
+
neighboring_languages_st) %>%
|
| 99 |
+
write_tsv(here(OUTPUTDIR_data_wrangling, "pop_reduced.tsv"))
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
glottolog_df_ISO <- glottolog_df %>%
|
| 103 |
+
dplyr::select("Language_ID", "ISO_639")
|
| 104 |
+
|
| 105 |
+
if (sample == "reduced") {
|
| 106 |
+
social_vars %>%
|
| 107 |
+
left_join(data_ethnologue, by = c("Language_ID")) %>%
|
| 108 |
+
dplyr::select(Language_ID,
|
| 109 |
+
L1_log10_st,
|
| 110 |
+
L2_prop,
|
| 111 |
+
Education,
|
| 112 |
+
Official,
|
| 113 |
+
neighboring_languages_st) %>%
|
| 114 |
+
left_join(glottolog_df_ISO,
|
| 115 |
+
by = c("Language_ID")) %>%
|
| 116 |
+
write_tsv(here(OUTPUTDIR_data_wrangling, "pop_reduced_with_ISO.tsv"))
|
| 117 |
+
}
|
101/replication_package/creating_boundness_metric.R
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#boundness/fusion
|
| 2 |
+
|
| 3 |
+
#Script was written by Hedvig Skirgård
|
| 4 |
+
|
| 5 |
+
source("requirements.R")
|
| 6 |
+
|
| 7 |
+
OUTPUTDIR1 <- file.path('.', "output", "Bound_morph")
|
| 8 |
+
# create output dir if it does not exist.
|
| 9 |
+
if (!dir.exists(OUTPUTDIR1)) {
|
| 10 |
+
dir.create(OUTPUTDIR1)
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
if (!file.exists(here(OUTPUTDIR1, "bound_morph_score.tsv"))) {
|
| 14 |
+
GB_wide <-
|
| 15 |
+
read_tsv(file.path("data", "GB_wide", "GB_wide_strict.tsv"),
|
| 16 |
+
col_types = WIDE_COLSPEC)
|
| 17 |
+
|
| 18 |
+
#read in sheet with scores for whether a feature denotes fusion
|
| 19 |
+
GB_fusion_points <-
|
| 20 |
+
data.table::fread(
|
| 21 |
+
file.path("data", "GB_wide", "parameters.csv"),
|
| 22 |
+
encoding = 'UTF-8',
|
| 23 |
+
quote = "\"",
|
| 24 |
+
header = TRUE,
|
| 25 |
+
sep = ","
|
| 26 |
+
) %>%
|
| 27 |
+
dplyr::select(Parameter_ID = ID, Fusion = boundness, informativity) %>%
|
| 28 |
+
mutate(Fusion = as.numeric(Fusion))
|
| 29 |
+
|
| 30 |
+
df_morph_count <- GB_wide %>%
|
| 31 |
+
filter(na_prop <= 0.25) %>% #exclude languages with more than 25% missing data
|
| 32 |
+
dplyr::select(-na_prop) %>%
|
| 33 |
+
reshape2::melt(id.vars = "Language_ID") %>%
|
| 34 |
+
dplyr::rename(Parameter_ID = variable) %>%
|
| 35 |
+
inner_join(GB_fusion_points, by = "Parameter_ID") %>%
|
| 36 |
+
filter(Fusion == 1) %>%
|
| 37 |
+
filter(!is.na(value)) %>%
|
| 38 |
+
group_by(Language_ID) %>%
|
| 39 |
+
dplyr::summarise(mean_morph = mean(value)) %>%
|
| 40 |
+
dplyr::select(Language_ID, boundness = mean_morph)
|
| 41 |
+
|
| 42 |
+
boundness_st = scale(df_morph_count$boundness)
|
| 43 |
+
df_morph_count <- cbind(df_morph_count, boundness_st)
|
| 44 |
+
|
| 45 |
+
df_morph_count %>%
|
| 46 |
+
write_tsv(file.path(OUTPUTDIR1, "bound_morph_score.tsv"))
|
| 47 |
+
|
| 48 |
+
}
|
101/replication_package/creating_informativity_score.R
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#informativity
|
| 2 |
+
source("requirements.R")
|
| 3 |
+
|
| 4 |
+
#Script was written by Hedvig Skirgård
|
| 5 |
+
|
| 6 |
+
OUTPUTDIR2 <- file.path('.', "output", "Informativity")
|
| 7 |
+
# create output dir if it does not exist.
|
| 8 |
+
if (!dir.exists(OUTPUTDIR2)) { dir.create(OUTPUTDIR2) }
|
| 9 |
+
|
| 10 |
+
if (!file.exists(here(OUTPUTDIR2, "informativity_score.tsv"))) {
|
| 11 |
+
|
| 12 |
+
GB_wide <-
|
| 13 |
+
read_tsv(file.path("data", "GB_wide", "GB_wide_strict.tsv"),
|
| 14 |
+
show_col_types = F) %>%
|
| 15 |
+
filter(na_prop <= 0.25) %>%
|
| 16 |
+
dplyr::select(-na_prop)
|
| 17 |
+
|
| 18 |
+
#read in sheet with scores for whether a feature denotes informativity
|
| 19 |
+
GB_informativity_points <- read_csv(file.path("data", "GB_wide", "parameters.csv"),
|
| 20 |
+
show_col_types = F) %>%
|
| 21 |
+
dplyr::select(Parameter_ID = ID, informativity) %>%
|
| 22 |
+
mutate(informativity = replace(informativity, Parameter_ID == "GB177", "argumentanimacy")) %>% #manually adding another parameter: assigning the parameter of GB177 ("Can the verb carry a marker of animacy of argument, unrelated to any gender/noun class of the argument visible in the NP domain?") feature to be informative
|
| 23 |
+
filter(!is.na(informativity))
|
| 24 |
+
|
| 25 |
+
GB_long_for_calc <- GB_wide %>%
|
| 26 |
+
reshape2::melt(id.vars = "Language_ID") %>%
|
| 27 |
+
rename(Parameter_ID = variable) %>%
|
| 28 |
+
inner_join(GB_informativity_points , by = "Parameter_ID")
|
| 29 |
+
|
| 30 |
+
##informativity score
|
| 31 |
+
lg_df_informativity_score <- GB_long_for_calc %>%
|
| 32 |
+
mutate(value = if_else(Parameter_ID == "GB140", abs(value - 1), value)) %>% # reversing GB140 because 0 is the informative state
|
| 33 |
+
group_by(Language_ID, informativity) %>% #grouping per language and per informativity category
|
| 34 |
+
summarise(sum_informativity = sum(value, na.rm = T),
|
| 35 |
+
#for each informativity cateogry for each langauge, how many are answered 1 ("yes")
|
| 36 |
+
sum_na = sum(is.na(value))) %>% #how many of the values per informativity category are missing
|
| 37 |
+
mutate(sum_informativity = ifelse(sum_na >= 1 &
|
| 38 |
+
sum_informativity == 0, NA, sum_informativity)) %>% #if there is at least one NA and the sum of values for the entire category is 0, the informativity score should be NA because there could be a 1 hiding under the NA value
|
| 39 |
+
mutate(informativity_score = ifelse(sum_informativity >= 1, 1, sum_informativity)) %>%
|
| 40 |
+
ungroup() %>%
|
| 41 |
+
group_by(Language_ID) %>%
|
| 42 |
+
summarise(`Informativity` = mean(informativity_score, na.rm = T, .groups = "drop")) %>%
|
| 43 |
+
dplyr::select(Language_ID, `Informativity`)
|
| 44 |
+
|
| 45 |
+
informativity_st = scale(lg_df_informativity_score$Informativity)
|
| 46 |
+
lg_df_informativity_score <-
|
| 47 |
+
cbind(lg_df_informativity_score, informativity_st)
|
| 48 |
+
|
| 49 |
+
lg_df_informativity_score %>%
|
| 50 |
+
write_tsv(here(OUTPUTDIR2, "informativity_score.tsv"))
|
| 51 |
+
}
|
101/replication_package/data/GB_wide/parameters.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:effcb8e4ae1ef49e5558a828a2efba5b446c9c289e564fabd822e4b3d1739083
|
| 3 |
+
size 955498
|
101/replication_package/data/complexity_data_WALS.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:05af559ebdfd0fb8a4a84f0ab525fbce3f2609eb43301fb0edeb310a12b9805a
|
| 3 |
+
size 49149
|
101/replication_package/data/glottolog-cldf_wide_df.tsv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fa70feae51fe695ae91d4ec29e5f78fb90bc26e507ede909dd3c10d45e14852b
|
| 3 |
+
size 10892168
|
101/replication_package/data/lang_endangerment_predictors.xlsx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:65ba3f53b2eb30352d758c326b4889910022adb64b45bdead1d0fbfa00df6e69
|
| 3 |
+
size 5040478
|
101/replication_package/data/phylogenies/EDGE6635-merged-relabelled.tree
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a99c4b3cda474be6091ed433fa3fc5ba50f55082e599319b6a6677b5baacbc7f
|
| 3 |
+
size 20461790
|
101/replication_package/data_wrangling/ethnologue_pop_SM.tsv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:42cde751f7f3555c3b9fa4b7bf70a5f0e9c5927c9524286834759370e5c82d90
|
| 3 |
+
size 228185
|
101/replication_package/data_wrangling/ethnologue_pop_SM_morph_compl_reanalysis.tsv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bf9d6ae875e98a5bb4cecfcfee4dd69f0f70949205ff6e3b3f3a6df0430d6e25
|
| 3 |
+
size 639778
|