R codes for my dissertation