New research by Kurt Gray (assistant professor of psychology, University of Maryland) and colleagues indicates that suffering plays an important role in belief in God.
In one study, participants read either that a family (the Millers)- and even their dog- had drowned from a water dam breakage or that the breakage had just ruined their lunch. They then were told either that the dam breakage was due to a clear human mistake, or that the cause was unknown.
The scientists theorized that when people had been severely harmed by the water breakage (when they died) this would heighten belief that God has agency (which is basically like a perceived ability to influence and do things), but only when the cause was not attributable to human error. This is basically because humans naturally need to make sense of, and give reason to, their suffering and misfortunes. If humans cannot be blamed (or praised), then people enact Supernatural agents as the sources of these tragedies (or miracles).
This is precisely what they found. People believed more in God's agency when they had read that other people (in this case hypothetical others) had suffered an unexplained tragedy.
Other research consistent with this has found that a "health index" is negatively correlated across all U.S. states with belief in God. In other words, the more healthy a state is, the less people in that state tend to believe in God. Put differently, the more people in a state "suffer" (experience health problems like infant mortality, infectious disease and cancer), the more likely they are to believe in God.
Some evolutionary psychologists have argued similarly to these scholars. Specifically, they have argued that overdetecting agency, relative to underdetecting it, has clear survival value. If something can't harm us and we conclude it can (overdetect agency), then all is well and we are still alive. But if we conclude we are safe when we aren't (underdetect agency) we are basically done. The bear eats us and the game of life is over. Well played bear. Hopefully at least you or I tasted good.
God is (perceived as) real - more real that is - when people suffer. Suffering breeds theism.
This link will take you to an article written by Kurt Gray about this research for the Personality and Social Psychology Review, which has the highest impact rating on any journal in social or personality psychology: