Newton Raphson Optimization In R