Magnesium deficiency in humans affects the sleep quality and may cause prolonged sleep-deprivation, in turn affecting your physical and mental health. Magnesium can be used as a supplement to improve sleep quality and allow better functioning of the body.