The high rate of suicide this time of year got me wondering if religious involvement lowers one's risk, so I looked for a study (Taliaferro, L., Rienzo, B., Pigg, R., Miller, M., & Dodd, V. (2009). Spiritual Well-Being and Suicidal Ideation Among College Students. Journal of American College Health, 58(1), 83-90.).
The above table lists the correlations from a study of 522 college students. I don't know why their measure of religiosity is not included here, but you can see that all three types of well-being--spiritual, religious, and existential--are negatively associated with feeling depressed, hopeless, and suicidal. ("Spiritual well-being" is simply the summed scores of religious and existential well-being.) Religious well-being measures satisfaction with one's relationship with God, while existential well-being concerns satisfaction with life and finding meaning and purpose in it.
This table shows that people who attend church frequently have lower levels of hopelessness, depression, and thoughts of suicide, as well as greater social support.
This table displays the multivariate results. It turns that that when you control for other relevant factors, religious involvement (religiosity) does not lower your risk of having suicidal thoughts. Not surprisingly, feelings of hopelessness and depression are associated with more thoughts of suicide, but even after taking their influence into account, finding meaning and purpose in life (existential well-being) appears to reduce thinking about suicide. Religious well-being, by contrast, exerts no independent influence.
So what seems to be crucial for a person is to find a way to avoid feeling that his life is pointless. Religious people often succeed at this--the correlation between religious well-being and existential well-being is a fairly strong .46--but irreligious people can find it as well. Nietzsche got this one right: "We may handle any how, if we only have a why."