Transitioning from Fortran codes to C++ with Rcpp. Added EM algorithm.