rms function for case 2