R script for first and second exo