R markdown file for AFE calculation