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