Psalm 107 is the psalm of thanksgiving, especially obligating a person who survives a dangerous situation. The psalm mentions four cycles of peril and deliverance. These constitute the four groups who are particularly required to thank Hashem for rescuing them.