R scripts for BAEA Project