R and RMarkdown code from Stat 579