Added R code.
Added equations.