Makefile 2.1 KB
Newer Older
Jon Zelner's avatar
Jon Zelner committed
1
## Phony target to make pdf
Jon Zelner's avatar
Jon Zelner committed
2
.PHONY: pdf
Jon Zelner's avatar
Jon Zelner committed
3
pdf : output/results.pdf 
Jon Zelner's avatar
Jon Zelner committed
4 5


Jon Zelner's avatar
Jon Zelner committed
6 7 8
## First, extract parameters from the text-based makefile into an R
## list saved into an RDS object file. This just makes it easier to access
## parameters by name during model execution and post-processing
Jon Zelner's avatar
Jon Zelner committed
9 10 11 12 13
output/parameters.Rds : munge/extract_parameters.R  data/parameters.csv
	@echo --- Extracting parameters from CSV ---
	@mkdir -p $(@D)
	./$< -o [email protected] -p $(word 2, $^)

Jon Zelner's avatar
Jon Zelner committed
14 15

## Using the parameter values from the input data, simulate a data file
Jon Zelner's avatar
Jon Zelner committed
16 17 18 19 20
output/samples.csv : src/simdata.R output/parameters.Rds
	@echo --- Simulating data ---
	@mkdir -p $(@D)
	./$< -o [email protected] -p $(word 2, $^)

Jon Zelner's avatar
Jon Zelner committed
21 22

## Run the stan model, and save the stanmodel object to an RDS file
Jon Zelner's avatar
Jon Zelner committed
23 24 25
output/stan_samples.Rds : src/runmodel.R src/model.stan output/samples.csv 
	@echo --- Running Stan mixture model ---
	@mkdir -p $(@D)
Jon Zelner's avatar
Jon Zelner committed
26
	./$< -o [email protected] -m $(word 2, $^) -d $(word 3, $^)  -c 2 -i 4000
Jon Zelner's avatar
Jon Zelner committed
27

Jon Zelner's avatar
Jon Zelner committed
28 29 30
## Generate figures using the posterior distributions of model parameters.
## Note the additional dependency on the input parameters, which we use to
## get a sense of goodness-of-fit in the posterior plots
31
output/figures/p_*.pdf : src/make_figures.R output/stan_samples.Rds output/parameters.Rds
Jon Zelner's avatar
Jon Zelner committed
32 33 34 35
	@echo --- Generating figures ---
	@mkdir -p $(@D)
	./$< -o output/figures -s $(word 2, $^) -p $(word 3, $^)

Jon Zelner's avatar
Jon Zelner committed
36 37 38 39 40 41
output/figures/d_density.pdf : src/data_figure.R output/samples.csv
	@echo --- Generating data figure ---
	@mkdir -p $(@D)
	./$< -o output/figures -d $(word 2, $^)

## Translate from Rmarkdown to markdown using knitr
42
output/results.md : presentations/results.Rmd output/figures/p_*.pdf output/figures/d_density.pdf data/parameters.csv
43
	@echo ----Translating results from RMD to Markdown----
Jon Zelner's avatar
Jon Zelner committed
44
	@mkdir -p $(@D)
45 46 47 48 49
	Rscript \
		-e "require(knitr)" \
                -e "knitr::render_markdown()"\
		-e "knitr::knit('$<','[email protected]')"

Jon Zelner's avatar
Jon Zelner committed
50 51
## Generate PDF from resulting markdown
output/results.pdf : output/results.md 
52
	@echo ----Generating PDF from Markdown----
Jon Zelner's avatar
Jon Zelner committed
53 54
	@mkdir -p $(@D)
	pandoc $< -V geometry:margin=1.0in --from=markdown -t latex -s -o [email protected]  -V fontsize=12pt
55 56


Jon Zelner's avatar
Jon Zelner committed
57 58
.PHONY: clean
clean :
Jon Zelner's avatar
Jon Zelner committed
59
	@echo --- Removing generated files ---
Jon Zelner's avatar
Jon Zelner committed
60
	rm -r output