fid function

Helper function for Cox deviance and gradient