R scripts for paper