R codes for analysis