forked from ceopinio/ceo-estimacions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snakefile
110 lines (94 loc) · 3.34 KB
/
Snakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from os.path import join
# Load the configuration
configfile: 'config/config.yaml'
SRC_FOLDER = config["SRC_FOLDER"]
DTA_FOLDER = config["DTA_FOLDER"]
RAW_DTA_FOLDER = config["RAW_DTA_FOLDER"]
MDL_FOLDER = config["MDL_FOLDER"]
RAW_DTA_FILE = "Microdades anonimitzades 1031.sav"
models=["model-partychoice", "model-abstention"]
exts=["RDS", "xgb"]
## Rules
rule all:
input:
expand(join(MDL_FOLDER, "{models}.{exts}"),
models=models,
exts=exts),
join(RAW_DTA_FOLDER, RAW_DTA_FILE),
join(DTA_FOLDER, "weight.RDS"),
join(DTA_FOLDER, "predicted-partychoice.RDS"),
join(DTA_FOLDER, "predicted-voting.RDS"),
join(DTA_FOLDER, "thr-predicted-voting.RDS"),
join(DTA_FOLDER, "individual-behavior.RDS"),
join(DTA_FOLDER, "estimated-vote-share.RDS"),
join(DTA_FOLDER, "vote-share-district.RDS"),
join(DTA_FOLDER, "seats-simulation.RDS"),
join(DTA_FOLDER, "seats.RDS"),
## Delete everything for re-runs
rule clean:
shell: f"find {DTA_FOLDER} -maxdepth 1 -type f -delete && find {MDL_FOLDER} -maxdepth 1 -type f -delete"
rule data_cleaning:
input:
dta=join(RAW_DTA_FOLDER, RAW_DTA_FILE),
cmd=join(SRC_FOLDER, "data-cleaning.R")
output: join(DTA_FOLDER, "clean-bop.RDS")
shell:
"Rscript {input.cmd}"
rule past_behavior:
input:
join(RAW_DTA_FOLDER, "results-2021.csv"),
join(RAW_DTA_FOLDER, "llengua.csv"),
join(DTA_FOLDER, "clean-bop.RDS"),
cmd=join(SRC_FOLDER, "past-behavior.R")
output:
join(DTA_FOLDER, "weight.RDS"),
join(DTA_FOLDER, "predicted-recall.RDS"),
join(MDL_FOLDER, "model-recall.RDS"),
join(MDL_FOLDER, "model-recall.xgb")
shell:
"Rscript {input.cmd}"
rule expected_behavior:
input:
dta=join(DTA_FOLDER, "clean-bop.RDS"),
cmd=join(SRC_FOLDER, "expected-behavior.R")
output:
expand(join(MDL_FOLDER, "{models}.{exts}"),
models=models,
exts=exts),
join(DTA_FOLDER, "predicted-partychoice.RDS"),
join(DTA_FOLDER, "predicted-voting.RDS"),
join(DTA_FOLDER, "thr-predicted-voting.RDS")
shell:
"Rscript {input.cmd}"
rule vote_shares:
input:
join(DTA_FOLDER, "clean-bop.RDS"),
join(DTA_FOLDER, "weight.RDS"),
join(DTA_FOLDER, "predicted-partychoice.RDS"),
join(DTA_FOLDER, "predicted-voting.RDS"),
join(DTA_FOLDER, "thr-predicted-voting.RDS"),
cmd=join(SRC_FOLDER, "vote-shares.R")
output:
join(DTA_FOLDER, "individual-behavior.RDS"),
join(DTA_FOLDER, "estimated-vote-share.RDS")
shell:
"Rscript {input.cmd}"
rule district_shares:
input:
join(RAW_DTA_FOLDER, "results-2021.csv"),
join(DTA_FOLDER, "clean-bop.RDS"),
join(DTA_FOLDER, "individual-behavior.RDS"),
cmd=join(SRC_FOLDER, "district-shares.R")
output:
join(DTA_FOLDER, "vote-share-district.RDS")
shell:
"Rscript {input.cmd}"
rule seat_estimates:
input:
join(DTA_FOLDER, "vote-share-district.RDS"),
cmd=join(SRC_FOLDER, "seat-estimates.R")
output:
join(DTA_FOLDER, "seats-simulation.RDS"),
join(DTA_FOLDER, "seats.RDS")
shell:
"Rscript {input.cmd}"