modified calc_rii.r file