-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·217 lines (167 loc) · 5.05 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#####################################
# name: Makefile
# author: Dylan Morris <dhmorris@princeton.edu>
#
# Makefile to generate analyses
# for Stoddard et al 2020 study
# of hummingbird non-spectral color
# perception
#
####################################
#####################################
# Directory structure
####################################
default: all
SRC := src
OUT := out
DAT := dat
MCMC_CHAINS := $(OUT)/mcmc_chains
CLEANED_DATA_DIR := $(DAT)/cleaned
PLOT_PATH = $(OUT)/figures
#####################################
# File extensions and the like
####################################
CHAINS_SUFFIX = _chains.Rds
#####################################
# Expected bash settings
#
# Check these vs your local
# machine setup if you are having
# difficulty reproducing the
# analysis
#####################################
CXX := g++-8
MKDIR := @mkdir -p
RM := rm -rf
R_OPTIONS = --vanilla
R_COMMAND := Rscript $(R_OPTIONS)
#####################################
# Installation / dependencies
#
# Rules for prepping analysis
#####################################
.PHONY: depend
depend:
$(R_COMMAND) $(SRC)/install_needed_packages.R
#####################################
# Analysis locations
#
# setup for data processing and
# model fitting
#####################################
# script locations
####################
MODEL_FITTING_SCRIPT = $(SRC)/fit_stan_model.R
DIAGNOSTIC_SCRIPT = $(SRC)/chain_diagnostics.R
REPORTED_QUANTITIES_SCRIPT = $(SRC)/extract_reported_quantities.R
####################
# data locations
####################
CLEANED_DATA = $(CLEANED_DATA_DIR)/CleanedDataTable.csv
#########################
# model names, model output locations
#########################
MAIN_MODEL_NAME = main_stan_model
MULTILEVEL_MODEL_NAME = multilevel_model
NO_ERROR_MODEL_NAME = no_error_model
MODELS = $(MAIN_MODEL_NAME) $(MULTILEVEL_MODEL_NAME) \
$(NO_ERROR_MODEL_NAME)
MODEL_DATA = $(CLEANED_DATA)
CHAINS = $(addsuffix $(CHAINS_SUFFIX), \
$(addprefix $(MCMC_CHAINS)/, $(MODELS)))
DIAGNOSTIC_FILE = $(OUT)/chain_diagnostics.csv
REPORTED_QUANTITIES_FILE = $(OUT)/reported_quantities.csv
##################################
# figure names and output paths
##################################
RIDGELINE_FIGS = $(addsuffix _ridgeline.pdf, \
$(addprefix figure_, $(MODELS)))
FIGURES = figure_position_effect.pdf figure_experience.pdf \
figure_pp_check.pdf figure_pp_check_all.pdf\
figure_axis_difference.pdf \
figure_axis_difference_multilevel.pdf \
$(RIDGELINE_FIGS)
FIGURE_PATHS := $(addprefix $(PLOT_PATH)/, $(FIGURES))
#############################
# Rules
#
# definition of dependency
# tree and specification of
# rules for doing stuff
#############################
####################
# rules for model fitting and post-processing
####################
# generic recipe for model chains output
$(MCMC_CHAINS)/%$(CHAINS_SUFFIX): $(SRC)/%.stan $(MODEL_FITTING_SCRIPT) $(MODEL_DATA)
$(MKDIR) $(MCMC_CHAINS)
$(R_COMMAND) $(MODEL_FITTING_SCRIPT) $< $(MODEL_DATA) $@
.PHONY: chains
chains: $(CHAINS)
$(DIAGNOSTIC_FILE): $(DIAGNOSTIC_SCRIPT) $(CHAINS) $(CLEANED_DATA)
$(MKDIR) $(MCMC_CHAINS)
$(R_COMMAND) $^ $@
$(REPORTED_QUANTITIES_FILE): $(REPORTED_QUANTITIES_SCRIPT) \
$(MCMC_CHAINS)/$(MAIN_MODEL_NAME)$(CHAINS_SUFFIX) \
$(CLEANED_DATA)
$(R_COMMAND) $^ $@
####################
# Figures
#
# Rules for autogenerating
# manuscript figures
#
####################
#################
# Generic fig rule
#
# generically, figures generated by file with same name, unless
# otherwise specified
$(PLOT_PATH)/%.pdf: $(SRC)/%.R $(MCMC_CHAINS)/$(MAIN_MODEL_NAME)$(CHAINS_SUFFIX) $(CLEANED_DATA)
$(MKDIR) $(PLOT_PATH)
$(R_COMMAND) $^ $@
@$(RM) Rplots.pdf
#################
# other fig rules
#################
$(PLOT_PATH)/figure_%_ridgeline.pdf: $(SRC)/figure_posterior_ridgeline.R \
$(MCMC_CHAINS)/%$(CHAINS_SUFFIX) $(CLEANED_DATA)
$(MKDIR) $(PLOT_PATH)
$(R_COMMAND) $^ $@
@$(RM) Rplots.pdf
$(PLOT_PATH)/figure_axis_difference_multilevel.pdf: $(SRC)/figure_axis_difference.R $(MCMC_CHAINS)/$(MULTILEVEL_MODEL_NAME)$(CHAINS_SUFFIX) $(CLEANED_DATA)
@$(MKDIR) $(PLOT_PATH)
$(R_COMMAND) $^ $@
@$(RM) Rplots.pdf
$(PLOT_PATH)/figure_pp_check_all.pdf: $(SRC)/figure_pp_check.R $(CHAINS) $(CLEANED_DATA) $(CLEANED_DATA_FULL)
@$(MKDIR) $(PLOT_PATH)
$(R_COMMAND) $^ $@
@$(RM) Rplots.pdf
.PHONY: figs
figs: $(FIGURE_PATHS)
#####################################
# Cleanup
#
# Rules for cleaning up
# directories
#####################################
.PHONY: clean del-temp
del-temp:
@$(RM) *#*
@$(RM) *~
@$(RM) */*~
@$(RM) */*#
clean: del-temp
@$(RM) out
@$(RM) .Rhistory
@$(RM) Rplots.pdf
#####################################
# Global rules
#
# define any rules that derive
# from everything above
#####################################
.PHONY: all
all: depend $(CLEANED_DATA) \
$(CHAINS) $(DIAGNOSTIC_FILE) \
$(REPORTED_QUANTITIES_FILE) $(FIGURE_PATHS)