finished elastic regression function