You likely are magnesium deficient
At the risk of sounding reductionist, there does appear to be an insufficient intake of magnesium by most Americans. The latest data indicates that 68% of Americans do not consume the recommended daily intake of magnesium (420 mg per day) and 19% of Americans do not consume even half the government’s recommended daily intake of magnesium.
Would a serious whole-food varied-plant diet provide adequate magnesium? Maybe. But thinking of by-gone millennia in which greens were the food of choice (and spring water/ rain water the only beverage) does raise some doubts. As an example, consider spinach and oat bran, both considered good sources of magnesium.
A dose of 30 grams (one cup) of spinach minus the 27.4 grams of water content has 23.7 mg of magnesium; 96 grams of oats (one and a half cups) minus 2 grams of water has 96 mg of magnesium. But on a per calorie basis spinach has 3.4 mg magnesium compared to 0.45 mg for oats. On a per dry weight comparison spinach has 3.4 mg/g of magnesium compared to 1.7 mg/g for oats. That’s more than five times the magnesium content in spinach compared to oats.
Magnesium, one of the most essential minerals in the human body, is a co-factor in more than 600 known enzymatic reactions. Magnesium is widely connected with brain biochemistry and, as a result, a deficiency is associated with a variety of neuromuscular and psychiatric symptoms such as depression, psychosis, agitation and irritability, headaches, seizures, muscular weakness, anxiety, insomnia, fatigue, confusion and cognitive changes; this is reversible with restoration of sufficient magnesium levels.
The diets of those clinically depressed is correlated with low intake of magnesium; research indicates an inverse relationship between dietary magnesium content and depressive symptoms. Suicidal depression particularly appears to be related to magnesium insufficiency; for example, data indicate that magnesium concentration in cerebrospinal fluid was low in patients with history of suicidal behavior.
The take-home here is to eat your greens. A magnesium level may be useful as an initial clinical workup for psychiatric symptoms. If your magnesium level is verified to be low and there are accompanying psychiatric symptoms, your provider may choose to add a supplement of 600 – 800 mg per day of any of the various forms of magnesium available (except magnesium oxide, which is not bioavailable).
 King, D. E., Mainous, A. G., Geesey, M. E., & Woolson, R. F. (2005). Dietary Magnesium and C-reactive Protein Levels. Journal of the American College of Nutrition, 24(3), 166-171. doi:10.1080/ 07315724. 2005.10719461.
 Kantak, K. M. (1988). Magnesium deficiency alters aggressive behavior and catecholamine function. Behavioral Neuroscience, 102(2), 304-311. doi:10.1037//0735-7044.102.2.304.
 Papadopol V, Tuchendria E, Palamaru I: Magnesium and some psychological features in two groups of pupils (magnesium and psychic features) (2001). Magnes Res, 14, 27–32.
 Jacka, F. N., Overland, S., Stewart, R., Tell, G. S., Bjelland, I., & Mykletun, A. (2009). Association between magnesium intake and depression and anxiety in community-dwelling adults: The Hordaland Health Study. Australian and New Zealand Journal of Psychiatry, 43(1), 45-52. doi:10.1080/00048670802534408.
 Banki, C. M., Arató, M., & Kilts, C. D. (1986). Aminergic Studies and Cerebrospinal Fluid Cations in Suicide. Ann NY Acad Sci Annals of the New York Academy of Sciences, 487(1 Psychobiology), 221-230. doi:10.1111/j.1749-6632.1986.tb27901.x.
 Banki, C. M., Vojnik, M., Papp, Z., Balla, K. Z., & Arató, M. (1985). Cerebrospinal fluid magnesium and calcium related to amine metabolites, diagnosis, and suicide attempts. Biological Psychiatry, 20(2), 163-171. doi:10.1016/0006-3223(85)90076-9.