Updated R code from the presentation.