Vitamin D improves my mood and also peripheral neuropathy (extremity tingling). I was probably fairly low on it from living in a sunless place and having celiac. Apparently, some of the effects like peripheral neuropathy in celiac are linked to poor absorption of vitamins due to the typical intestinal damage.
Two days later, I was asking myself what the heck had changed. My mood seemed much more stable, even, comfortable.
The only thing that had changed, was the vitamin D.
Now, if/when I run out of it and don't get to the store for a few days, I notice my mood regressing. Particularly when I haven't recently gotten significant, direct skin sun exposure.
As for magnesium, more recently I read that, among other things, it helps with vitamin D absorption and/or utilization. This is not its only apparent benefit. And, unlike some other supplements, there appears to be direct observation of subjects/people to back up claims of these other benefits. I don't know about studies that elucidate the relative biochemical mechanisms.