Please check the resources of this lecture - you will find a PDF file with all the R codes used in the fifth chapter of the course.