I am having trouble linking the algorithm together. The steps are as follows :https://stats.stackexchange.com/q/488694/282288
I posted in CrossValidated, it was difficult