Update r code to add derived fields and run regression