US stocks close higher to partially recover from previous losses