A Model of the Religious Transition