The main root cause of this behavior in dogs is in their "pack" instincts.These behaviors can still be exhibited in domesticated dogs.
These instincts also draw on the fact that the leader has the more ideal sleeping spot, hence why they lay at your feet or sleep at the foot of your bed.