.ONESHELL:
SHELL=bash

Ns=[1000, 5000, 10000]
ms=[100, 200, 400]
seeds=[$(shell seq -s, 1 500)]
explained_variances=[0.1]

all:main supplement
main:remembr.RDS 
supplement:robustness_1.RDS robustness_1_dv.RDS robustness_2.RDS robustness_2_dv.RDS robustness_3.RDS robustness_3_dv.RDS robustness_3_proflik.RDS robustness_3_dv_proflik.RDS robustness_4.RDS robustness_4_dv.RDS robustness_5.RDS robustness_5_dv.RDS robustness_6.feather

srun=sbatch --wait --verbose run_job.sbatch


joblists:example_1_jobs example_2_jobs example_3_jobs

# test_true_z_jobs: test_true_z.R simulation_base.R
# 	sbatch --wait --verbose run_job.sbatch  ./grid_sweep.py --command "Rscript test_true_z.R" --arg_dict '{"N":${Ns},"m":${ms}, "seed":${seeds}, "outfile":["test_true_z.feather"], "y_explained_variancevari":${explained_variances}, "Bzx":${Bzx}}' --outfile test_true_z_jobsb

# test_true_z.feather: test_true_z_jobs 
# 	rm -f test_true_z.feather
# 	sbatch --wait --verbose --array=1-3000 run_simulation.sbatch 0 test_true_z_jobs
# 	sbatch --wait --verbose --array=3001-6001 run_simulation.sbatch 0 test_true_z_jobs


example_1_jobs: 01_two_covariates.R simulation_base.R grid_sweep.py pl_methods.R
	${srun} ./grid_sweep.py --command "Rscript 01_two_covariates.R" --arg_dict '{"N":${Ns},"m":${ms}, "seed":${seeds}, "outfile":["example_1.feather"], "y_explained_variance":${explained_variances}, "Bzx":[1]}' --outfile example_1_jobs

example_1.feather: example_1_jobs 
	rm -f example_1.feather
	sbatch --wait --verbose --array=1-1000  run_simulation.sbatch 0 example_1_jobs
	sbatch --wait --verbose --array=1001-2000 run_simulation.sbatch 0 example_1_jobs
	sbatch --wait --verbose --array=2001-3000  run_simulation.sbatch 0 example_1_jobs
	sbatch --wait --verbose --array=3001-$(shell cat example_1_jobs | wc -l) run_simulation.sbatch 0 example_1_jobs

example_2_jobs: 02_indep_differential.R simulation_base.R grid_sweep.py pl_methods.R
	sbatch --wait --verbose run_job.sbatch ./grid_sweep.py --command "Rscript 02_indep_differential.R" --arg_dict '{"N":${Ns},"m":${ms}, "seed":${seeds}, "outfile":["example_2.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+z+x"]}' --outfile example_2_jobs

example_2.feather: example_2_jobs 
	rm -f example_2.feather
	sbatch --wait --verbose --array=1-1000  run_simulation.sbatch 0 example_2_jobs
	sbatch --wait --verbose --array=1001-2000 run_simulation.sbatch 0 example_2_jobs
	sbatch --wait --verbose --array=2001-3000  run_simulation.sbatch 0 example_2_jobs
	sbatch --wait --verbose --array=3001-$(shell cat example_2_jobs | wc -l) run_simulation.sbatch 0 example_2_jobs



# example_2_B_jobs: example_2_B.R
# 	sbatch --wait --verbose run_job.sbatch python3 ./grid_sweep.py --command "Rscript example_2_B.R" --arg_dict '{"N":${Ns},"m":${ms}, "seed":${seeds}, "outfile":["example_2_B.feather"]}' --outfile example_2_B_jobs

# example_2_B.feather: example_2_B_jobs
# 	rm -f example_2_B.feather
# 	sbatch --wait --verbose --array=1-3000 run_simulation.sbatch 0 example_2_B_jobs

example_3_jobs: 03_depvar.R simulation_base.R grid_sweep.py pl_methods.R
	sbatch --wait --verbose run_job.sbatch ./grid_sweep.py --command "Rscript 03_depvar.R" --arg_dict '{"N":${Ns},"m":${ms}, "Bxy":[0.7],"Bzy":[-0.7],"Bzx":[1],"seed":${seeds}, "outfile":["example_3.feather"], "y_explained_variance":${explained_variances}}' --outfile example_3_jobs

example_3.feather: example_3_jobs
	rm -f example_3.feather	
	sbatch --wait --verbose --array=1-1000  run_simulation.sbatch 0 example_3_jobs
	sbatch --wait --verbose --array=1001-2000 run_simulation.sbatch 0 example_3_jobs
	 sbatch --wait --verbose --array=2001-3000  run_simulation.sbatch 0 example_3_jobs
	sbatch --wait --verbose --array=3001-$(shell cat example_3_jobs | wc -l) run_simulation.sbatch 0 example_3_jobs

example_4_jobs: 04_depvar_differential.R simulation_base.R grid_sweep.py pl_methods.R
	sbatch --wait --verbose run_job.sbatch ./grid_sweep.py --command "Rscript 04_depvar_differential.R" --arg_dict '{"N":${Ns},"Bxy":[0.7],"Bzy":[-0.7],"Bzx":[1], "m":${ms}, "seed":${seeds}, "outfile":["example_4.feather"], "z_bias":[-0.5], "prediction_accuracy":[0.73]}' --outfile example_4_jobs

example_4.feather: example_4_jobs
	rm -f example_4.feather
	sbatch --wait --verbose --array=1-1000  run_simulation.sbatch 0 example_4_jobs
	sbatch --wait --verbose --array=1001-2000  run_simulation.sbatch 0 example_4_jobs
	sbatch --wait --verbose --array=2001-3001 run_simulation.sbatch 0 example_4_jobs
	sbatch --wait --verbose --array=2001-3000  run_simulation.sbatch 0 example_4_jobs
	sbatch --wait --verbose --array=3001-$(shell cat example_4_jobs | wc -l)  run_simulation.sbatch 0 example_4_jobs


remembr.RDS:example_1.feather example_2.feather example_3.feather example_4.feather plot_example.R plot_dv_example.R summarize_estimator.R
	rm -f remembr.RDS
	${srun} Rscript plot_example.R --infile example_1.feather --name "plot.df.example.1"
	${srun} Rscript plot_example.R --infile example_2.feather --name "plot.df.example.2"
	${srun} Rscript plot_dv_example.R --infile example_3.feather --name "plot.df.example.3"
	${srun} Rscript plot_dv_example.R --infile example_4.feather --name "plot.df.example.4"


START=0
STEP=1000
ONE=1

robustness_Ns=[1000,5000]
robustness_ms=[100,200]

#in robustness 1 / example 2 misclassification is correlated with Y.
robustness_1_jobs_p1: 02_indep_differential.R simulation_base.R grid_sweep.py
	sbatch --wait --verbose run_job.sbatch ./grid_sweep.py --command "Rscript 02_indep_differential.R" --arg_dict '{"N":[1000],"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_1.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3,0],"Bxy":[0.3],"Bzx":[1,0], "outcome_formula":["y~x+z"], "z_bias":[0, 0.5], "proxy_formula":["w_pred~y+x"], "truth_formula":["x~1"]}' --outfile robustness_1_jobs_p1

robustness_1_jobs_p2: 02_indep_differential.R simulation_base.R grid_sweep.py
	sbatch --wait --verbose run_job.sbatch ./grid_sweep.py --command "Rscript 02_indep_differential.R" --arg_dict '{"N":[5000],"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_1.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3,0],"Bxy":[0.3],"Bzx":[1,0], "outcome_formula":["y~x+z"], "z_bias":[0, 0.5], "proxy_formula":["w_pred~y+x"], "truth_formula":["x~1"]}' --outfile robustness_1_jobs_p2

robustness_1.feather: robustness_1_jobs_p1 robustness_1_jobs_p2
	rm -f $@
	$(eval END_1!=cat robustness_1_jobs_p1 | wc -l)
	$(eval ITEMS_1!=seq $(START) $(STEP) $(END_1))
	$(eval END_2!=cat robustness_1_jobs_p2 | wc -l)
	$(eval ITEMS_2!=seq $(START) $(STEP) $(END_2))
	$(foreach item,$(ITEMS_1),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_1_jobs_p1;)
	$(foreach item,$(ITEMS_2),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_1_jobs_p2;)

robustness_1.RDS: robustness_1.feather summarize_estimator.R
	rm -f robustness_1.RDS
	${srun} Rscript plot_example.R --infile $< --name "robustness_1" --remember-file $@

# when Bzy is 0 and zbias is not zero, we have the case where P(W|Y,X,Z) has an omitted variable that is conditionanlly independent from Y.  Note that X and Z are independent in this scenario.
robustness_1_dv_jobs_p1: simulation_base.R 04_depvar_differential.R grid_sweep.py
	${srun} ./grid_sweep.py --command 'Rscript 04_depvar_differential.R' --arg_dict '{"N":[1000],"Bzx":[1], "Bxy":[0.7,0],"Bzy":[-0.7,0],"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_1_dv.feather"], "proxy_formula":["w_pred~y"],"z_bias":[-0.5]}' --outfile robustness_1_dv_jobs_p1

robustness_1_dv_jobs_p2: simulation_base.R 04_depvar_differential.R grid_sweep.py
	${srun} ./grid_sweep.py --command 'Rscript 04_depvar_differential.R' --arg_dict '{"N":[5000],"Bzx":[1], "Bxy":[0.7,0],"Bzy":[-0.7,0],"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_1_dv.feather"], "proxy_formula":["w_pred~y"],"z_bias":[-0.5]}' --outfile robustness_1_dv_jobs_p2

robustness_1_dv.feather: robustness_1_dv_jobs_p1 robustness_1_dv_jobs_p2
	rm -f $@
	$(eval END_1!=cat robustness_1_dv_jobs_p1 | wc -l)
	$(eval ITEMS_1!=seq $(START) $(STEP) $(END_1))
	$(eval END_2!=cat robustness_1_dv_jobs_p2 | wc -l)
	$(eval ITEMS_2!=seq $(START) $(STEP) $(END_1))
	$(foreach item,$(ITEMS_1),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_1_dv_jobs_p1;)
	$(foreach item,$(ITEMS_2),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_1_dv_jobs_p2;)

robustness_1_dv.RDS: robustness_1_dv.feather summarize_estimator.R
	rm -f $@
	${srun} Rscript plot_dv_example.R --infile $< --name "robustness_1_dv" --remember-file $@


robustness_2_jobs_p1: grid_sweep.py 01_two_covariates.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 01_two_covariates.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_2.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x"], "truth_formula":["x~z"], "prediction_accuracy":[0.60,0.65]}' --outfile $@

robustness_2_jobs_p2: grid_sweep.py 01_two_covariates.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 01_two_covariates.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_2.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x"], "truth_formula":["x~z"], "prediction_accuracy":[0.70,0.75]}' --outfile $@

robustness_2_jobs_p3: grid_sweep.py 01_two_covariates.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 01_two_covariates.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_2.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x"], "truth_formula":["x~z"], "prediction_accuracy":[0.80,0.85]}' --outfile $@

robustness_2_jobs_p4: grid_sweep.py 01_two_covariates.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 01_two_covariates.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_2.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x"], "truth_formula":["x~z"], "prediction_accuracy":[0.90,0.95]}' --outfile $@

robustness_2.feather: robustness_2_jobs_p1 robustness_2_jobs_p2 robustness_2_jobs_p3 robustness_2_jobs_p4
	rm $@
	$(eval END_1!=cat robustness_2_jobs_p1 | wc -l)
	$(eval ITEMS_1!=seq $(START) $(STEP) $(END_1))
	$(eval END_2!=cat robustness_2_jobs_p2 | wc -l)
	$(eval ITEMS_2!=seq $(START) $(STEP) $(END_2))
	$(eval END_3!=cat robustness_2_jobs_p3 | wc -l)
	$(eval ITEMS_3!=seq $(START) $(STEP) $(END_3))
	$(eval END_4!=cat robustness_2_jobs_p4 | wc -l)
	$(eval ITEMS_4!=seq $(START) $(STEP) $(END_4))

	$(foreach item,$(ITEMS_1),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_2_jobs_p1;)
	$(foreach item,$(ITEMS_2),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_2_jobs_p2;)
	$(foreach item,$(ITEMS_3),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_2_jobs_p3;)
	$(foreach item,$(ITEMS_4),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_2_jobs_p4;)

robustness_2.RDS: plot_example.R robustness_2.feather summarize_estimator.R
	rm -f $@
	${srun} Rscript $< --infile $(word 2, $^) --name "robustness_2" --remember-file $@

robustness_2_dv_jobs_p1: grid_sweep.py 03_depvar.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 03_depvar.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_2_dv.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1], "outcome_formula":["y~x+z"], "prediction_accuracy":[0.60,0.65]}' --outfile $@

robustness_2_dv_jobs_p2: grid_sweep.py 03_depvar.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 03_depvar.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_2_dv.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1], "outcome_formula":["y~x+z"], "prediction_accuracy":[0.70,0.75]}' --outfile $@

robustness_2_dv_jobs_p3: grid_sweep.py 03_depvar.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 03_depvar.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_2_dv.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1], "outcome_formula":["y~x+z"], "prediction_accuracy":[0.80,0.85]}' --outfile $@

robustness_2_dv_jobs_p4: grid_sweep.py 03_depvar.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 03_depvar.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_2_dv.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1], "outcome_formula":["y~x+z"], "prediction_accuracy":[0.90,0.95]}' --outfile $@

robustness_2_dv.feather: robustness_2_dv_jobs_p1 robustness_2_dv_jobs_p2 robustness_2_dv_jobs_p3 robustness_2_dv_jobs_p4
	rm -f $@
	$(eval END_1!=cat robustness_2_dv_jobs_p1 | wc -l)
	$(eval ITEMS_1!=seq $(START) $(STEP) $(END_1))
	$(eval END_2!=cat robustness_2_dv_jobs_p2 | wc -l)
	$(eval ITEMS_2!=seq $(START) $(STEP) $(END_2))
	$(eval END_3!=cat robustness_2_dv_jobs_p3 | wc -l)
	$(eval ITEMS_3!=seq $(START) $(STEP) $(END_3))
	$(eval END_4!=cat robustness_2_dv_jobs_p4 | wc -l)
	$(eval ITEMS_4!=seq $(START) $(STEP) $(END_4))

	$(foreach item,$(ITEMS_1),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_2_dv_jobs_p1;)
	$(foreach item,$(ITEMS_2),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_2_dv_jobs_p2;)
	$(foreach item,$(ITEMS_3),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_2_dv_jobs_p3;)
	$(foreach item,$(ITEMS_4),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_2_dv_jobs_p4;)

robustness_2_dv.RDS: plot_dv_example.R robustness_2_dv.feather summarize_estimator.R
	rm -f $@
	${srun} Rscript $< --infile $(word 2, $^) --name "robustness_2_dv" --remember-file $@


robustness_3_proflik_jobs: grid_sweep.py 01_two_covariates.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 01_two_covariates.R'  --arg_dict '{"N":[1000],"m":[100], "seed":${seeds}, "outfile":["robustness_3_proflik.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1],"Px":[0.5,0.6,0.7,0.8,0.9,0.95], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x"], "truth_formula":["x~z"], "prediction_accuracy":[0.85], "confint_method":['spline']}' --outfile $@

robustness_3_proflik.feather: robustness_3_proflik_jobs
	rm -f $@
	$(eval END_1!=cat robustness_3_proflik_jobs | wc -l)
	$(eval ITEMS_1!=seq $(START) $(STEP) $(END_1))
	$(foreach item,$(ITEMS_1),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_3_proflik_jobs;)

robustness_3_proflik.RDS: plot_example.R robustness_3_proflik.feather summarize_estimator.R
	rm -f $@
	${srun} Rscript $< --infile $(word 2, $^) --name "robustness_3_proflik" --remember-file $@


robustness_3_jobs_p1: grid_sweep.py 01_two_covariates.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 01_two_covariates.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_3.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1],"Px":[0.5,0.6], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x"], "truth_formula":["x~z"], "prediction_accuracy":[0.85]}' --outfile $@

robustness_3_jobs_p2: grid_sweep.py 01_two_covariates.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 01_two_covariates.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_3.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1],"Px":[0.7,0.8], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x"], "truth_formula":["x~z"], "prediction_accuracy":[0.85]}' --outfile $@

robustness_3_jobs_p3: grid_sweep.py 01_two_covariates.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 01_two_covariates.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_3.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1],"Px":[0.9,0.95], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x"], "truth_formula":["x~z"], "prediction_accuracy":[0.85]}' --outfile $@

robustness_3.feather: robustness_3_jobs_p1 robustness_3_jobs_p2 robustness_3_jobs_p3
	rm -f $@
	$(eval END_1!=cat robustness_3_jobs_p1 | wc -l)
	$(eval ITEMS_1!=seq $(START) $(STEP) $(END_1))
	$(eval END_2!=cat robustness_3_jobs_p2 | wc -l)
	$(eval ITEMS_2!=seq $(START) $(STEP) $(END_2))
	$(eval END_3!=cat robustness_3_jobs_p3 | wc -l)
	$(eval ITEMS_3!=seq $(START) $(STEP) $(END_3))

	$(foreach item,$(ITEMS_1),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_3_jobs_p1;)
	$(foreach item,$(ITEMS_2),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_3_jobs_p2;)
	$(foreach item,$(ITEMS_3),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_3_jobs_p3;)

robustness_3.RDS: plot_example.R robustness_3.feather summarize_estimator.R
	rm -f $@
	${srun} Rscript $< --infile $(word 2, $^) --name "robustness_3" --remember-file $@

robustness_3_dv_proflik_jobs: grid_sweep.py 03_depvar.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 03_depvar.R'  --arg_dict '{"N":[1000],"m":[100], "seed":${seeds}, "outfile":["robustness_3_dv_proflik.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1],"B0":[0,0.405,0.846,1.386,2.197,2.944], "outcome_formula":["y~x+z"], "prediction_accuracy":[0.85],"confint_method":['spline']}' --outfile $@

robustness_3_dv_proflik.feather: robustness_3_dv_proflik_jobs
	rm -f $@
	$(eval END_1!=cat robustness_3_dv_proflik_jobs | wc -l)
	$(eval ITEMS_1!=seq $(START) $(STEP) $(END_1))
	$(foreach item,$(ITEMS_1),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_3_dv_proflik_jobs;)

robustness_3_dv_proflik.RDS: plot_dv_example.R robustness_3_dv_proflik.feather summarize_estimator.R
	rm -f $@
	${srun} Rscript $< --infile $(word 2, $^) --name "robustness_3_dv_proflik" --remember-file $@


 robustness_3_dv_jobs_p1: grid_sweep.py 03_depvar.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 03_depvar.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_3_dv.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1],"B0":[0,0.405], "outcome_formula":["y~x+z"], "prediction_accuracy":[0.85]}' --outfile $@

robustness_3_dv_jobs_p2: grid_sweep.py 03_depvar.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 03_depvar.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_3_dv.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1],"B0":[0.847,1.386], "outcome_formula":["y~x+z"], "prediction_accuracy":[0.85]}' --outfile $@


robustness_3_dv_jobs_p3: grid_sweep.py 03_depvar.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 03_depvar.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_3_dv.feather"],"y_explained_variance":${explained_variances},  "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1], "B0":[2.197,2.944], "outcome_formula":["y~x+z"], "prediction_accuracy":[0.85]}' --outfile $@

robustness_3_dv.feather: robustness_3_dv_jobs_p1 robustness_3_dv_jobs_p2 robustness_3_dv_jobs_p3
	rm -f $@
	$(eval END_1!=cat robustness_3_dv_jobs_p1 | wc -l)
	$(eval ITEMS_1!=seq $(START) $(STEP) $(END_1))
	$(eval END_2!=cat robustness_3_dv_jobs_p2 | wc -l)
	$(eval ITEMS_2!=seq $(START) $(STEP) $(END_2))
	$(eval END_3!=cat robustness_3_dv_jobs_p3 | wc -l)
	$(eval ITEMS_3!=seq $(START) $(STEP) $(END_3))

	$(foreach item,$(ITEMS_1),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_3_dv_jobs_p1;)
	$(foreach item,$(ITEMS_2),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_3_dv_jobs_p2;)
	 $(foreach item,$(ITEMS_3),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_3_dv_jobs_p3;)


robustness_3_dv.RDS: plot_dv_example.R robustness_3_dv.feather summarize_estimator.R
	rm -f $@
	${srun} Rscript $< --infile $(word 2, $^) --name "robustness_3_dv" --remember-file $@



robustness_4_jobs_p1: grid_sweep.py 02_indep_differential.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 02_indep_differential.R' --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_4.feather"],"y_explained_variance":${explained_variances}, "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x+z"], "truth_formula":["x~z"], "y_bias":[-2.944,-2.197]}' --outfile $@

robustness_4_jobs_p2: grid_sweep.py 02_indep_differential.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 02_indep_differential.R' --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_4.feather"],"y_explained_variance":${explained_variances}, "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x+z"], "truth_formula":["x~z"], "y_bias":[-1.386,-0.846]}' --outfile $@

robustness_4_jobs_p3: grid_sweep.py 02_indep_differential.R simulation_base.R
	rm -f ./$@
	${srun} ./$< --command 'Rscript 02_indep_differential.R' --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_4.feather"],"y_explained_variance":${explained_variances}, "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x+z"], "truth_formula":["x~z"], "y_bias":[-0.405,-0.25]}' --outfile $@

robustness_4_jobs_p4: grid_sweep.py 02_indep_differential.R simulation_base.R
	rm -f ./$@
	${srun} ./$< --command 'Rscript 02_indep_differential.R' --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_4.feather"],"y_explained_variance":${explained_variances}, "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x+z"], "truth_formula":["x~z"], "y_bias":[0,-0.1]}' --outfile $@


robustness_4.feather: robustness_4_jobs_p1 robustness_4_jobs_p2 robustness_4_jobs_p3
	rm -f $@
	$(eval END_1!=cat robustness_4_jobs_p1 | wc -l)
	$(eval ITEMS_1!=seq $(START) $(STEP) $(END_1))
	$(eval END_2!=cat robustness_4_jobs_p2 | wc -l)
	$(eval ITEMS_2!=seq $(START) $(STEP) $(END_2))
	$(eval END_3!=cat robustness_4_jobs_p3 | wc -l)
	$(eval ITEMS_3!=seq $(START) $(STEP) $(END_3))
	$(eval END_4!=cat robustness_4_jobs_p3 | wc -l)
	$(eval ITEMS_3!=seq $(START) $(STEP) $(END_4))


	$(foreach item,$(ITEMS_1),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_4_jobs_p1;)
	$(foreach item,$(ITEMS_2),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_4_jobs_p2;)
	$(foreach item,$(ITEMS_3),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_4_jobs_p3;)
	$(foreach item,$(ITEMS_4),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_4_jobs_p3;)


robustness_4.RDS: plot_example.R robustness_4.feather summarize_estimator.R
	rm -f $@
	${srun} Rscript $< --infile $(word 2, $^) --name "robustness_4" --remember-file $@


# '{"N":${robustness_Ns},"Bxy":[0.7],"Bzy":[-0.7],"m":${ms}, "seed":${seeds}, "outfile":["example_4.feather"], "z_bias":[0.5]}' --example_4_jobs

robustness_4_dv_jobs_p1: grid_sweep.py 04_depvar_differential.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 04_depvar_differential.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_4_dv.feather"], "Bzy":[-0.7],"Bxy":[0.7],"Bzx":[1], "outcome_formula":["y~x+z"], "z_bias":[0,0.1]}' --outfile $@

robustness_4_dv_jobs_p2: grid_sweep.py 04_depvar_differential.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 04_depvar_differential.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_4_dv.feather"], "Bzy":[-0.7],"Bxy":[0.7],"Bzx":[1], "outcome_formula":["y~x+z"], "z_bias":[0.25,0.405]}' --outfile $@

robustness_4_dv_jobs_p3: grid_sweep.py 04_depvar_differential.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 04_depvar_differential.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_4_dv.feather"], "Bzy":[-0.7],"Bxy":[0.7],"Bzx":[1],"outcome_formula":["y~x+z"],"z_bias":[0.846,1.386]}' --outfile $@ 

robustness_4_dv_jobs_p4: grid_sweep.py 04_depvar_differential.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 04_depvar_differential.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_4_dv.feather"],"Bzy":[-0.7],"Bxy":[0.7],"Bzx":[1], "outcome_formula":["y~x+z"], "z_bias":[2.197,2.944]}' --outfile $@

robustness_4_dv.feather: robustness_4_dv_jobs_p1 robustness_4_dv_jobs_p2 robustness_4_dv_jobs_p3 robustness_4_dv_jobs_p4
	rm -f $@
	$(eval END_1!=cat robustness_4_dv_jobs_p1 | wc -l)
	$(eval ITEMS_1!=seq $(START) $(STEP) $(END_1))
	$(eval END_2!=cat robustness_4_dv_jobs_p2 | wc -l)
	$(eval ITEMS_2!=seq $(START) $(STEP) $(END_2))
	$(eval END_3!=cat robustness_4_dv_jobs_p3 | wc -l)
	$(eval ITEMS_3!=seq $(START) $(STEP) $(END_3))
	$(eval END_4!=cat robustness_4_dv_jobs_p4 | wc -l)
	$(eval ITEMS_4!=seq $(START) $(STEP) $(END_4))
	$(foreach item,$(ITEMS_1),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_4_dv_jobs_p1;)
	$(foreach item,$(ITEMS_2),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_4_dv_jobs_p2;)
	$(foreach item,$(ITEMS_3),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_4_dv_jobs_p3;)
	$(foreach item,$(ITEMS_4),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_4_dv_jobs_p4;)


robustness_4_dv.RDS: plot_dv_example.R robustness_4_dv.feather summarize_estimator.R
	rm -f $@
	${srun} Rscript $< --infile $(word 2, $^) --name "robustness_4_dv" --remember-file $@


robustness_5_jobs_p1: grid_sweep.py 02_indep_differential.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 02_indep_differential.R' --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_5.feather"],"y_explained_variance":${explained_variances}, "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[1.386,2.197], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x+z"], "truth_formula":["x~z"]}' --outfile $@

robustness_5_jobs_p2: grid_sweep.py 02_indep_differential.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 02_indep_differential.R' --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_5.feather"],"y_explained_variance":${explained_variances}, "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[0.405,0.846], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x+z"], "truth_formula":["x~z"]}' --outfile $@

robustness_5_jobs_p3: grid_sweep.py 02_indep_differential.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 02_indep_differential.R' --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_5.feather"],"y_explained_variance":${explained_variances}, "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[0,0.25], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x+z"], "truth_formula":["x~z"]}' --outfile $@

robustness_5_jobs_p4: grid_sweep.py 02_indep_differential.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 02_indep_differential.R' --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_5.feather"],"y_explained_variance":${explained_variances}, "Bzy":[-0.3],"Bxy":[0.3],"Bzx":[2.944], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x+z"], "truth_formula":["x~z"]}' --outfile $@


robustness_5.feather: robustness_5_jobs_p1 robustness_5_jobs_p2 robustness_5_jobs_p3
	rm -f $@
	$(eval END_1!=cat robustness_5_jobs_p1 | wc -l)
	$(eval ITEMS_1!=seq $(START) $(STEP) $(END_1))
	$(eval END_2!=cat robustness_5_jobs_p2 | wc -l)
	$(eval ITEMS_2!=seq $(START) $(STEP) $(END_2))
	$(eval END_3!=cat robustness_5_jobs_p3 | wc -l)
	$(eval ITEMS_3!=seq $(START) $(STEP) $(END_3))
	$(eval END_4!=cat robustness_5_jobs_p4 | wc -l)
	$(eval ITEMS_4!=seq $(START) $(STEP) $(END_4))

	$(foreach item,$(ITEMS_1),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_5_jobs_p1;)
	$(foreach item,$(ITEMS_2),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_5_jobs_p2;)
	$(foreach item,$(ITEMS_3),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_5_jobs_p3;)
	$(foreach item,$(ITEMS_4),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_5_jobs_p4;)

robustness_5.RDS: plot_example.R robustness_5.feather summarize_estimator.R
	rm -f $@
	${srun} Rscript $< --infile $(word 2, $^) --name "robustness_5" --remember-file $@


# '{"N":${robustness_Ns},"Bxy":[0.7],"Bzy":[-0.7],"m":${ms}, "seed":${seeds}, "outfile":["example_4.feather"], "z_bias":[0.5]}' --example_4_jobs

robustness_5_dv_jobs_p1: grid_sweep.py 04_depvar_differential.R simulation_base.R
	rm -f $@
	 ${srun} ./$< --command 'Rscript 04_depvar_differential.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_5_dv.feather"], "Bzy":[-0.7],"Bxy":[0.7],"Bzx":[0,0.25], "outcome_formula":["y~x+z"], "z_bias":[-0.5]}' --outfile $@

robustness_5_dv_jobs_p2: grid_sweep.py 04_depvar_differential.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 04_depvar_differential.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_5_dv.feather"], "Bzy":[-0.7],"Bxy":[0.7],"Bzx":[0.405,0.846], "outcome_formula":["y~x+z"],  "z_bias":[-0.5]}' --outfile $@

robustness_5_dv_jobs_p3: grid_sweep.py 04_depvar_differential.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 04_depvar_differential.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_5_dv.feather"], "Bzy":[-0.7],"Bxy":[0.7],"Bzx":[1.386,2.197],"outcome_formula":["y~x+z"], "z_bias":[-0.5]}' --outfile $@ 

robustness_5_dv_jobs_p4: grid_sweep.py 04_depvar_differential.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 04_depvar_differential.R'  --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_5_dv.feather"],"Bzy":[-0.7],"Bxy":[0.7],"Bzx":[2.944], "outcome_formula":["y~x+z"], "z_bias":[-0.5]}' --outfile $@

robustness_5_dv.feather: robustness_5_dv_jobs_p1 robustness_5_dv_jobs_p2 robustness_5_dv_jobs_p3 robustness_5_dv_jobs_p4
	rm -f $@
	$(eval END_1!=cat robustness_5_dv_jobs_p1 | wc -l)
	$(eval ITEMS_1!=seq $(START) $(STEP) $(END_1))
	$(eval END_2!=cat robustness_5_dv_jobs_p2 | wc -l)
	$(eval ITEMS_2!=seq $(START) $(STEP) $(END_2))
	$(eval END_3!=cat robustness_5_dv_jobs_p3 | wc -l)
	$(eval ITEMS_3!=seq $(START) $(STEP) $(END_3))
	$(eval END_4!=cat robustness_5_dv_jobs_p4 | wc -l)
	$(eval ITEMS_4!=seq $(START) $(STEP) $(END_4))


	$(foreach item,$(ITEMS_1),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_5_dv_jobs_p1;)
	$(foreach item,$(ITEMS_2),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_5_dv_jobs_p2;)
	$(foreach item,$(ITEMS_3),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_5_dv_jobs_p3;)
	$(foreach item,$(ITEMS_4),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_5_dv_jobs_p4;)


robustness_5_dv.RDS: plot_dv_example.R robustness_5_dv.feather summarize_estimator.R
	rm -f $@
	${srun} Rscript $< --infile $(word 2, $^) --name "robustness_5_dv" --remember-file $@


clean_main:
	rm -f remembr.RDS
	rm -f example_1_jobs
	rm -f example_2_jobs
	rm -f example_3_jobs
	rm -f example_4_jobs
	rm -f example_1.feather
	rm -f example_2.feather
	rm -f example_3.feather
	rm -f example_4.feather


#	
clean_all:
	rm *.feather
	rm -f remembr.RDS
	rm -f remembr*.RDS
	rm -f robustness*.RDS
	rm -f example_*_jobs
	rm -f robustness_*_jobs_*
#	sbatch --wait --verbose --array=3001-6001 run_simulation.sbatch 0 example_2_B_jobs

# example_2_B_mecor_jobs:
# 	sbatch --wait --verbose run_job.sbatch grid_sweep.py --command "Rscript example_2_B_mecor.R" --arg_dict '{"N":${Ns},"m":${ms}, "seed":${seeds}, "outfile":["example_2_B_mecor.feather"]}' --outfile example_2_B_mecor_jobs

# example_2_B_mecor.feather:example_2_B_mecor.R example_2_B_mecor_jobs
# 	rm -f example_2_B_mecor.feather
# 	sbatch --wait --verbose --array=1-3000 run_simulation.sbatch 0 example_2_B_mecor_jobs
# 	sbatch --wait --verbose --array=3001-6001 run_simulation.sbatch 0 example_2_B_mecor_jobs

robustness_6_jobs_p1: grid_sweep.py 03_indep_differential_nonnorm.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 03_indep_differential_nonnorm.R' --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_6.feather"],"y_explained_variance":${explained_variances}, "Bzy":[-0.3],"Bxy":[0.3], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x+z"], "truth_formula":["x~z"],"sd_y_mixin":[0,1,2.5]}' --outfile $@

robustness_6_jobs_p2: grid_sweep.py 03_indep_differential_nonnorm.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 03_indep_differential_nonnorm.R' --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_6.feather"],"y_explained_variance":${explained_variances}, "Bzy":[-0.3],"Bxy":[0.3], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x+z"], "truth_formula":["x~z"],"sd_y_mixin":[5,10]}' --outfile $@

robustness_6_jobs_p3: grid_sweep.py 03_indep_differential_nonnorm.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 03_indep_differential_nonnorm.R' --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_6.feather"],"y_explained_variance":${explained_variances}, "Bzy":[-0.3],"Bxy":[0.3], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x+z"], "truth_formula":["x~z"],"sd_y_mixin":[0,1,2.5],"y_bias":[0]}' --outfile $@

robustness_6_jobs_p4: grid_sweep.py 03_indep_differential_nonnorm.R simulation_base.R
	rm -f $@
	${srun} ./$< --command 'Rscript 03_indep_differential_nonnorm.R' --arg_dict '{"N":${robustness_Ns},"m":${robustness_ms}, "seed":${seeds}, "outfile":["robustness_6.feather"],"y_explained_variance":${explained_variances}, "Bzy":[-0.3],"Bxy":[0.3], "outcome_formula":["y~x+z"], "proxy_formula":["w_pred~y+x+z"], "truth_formula":["x~z"],"sd_y_mixin":[5,10],"y_bias":[0]}' --outfile $@


robustness_6.feather: robustness_6_jobs_p1 robustness_6_jobs_p2 robustness_6_jobs_p3 robustness_6_jobs_p4
	rm -f $@
	$(eval END_1!=cat robustness_6_jobs_p1 | wc -l)
	$(eval ITEMS_1!=seq $(START) $(STEP) $(END_1))
	$(eval END_2!=cat robustness_6_jobs_p2 | wc -l)
	$(eval ITEMS_2!=seq $(START) $(STEP) $(END_2))
	$(eval END_3!=cat robustness_6_jobs_p3 | wc -l)
	$(eval ITEMS_3!=seq $(START) $(STEP) $(END_3))
	$(eval END_4!=cat robustness_6_jobs_p4 | wc -l)
	$(eval ITEMS_4!=seq $(START) $(STEP) $(END_4))


	# $(foreach item,$(ITEMS_1),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_6_jobs_p1;)
	# $(foreach item,$(ITEMS_2),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_6_jobs_p2;)
	# $(foreach item,$(ITEMS_3),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_6_jobs_p3;)
	$(foreach item,$(ITEMS_4),sbatch --wait --verbose --array=$(shell expr $(item) + $(ONE))-$(shell expr $(item) + $(STEP)) run_simulation.sbatch 0 robustness_6_jobs_p4;)


robustness_6.RDS: plot_example.R robustness_6.feather summarize_estimator.R
	rm -f $@
	${srun} Rscript $< --infile $(word 2, $^) --name "robustness_6" --remember-file $@


.PHONY: supplement
